@openclaw/matrix 2026.9.8 → 2026.10.1-beta.2

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 (278) hide show
  1. package/dist/.setup/{account-selection-B7axQ80R.mjs → account-selection-BDeeqwwR.mjs} +1 -1
  2. package/dist/.setup/{accounts-WkgrIxMt.mjs → accounts-C_r0UlEm.mjs} +2 -2
  3. package/dist/.setup/{approval-handler.runtime-C-pw3NvY.mjs → approval-handler.runtime-QkHLH2az.mjs} +14 -19
  4. package/dist/.setup/{approval-reactions-BrS5ECU0.mjs → approval-reactions-DhB6gNPU.mjs} +11 -25
  5. package/dist/.setup/{channel-DXenXmj0.mjs → channel-CeRXEAEP.mjs} +17 -46
  6. package/dist/.setup/{channel.runtime-BXUawOno.mjs → channel.runtime-DBQA2y1F.mjs} +6 -6
  7. package/dist/.setup/{channel.setup-DWfLaXqT.mjs → channel.setup-DC2t7_PK.mjs} +12 -26
  8. package/dist/.setup/{cli-IhZO2OEj.mjs → cli-Be8tdNw8.mjs} +24 -45
  9. package/dist/.setup/{cli-metadata-nowEgdY0.mjs → cli-metadata-CtcjBFhc.mjs} +1 -1
  10. package/dist/.setup/{client-BXATebyo.mjs → client-DY3HExqI.mjs} +3 -3
  11. package/dist/.setup/{client-bootstrap-BiHX55is.mjs → client-bootstrap-CZvJjr29.mjs} +1 -1
  12. package/dist/.setup/{client-Ccv77kwh.mjs → client-kmih04ng.mjs} +21 -40
  13. package/dist/.setup/{client-support-Bn9Bk0-H.mjs → client-support-D7BlioUb.mjs} +14 -23
  14. package/dist/.setup/{config-update-5m1Un5gJ.mjs → config-update-CZndPxNd.mjs} +29 -72
  15. package/dist/.setup/{create-client-DRZ580E3.mjs → create-client-CbJVyFDy.mjs} +5 -5
  16. package/dist/.setup/{credentials-C9qDO5-2.mjs → credentials-C2dvc_kB.mjs} +1 -1
  17. package/dist/.setup/{credentials-read-KD4o5biZ.mjs → credentials-read-CqRiEAQa.mjs} +1 -1
  18. package/dist/.setup/{crypto-runtime-DPjIDF8H.mjs → crypto-runtime-B2AjWo-i.mjs} +223 -79
  19. package/dist/.setup/{deps-CLQ4EOq7.mjs → deps-CFNl7tQo.mjs} +14 -39
  20. package/dist/.setup/{device-health-U-yoVjPw.mjs → device-health-Be60VF1w.mjs} +1 -1
  21. package/dist/.setup/{direct-management-Cn2t8n1V.mjs → direct-management-DJtQhLKH.mjs} +4 -8
  22. package/dist/.setup/{directory-live-_sw-Q7KO.mjs → directory-live-DW5UykLL.mjs} +3 -3
  23. package/dist/.setup/{doctor-contract-De6geW0h.mjs → doctor-contract-CsTNmbMa.mjs} +10 -133
  24. package/dist/.setup/{draft-stream-CdVMstpR.mjs → draft-stream-B87DfA6a.mjs} +4 -8
  25. package/dist/.setup/{encryption-guidance-B6797jNA.mjs → encryption-guidance-BEjKbiMR.mjs} +1 -1
  26. package/dist/.setup/{exec-approvals-fsiMQ1ce.mjs → exec-approvals-BLDAMyHs.mjs} +6 -19
  27. package/dist/.setup/{file-sync-store-B-9bMb_O.mjs → file-sync-store-Clc9iEdn.mjs} +3 -3
  28. package/dist/.setup/{http-client-C1XvVD3K.mjs → http-client-DfJY5Ck0.mjs} +8 -29
  29. package/dist/.setup/{inbound-dedupe-BGrMrTTu.mjs → inbound-dedupe-C-EBGY0B.mjs} +1 -1
  30. package/dist/.setup/{joined-room-encryption-TZoOKXgh.mjs → joined-room-encryption-BAD70N5n.mjs} +1 -1
  31. package/dist/.setup/logger-CXQnpXCt.mjs +44 -0
  32. package/dist/.setup/{logging-mhnFQGzB.mjs → logging-BKV8TYQq.mjs} +7 -32
  33. package/dist/.setup/{messages-Buz27pi5.mjs → messages-uCbwLRKS.mjs} +5 -8
  34. package/dist/.setup/{monitor-BBg5qgov.mjs → monitor-skIntQVG.mjs} +109 -180
  35. package/dist/.setup/{onboarding-hJaieQj5.mjs → onboarding-Cm_tOJxs.mjs} +12 -19
  36. package/dist/.setup/{outbound-C9vBijaH.mjs → outbound-CqQou3ny.mjs} +16 -22
  37. package/dist/.setup/{profile-B3DD2jYa.mjs → profile-DS0xdJAi.mjs} +11 -31
  38. package/dist/.setup/{profile-update-CmxIAd4c.mjs → profile-update-C1n8SRqH.mjs} +3 -3
  39. package/dist/.setup/{reaction-events-mnzc_JvP.mjs → reaction-events-Cqq46xsG.mjs} +5 -5
  40. package/dist/.setup/{resolve-targets-BFq3q4c9.mjs → resolve-targets-DFeU1Ww6.mjs} +2 -2
  41. package/dist/.setup/retired-state-BXUQ2I-C.mjs +91 -0
  42. package/dist/.setup/{room-info-BbTGRJcR.mjs → room-info-BPMbwe8I.mjs} +33 -50
  43. package/dist/.setup/{sdk-DmRVM0VA.mjs → sdk-CgQGkCsS.mjs} +226 -182
  44. package/dist/.setup/{send-GOF64QRc.mjs → send-B1Y2L4wj.mjs} +19 -68
  45. package/dist/.setup/{setup-bootstrap-AzalcuCW.mjs → setup-bootstrap-UNIGyKnk.mjs} +2 -2
  46. package/dist/.setup/{setup-core-BeifoeL4.mjs → setup-core-6DppLENo.mjs} +5 -5
  47. package/dist/.setup/{setup-plugin-api-Bsbdw41x.mjs → setup-plugin-api-BRs9bcp4.mjs} +1 -1
  48. package/dist/.setup/startup-verification-D00eUt74.mjs +122 -0
  49. package/dist/.setup/storage-D7agewjH.mjs +464 -0
  50. package/dist/.setup/{sync-cache-state-C6sEmvJK.mjs → sync-cache-state-C2z64uyk.mjs} +10 -24
  51. package/dist/.setup/{thread-bindings-jXu_9cHE.mjs → thread-bindings-DveHVZqN.mjs} +13 -71
  52. package/dist/.setup/{tool-actions-Ce7Okg6m.mjs → tool-actions-BqlK2ilM.mjs} +51 -73
  53. package/dist/.setup/{verification-C45rOZkM.mjs → verification-kMlFYUn0.mjs} +10 -27
  54. package/dist/api.js +5 -5
  55. package/dist/channel-plugin-api.js +1 -1
  56. package/dist/cli-metadata.js +1 -1
  57. package/dist/contract-api.js +2 -2
  58. package/dist/doctor-contract-api.js +48 -201
  59. package/dist/helper-api.js +1 -1
  60. package/dist/index.js +1 -1
  61. package/dist/plugin-entry.handlers.runtime.js +1 -1
  62. package/dist/runtime-api.js +3 -3
  63. package/dist/session-binding-contract-api.js +1 -1
  64. package/dist/setup-entry.js +1 -1
  65. package/dist/setup-plugin-api.js +1 -1
  66. package/node_modules/@openclaw/fs-safe/CHANGELOG.md +95 -0
  67. package/node_modules/@openclaw/fs-safe/README.md +70 -379
  68. package/node_modules/@openclaw/fs-safe/dist/absolute-path.js +35 -51
  69. package/node_modules/@openclaw/fs-safe/dist/advanced.d.ts +2 -0
  70. package/node_modules/@openclaw/fs-safe/dist/advanced.js +1 -0
  71. package/node_modules/@openclaw/fs-safe/dist/archive-input.js +2 -0
  72. package/node_modules/@openclaw/fs-safe/dist/archive-parser.wasm +0 -0
  73. package/node_modules/@openclaw/fs-safe/dist/archive-staging.d.ts +1 -1
  74. package/node_modules/@openclaw/fs-safe/dist/archive-staging.js +9 -10
  75. package/node_modules/@openclaw/fs-safe/dist/archive.js +2 -5
  76. package/node_modules/@openclaw/fs-safe/dist/atomic-io.d.ts +51 -0
  77. package/node_modules/@openclaw/fs-safe/dist/atomic-io.js +242 -0
  78. package/node_modules/@openclaw/fs-safe/dist/config.d.ts +1 -1
  79. package/node_modules/@openclaw/fs-safe/dist/config.js +1 -1
  80. package/node_modules/@openclaw/fs-safe/dist/copy-file-input.d.ts +1 -1
  81. package/node_modules/@openclaw/fs-safe/dist/copy-file-input.js +2 -2
  82. package/node_modules/@openclaw/fs-safe/dist/copy-tree-portable.js +2 -0
  83. package/node_modules/@openclaw/fs-safe/dist/create.js +12 -5
  84. package/node_modules/@openclaw/fs-safe/dist/directory-guard.d.ts +11 -0
  85. package/node_modules/@openclaw/fs-safe/dist/directory-guard.js +4 -7
  86. package/node_modules/@openclaw/fs-safe/dist/entry-publication-types.d.ts +55 -0
  87. package/node_modules/@openclaw/fs-safe/dist/entry-publication-types.js +1 -0
  88. package/node_modules/@openclaw/fs-safe/dist/entry-publication.d.ts +8 -0
  89. package/node_modules/@openclaw/fs-safe/dist/entry-publication.js +262 -0
  90. package/node_modules/@openclaw/fs-safe/dist/exclusive-create.d.ts +3 -0
  91. package/node_modules/@openclaw/fs-safe/dist/exclusive-create.js +22 -0
  92. package/node_modules/@openclaw/fs-safe/dist/file-cleanup.d.ts +1 -6
  93. package/node_modules/@openclaw/fs-safe/dist/file-cleanup.js +3 -6
  94. package/node_modules/@openclaw/fs-safe/dist/file-identity.js +3 -6
  95. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-io.js +2 -2
  96. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-mutation.js +9 -0
  97. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root.js +4 -6
  98. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-stale-admission.js +1 -1
  99. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync.js +8 -0
  100. package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.js +2 -0
  101. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.js +20 -18
  102. package/node_modules/@openclaw/fs-safe/dist/file-store.js +4 -10
  103. package/node_modules/@openclaw/fs-safe/dist/fs.d.ts +2 -10
  104. package/node_modules/@openclaw/fs-safe/dist/fs.js +2 -10
  105. package/node_modules/@openclaw/fs-safe/dist/guarded-mkdir.d.ts +3 -4
  106. package/node_modules/@openclaw/fs-safe/dist/guarded-mkdir.js +6 -18
  107. package/node_modules/@openclaw/fs-safe/dist/guest-dispatch-python.js +1 -1
  108. package/node_modules/@openclaw/fs-safe/dist/guest-native-python.js +0 -2
  109. package/node_modules/@openclaw/fs-safe/dist/guest.js +3 -9
  110. package/node_modules/@openclaw/fs-safe/dist/index.d.ts +1 -1
  111. package/node_modules/@openclaw/fs-safe/dist/index.js +1 -1
  112. package/node_modules/@openclaw/fs-safe/dist/json-durable-queue-directory.js +1 -5
  113. package/node_modules/@openclaw/fs-safe/dist/json.js +19 -37
  114. package/node_modules/@openclaw/fs-safe/dist/move-path.js +2 -0
  115. package/node_modules/@openclaw/fs-safe/dist/mutation-authority.d.ts +1 -0
  116. package/node_modules/@openclaw/fs-safe/dist/mutation-authority.js +9 -1
  117. package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +47 -2
  118. package/node_modules/@openclaw/fs-safe/dist/native-config.d.ts +1 -9
  119. package/node_modules/@openclaw/fs-safe/dist/native-config.js +6 -40
  120. package/node_modules/@openclaw/fs-safe/dist/native-parent-admission.d.ts +2 -0
  121. package/node_modules/@openclaw/fs-safe/dist/native-parent-admission.js +5 -2
  122. package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +11 -316
  123. package/node_modules/@openclaw/fs-safe/dist/native-policy-parent-windows.d.ts +7 -7
  124. package/node_modules/@openclaw/fs-safe/dist/native-policy-parent-windows.js +28 -175
  125. package/node_modules/@openclaw/fs-safe/dist/native-policy-parent.d.ts +15 -0
  126. package/node_modules/@openclaw/fs-safe/dist/native-policy-parent.js +418 -0
  127. package/node_modules/@openclaw/fs-safe/dist/native-rename-outcome.js +9 -4
  128. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.js +17 -13
  129. package/node_modules/@openclaw/fs-safe/dist/native-staged-symlink.js +6 -24
  130. package/node_modules/@openclaw/fs-safe/dist/native.js +5 -1
  131. package/node_modules/@openclaw/fs-safe/dist/path-case.js +10 -9
  132. package/node_modules/@openclaw/fs-safe/dist/path-scope-lexical.js +4 -1
  133. package/node_modules/@openclaw/fs-safe/dist/path-segment-route.d.ts +1 -0
  134. package/node_modules/@openclaw/fs-safe/dist/path-segment-route.js +3 -0
  135. package/node_modules/@openclaw/fs-safe/dist/path.js +4 -1
  136. package/node_modules/@openclaw/fs-safe/dist/permissions-windows.d.ts +0 -1
  137. package/node_modules/@openclaw/fs-safe/dist/pinned-mutation-admission.js +1 -3
  138. package/node_modules/@openclaw/fs-safe/dist/pinned-write-staged.js +2 -0
  139. package/node_modules/@openclaw/fs-safe/dist/pinned-write.js +9 -10
  140. package/node_modules/@openclaw/fs-safe/dist/private-producer-handoff.js +3 -6
  141. package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.js +2 -2
  142. package/node_modules/@openclaw/fs-safe/dist/publish-file.js +4 -3
  143. package/node_modules/@openclaw/fs-safe/dist/replace-file-buffer.d.ts +3 -4
  144. package/node_modules/@openclaw/fs-safe/dist/replace-file-buffer.js +18 -32
  145. package/node_modules/@openclaw/fs-safe/dist/replace-file-copy-fallback.d.ts +5 -17
  146. package/node_modules/@openclaw/fs-safe/dist/replace-file-copy-fallback.js +92 -230
  147. package/node_modules/@openclaw/fs-safe/dist/replace-file-copy-source.d.ts +4 -15
  148. package/node_modules/@openclaw/fs-safe/dist/replace-file-copy-source.js +22 -63
  149. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.d.ts +9 -34
  150. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +78 -83
  151. package/node_modules/@openclaw/fs-safe/dist/replace-file-destination.d.ts +18 -20
  152. package/node_modules/@openclaw/fs-safe/dist/replace-file-destination.js +64 -98
  153. package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.d.ts +16 -33
  154. package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.js +61 -200
  155. package/node_modules/@openclaw/fs-safe/dist/replace-file-types.d.ts +1 -6
  156. package/node_modules/@openclaw/fs-safe/dist/replace-file.js +76 -216
  157. package/node_modules/@openclaw/fs-safe/dist/root-boundary.js +14 -24
  158. package/node_modules/@openclaw/fs-safe/dist/root-context.d.ts +1 -4
  159. package/node_modules/@openclaw/fs-safe/dist/root-context.js +4 -19
  160. package/node_modules/@openclaw/fs-safe/dist/root-create-native.d.ts +52 -0
  161. package/node_modules/@openclaw/fs-safe/dist/root-create-native.js +350 -0
  162. package/node_modules/@openclaw/fs-safe/dist/root-directory-list-types.d.ts +35 -0
  163. package/node_modules/@openclaw/fs-safe/dist/root-directory-list-types.js +1 -0
  164. package/node_modules/@openclaw/fs-safe/dist/root-directory-list.d.ts +2 -27
  165. package/node_modules/@openclaw/fs-safe/dist/root-directory-list.js +31 -28
  166. package/node_modules/@openclaw/fs-safe/dist/root-directory.js +1 -4
  167. package/node_modules/@openclaw/fs-safe/dist/root-errors.js +34 -0
  168. package/node_modules/@openclaw/fs-safe/dist/root-file.js +9 -21
  169. package/node_modules/@openclaw/fs-safe/dist/root-impl.js +105 -37
  170. package/node_modules/@openclaw/fs-safe/dist/root-move-noreplace.d.ts +7 -2
  171. package/node_modules/@openclaw/fs-safe/dist/root-move-noreplace.js +67 -38
  172. package/node_modules/@openclaw/fs-safe/dist/root-observed-path.d.ts +1 -1
  173. package/node_modules/@openclaw/fs-safe/dist/root-observed-path.js +0 -2
  174. package/node_modules/@openclaw/fs-safe/dist/root-options.d.ts +2 -3
  175. package/node_modules/@openclaw/fs-safe/dist/root-path-existing.js +3 -1
  176. package/node_modules/@openclaw/fs-safe/dist/root-path-stat.js +68 -85
  177. package/node_modules/@openclaw/fs-safe/dist/root-path.js +6 -1
  178. package/node_modules/@openclaw/fs-safe/dist/root-paths-lexical.d.ts +4 -0
  179. package/node_modules/@openclaw/fs-safe/dist/root-paths-lexical.js +1 -1
  180. package/node_modules/@openclaw/fs-safe/dist/root-paths.js +4 -9
  181. package/node_modules/@openclaw/fs-safe/dist/root-remove-native.d.ts +4 -0
  182. package/node_modules/@openclaw/fs-safe/dist/root-remove-native.js +311 -0
  183. package/node_modules/@openclaw/fs-safe/dist/root-remove.d.ts +11 -0
  184. package/node_modules/@openclaw/fs-safe/dist/root-remove.js +3 -1
  185. package/node_modules/@openclaw/fs-safe/dist/root-walk.d.ts +2 -2
  186. package/node_modules/@openclaw/fs-safe/dist/root-walk.js +1 -3
  187. package/node_modules/@openclaw/fs-safe/dist/root-write-admission.d.ts +3 -3
  188. package/node_modules/@openclaw/fs-safe/dist/root-write-admission.js +8 -10
  189. package/node_modules/@openclaw/fs-safe/dist/safe-path-segment.d.ts +0 -1
  190. package/node_modules/@openclaw/fs-safe/dist/safe-path-segment.js +0 -4
  191. package/node_modules/@openclaw/fs-safe/dist/secret-file.js +12 -9
  192. package/node_modules/@openclaw/fs-safe/dist/secure-temp-dir.d.ts +0 -2
  193. package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.js +2 -0
  194. package/node_modules/@openclaw/fs-safe/dist/sibling-temp.js +7 -4
  195. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-acquire.js +13 -6
  196. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.d.ts +0 -3
  197. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js +5 -23
  198. package/node_modules/@openclaw/fs-safe/dist/staged-file-settlement.d.ts +2 -1
  199. package/node_modules/@openclaw/fs-safe/dist/staged-file-settlement.js +11 -6
  200. package/node_modules/@openclaw/fs-safe/dist/temp-cleanup.js +1 -8
  201. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.d.ts +1 -1
  202. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.js +2 -9
  203. package/node_modules/@openclaw/fs-safe/dist/text-atomic.d.ts +1 -6
  204. package/node_modules/@openclaw/fs-safe/dist/trash.js +6 -2
  205. package/node_modules/@openclaw/fs-safe/dist/walk.js +100 -46
  206. package/node_modules/@openclaw/fs-safe/dist/watch-hints.d.ts +7 -0
  207. package/node_modules/@openclaw/fs-safe/dist/watch-hints.js +235 -19
  208. package/node_modules/@openclaw/fs-safe/dist/watch-native.d.ts +21 -2
  209. package/node_modules/@openclaw/fs-safe/dist/watch-native.js +21 -3
  210. package/node_modules/@openclaw/fs-safe/dist/watch-rescan.d.ts +6 -0
  211. package/node_modules/@openclaw/fs-safe/dist/watch-rescan.js +111 -0
  212. package/node_modules/@openclaw/fs-safe/dist/watch-scan.d.ts +13 -0
  213. package/node_modules/@openclaw/fs-safe/dist/watch-scan.js +27 -4
  214. package/node_modules/@openclaw/fs-safe/dist/watch-stream.js +2 -0
  215. package/node_modules/@openclaw/fs-safe/dist/watch.js +131 -40
  216. package/node_modules/@openclaw/fs-safe/dist/windows-path-alias.d.ts +8 -0
  217. package/node_modules/@openclaw/fs-safe/dist/windows-path-alias.js +24 -6
  218. package/node_modules/@openclaw/fs-safe/dist/windows-path-syntax.d.ts +13 -0
  219. package/node_modules/@openclaw/fs-safe/dist/windows-path-syntax.js +51 -0
  220. package/node_modules/@openclaw/fs-safe/docs/advanced.md +4 -0
  221. package/node_modules/@openclaw/fs-safe/docs/atomic.md +4 -1
  222. package/node_modules/@openclaw/fs-safe/docs/config.md +6 -14
  223. package/node_modules/@openclaw/fs-safe/docs/contributing.md +4 -14
  224. package/node_modules/@openclaw/fs-safe/docs/durability.md +6 -29
  225. package/node_modules/@openclaw/fs-safe/docs/entry-publication.md +146 -0
  226. package/node_modules/@openclaw/fs-safe/docs/errors.md +16 -0
  227. package/node_modules/@openclaw/fs-safe/docs/file-store.md +28 -5
  228. package/node_modules/@openclaw/fs-safe/docs/index.md +2 -31
  229. package/node_modules/@openclaw/fs-safe/docs/install.md +10 -31
  230. package/node_modules/@openclaw/fs-safe/docs/json.md +1 -1
  231. package/node_modules/@openclaw/fs-safe/docs/local-roots.md +0 -1
  232. package/node_modules/@openclaw/fs-safe/docs/migrating-to-0.5.md +12 -12
  233. package/node_modules/@openclaw/fs-safe/docs/native-helper.md +35 -96
  234. package/node_modules/@openclaw/fs-safe/docs/native.md +22 -20
  235. package/node_modules/@openclaw/fs-safe/docs/path.md +1 -1
  236. package/node_modules/@openclaw/fs-safe/docs/permissions.md +1 -2
  237. package/node_modules/@openclaw/fs-safe/docs/public-api.md +1 -2
  238. package/node_modules/@openclaw/fs-safe/docs/reading.md +1 -2
  239. package/node_modules/@openclaw/fs-safe/docs/root.md +26 -184
  240. package/node_modules/@openclaw/fs-safe/docs/secret-file.md +1 -1
  241. package/node_modules/@openclaw/fs-safe/docs/security-model.md +115 -3
  242. package/node_modules/@openclaw/fs-safe/docs/store.md +2 -2
  243. package/node_modules/@openclaw/fs-safe/docs/temp.md +29 -65
  244. package/node_modules/@openclaw/fs-safe/docs/testing.md +90 -58
  245. package/node_modules/@openclaw/fs-safe/docs/types.md +3 -16
  246. package/node_modules/@openclaw/fs-safe/docs/walk.md +33 -5
  247. package/node_modules/@openclaw/fs-safe/docs/watch.md +96 -14
  248. package/node_modules/@openclaw/fs-safe/docs/writing.md +172 -16
  249. package/node_modules/@openclaw/fs-safe/package.json +10 -10
  250. package/node_modules/@openclaw/fs-safe-darwin-arm64/fs-safe-native.node +0 -0
  251. package/node_modules/@openclaw/fs-safe-darwin-arm64/package.json +1 -1
  252. package/node_modules/@openclaw/fs-safe-darwin-x64/fs-safe-native.node +0 -0
  253. package/node_modules/@openclaw/fs-safe-darwin-x64/package.json +1 -1
  254. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/fs-safe-native.node +0 -0
  255. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/package.json +1 -1
  256. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/fs-safe-native.node +0 -0
  257. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/package.json +1 -1
  258. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/fs-safe-native.node +0 -0
  259. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/package.json +1 -1
  260. package/node_modules/@openclaw/fs-safe-linux-x64-musl/fs-safe-native.node +0 -0
  261. package/node_modules/@openclaw/fs-safe-linux-x64-musl/package.json +1 -1
  262. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/fs-safe-native.node +0 -0
  263. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/package.json +1 -1
  264. package/openclaw.plugin.json +0 -9
  265. package/package.json +5 -5
  266. package/dist/.setup/crypto-snapshot-doctor.runtime-44FrCPR7.mjs +0 -91
  267. package/dist/.setup/doctor-DMvEBx6o.mjs +0 -49
  268. package/dist/.setup/idb-persistence-DBvfre1X.mjs +0 -227
  269. package/dist/.setup/idb-persistence-lock-D_mDu4Cf.mjs +0 -27
  270. package/dist/.setup/logger-CVv56jzH.mjs +0 -74
  271. package/dist/.setup/startup-verification-Aiy_xVdI.mjs +0 -204
  272. package/dist/.setup/storage-BXS2cB2i.mjs +0 -288
  273. package/dist/.setup/storage-metadata-BDRZ7vpX.mjs +0 -371
  274. package/node_modules/@openclaw/fs-safe/dist/watch-alias.d.ts +0 -6
  275. package/node_modules/@openclaw/fs-safe/dist/watch-alias.js +0 -88
  276. package/node_modules/@openclaw/fs-safe/docs/mutation-policy-proof.md +0 -69
  277. package/node_modules/@openclaw/fs-safe/docs/private-file-store.md +0 -68
  278. package/node_modules/@openclaw/fs-safe/docs/test-hooks.md +0 -110
@@ -1,288 +0,0 @@
1
- import { t as getMatrixRuntime } from "./runtime-1kn1P6io.mjs";
2
- import { n as isMatrixActiveTokenRootDirectory, r as resolveMatrixAccountStorageRoot } from "./storage-paths-B51JM-pC.mjs";
3
- import { S as scoreMatrixCryptoStateInStore, c as MATRIX_RECOVERY_KEY_FILENAME, d as migrateLegacyMatrixLegacyCryptoMigrationFileToStore, f as migrateLegacyMatrixRecoveryKeyFilePathToStoreAsync, i as openMatrixStorageMetaStoreOptions, o as MATRIX_IDB_SNAPSHOT_FILENAME, r as normalizeMatrixStorageMetadata, s as MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME, t as STORAGE_META_STATE_KEY } from "./storage-metadata-BDRZ7vpX.mjs";
4
- import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
5
- import path from "node:path";
6
- import fs from "node:fs";
7
- import os from "node:os";
8
- import { loadJsonFile } from "openclaw/plugin-sdk/json-store";
9
- //#region extensions/matrix/src/matrix/client/storage.ts
10
- const DEFAULT_ACCOUNT_KEY = "default";
11
- const STORAGE_META_FILENAME = "storage-meta.json";
12
- const THREAD_BINDINGS_FILENAME = "thread-bindings.json";
13
- function openStorageMetaStore(rootDir) {
14
- return getMatrixRuntime().state.openKeyedStore(openMatrixStorageMetaStoreOptions(rootDir));
15
- }
16
- async function scoreStorageRoot(rootDir, metadata) {
17
- let score = 0;
18
- if (Object.keys(metadata).length > 0) score += 1;
19
- if (metadata.currentTokenStateClaimed === true) score += 8;
20
- for (const [filename, weight] of [
21
- ["crypto", 8],
22
- [THREAD_BINDINGS_FILENAME, 4],
23
- [MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME, 3],
24
- [MATRIX_RECOVERY_KEY_FILENAME, 2],
25
- [MATRIX_IDB_SNAPSHOT_FILENAME, 2]
26
- ]) if (fs.existsSync(path.join(rootDir, filename))) score += weight;
27
- score += await scoreMatrixCryptoStateInStore(rootDir);
28
- return score;
29
- }
30
- function resolveStorageRootMtimeMs(rootDir) {
31
- try {
32
- return fs.statSync(rootDir).mtimeMs;
33
- } catch {
34
- return 0;
35
- }
36
- }
37
- async function readStoredRootMetadata(rootDir) {
38
- if (fs.existsSync(path.join(rootDir, "state", "openclaw.sqlite"))) try {
39
- const stored = normalizeMatrixStorageMetadata(await openStorageMetaStore(rootDir).lookup(STORAGE_META_STATE_KEY));
40
- if (stored) return stored;
41
- } catch {}
42
- return normalizeMatrixStorageMetadata(loadJsonFile(path.join(rootDir, STORAGE_META_FILENAME))) ?? {};
43
- }
44
- function isCompatibleStorageRoot(params) {
45
- const { metadata } = params;
46
- if (metadata.homeserver && metadata.homeserver !== params.homeserver) return false;
47
- if (metadata.userId && metadata.userId !== params.userId) return false;
48
- if (metadata.accountId && normalizeAccountId(metadata.accountId) !== normalizeAccountId(params.accountKey)) return false;
49
- return metadata.deviceId?.trim() === params.deviceId.trim();
50
- }
51
- async function resolvePreferredMatrixStorageRoot(params) {
52
- const canonical = {
53
- rootDir: params.canonicalRootDir,
54
- tokenHash: params.canonicalTokenHash
55
- };
56
- const deviceId = params.deviceId?.trim();
57
- if (!deviceId) return canonical;
58
- const canonicalMetadata = await readStoredRootMetadata(params.canonicalRootDir);
59
- if (canonicalMetadata.accessTokenHash === params.canonicalTokenHash && canonicalMetadata.deviceId?.trim() === deviceId && canonicalMetadata.currentTokenStateClaimed === true) return canonical;
60
- const parentDir = path.dirname(params.canonicalRootDir);
61
- const bestCurrentScore = await scoreStorageRoot(params.canonicalRootDir, canonicalMetadata);
62
- const bestCurrentMtimeMs = resolveStorageRootMtimeMs(params.canonicalRootDir);
63
- let best = {
64
- rootDir: params.canonicalRootDir,
65
- tokenHash: params.canonicalTokenHash,
66
- score: bestCurrentScore,
67
- mtimeMs: bestCurrentMtimeMs
68
- };
69
- let siblingEntries;
70
- try {
71
- siblingEntries = fs.readdirSync(parentDir, { withFileTypes: true });
72
- } catch {
73
- return {
74
- rootDir: best.rootDir,
75
- tokenHash: best.tokenHash
76
- };
77
- }
78
- const compatiblePopulatedSiblings = [];
79
- const populatedTokenHashes = bestCurrentScore > 0 ? [params.canonicalTokenHash] : [];
80
- for (const entry of siblingEntries.toSorted((a, b) => a.name.localeCompare(b.name))) {
81
- if (!entry.isDirectory()) continue;
82
- if (entry.name === params.canonicalTokenHash) continue;
83
- if (!isMatrixActiveTokenRootDirectory(entry.name)) continue;
84
- const candidateRootDir = path.join(parentDir, entry.name);
85
- const metadata = await readStoredRootMetadata(candidateRootDir);
86
- if (!isCompatibleStorageRoot({
87
- metadata,
88
- homeserver: params.homeserver,
89
- userId: params.userId,
90
- accountKey: params.accountKey,
91
- deviceId
92
- })) continue;
93
- const candidateScore = await scoreStorageRoot(candidateRootDir, metadata);
94
- if (candidateScore <= 0) continue;
95
- populatedTokenHashes.push(entry.name);
96
- compatiblePopulatedSiblings.push({
97
- rootDir: candidateRootDir,
98
- tokenHash: entry.name,
99
- score: candidateScore,
100
- mtimeMs: resolveStorageRootMtimeMs(candidateRootDir)
101
- });
102
- }
103
- for (const candidate of compatiblePopulatedSiblings) if (candidate.score > best.score || best.rootDir !== params.canonicalRootDir && candidate.score === best.score && candidate.mtimeMs > best.mtimeMs) best = candidate;
104
- if (populatedTokenHashes.length > 1) getMatrixRuntime().logging.getChildLogger({ module: "matrix-storage" }).warn("matrix: multiple populated token-hash storage roots detected", {
105
- parentDir,
106
- canonicalTokenHash: params.canonicalTokenHash,
107
- selectedTokenHash: best.tokenHash,
108
- populatedTokenHashes,
109
- populatedSiblingTokenHashes: compatiblePopulatedSiblings.map((root) => root.tokenHash),
110
- populatedRootCount: populatedTokenHashes.length
111
- });
112
- return {
113
- rootDir: best.rootDir,
114
- tokenHash: best.tokenHash
115
- };
116
- }
117
- async function resolveMatrixStoragePaths(params) {
118
- const env = params.env ?? process.env;
119
- const stateDir = params.stateDir ?? getMatrixRuntime().state.resolveStateDir(env, os.homedir);
120
- const canonical = resolveMatrixAccountStorageRoot({
121
- stateDir,
122
- homeserver: params.homeserver,
123
- userId: params.userId,
124
- accessToken: params.accessToken,
125
- accountId: params.accountId
126
- });
127
- const { rootDir, tokenHash } = await resolvePreferredMatrixStorageRoot({
128
- canonicalRootDir: canonical.rootDir,
129
- canonicalTokenHash: canonical.tokenHash,
130
- homeserver: params.homeserver,
131
- userId: params.userId,
132
- accountKey: canonical.accountKey,
133
- deviceId: params.deviceId
134
- });
135
- return {
136
- rootDir,
137
- storagePath: path.join(rootDir, "bot-storage.json"),
138
- cryptoPath: path.join(rootDir, "crypto"),
139
- recoveryKeyPath: path.join(rootDir, MATRIX_RECOVERY_KEY_FILENAME),
140
- idbSnapshotPath: path.join(rootDir, MATRIX_IDB_SNAPSHOT_FILENAME),
141
- accountKey: canonical.accountKey,
142
- tokenHash
143
- };
144
- }
145
- async function resolveMatrixStateFilePath(params) {
146
- const storagePaths = await resolveMatrixStoragePaths({
147
- homeserver: params.auth.homeserver,
148
- userId: params.auth.userId,
149
- accessToken: params.auth.accessToken,
150
- accountId: params.accountId ?? params.auth.accountId,
151
- deviceId: params.auth.deviceId,
152
- env: params.env,
153
- stateDir: params.stateDir
154
- });
155
- return path.join(storagePaths.rootDir, params.filename);
156
- }
157
- async function maybeMigrateLegacyStorage({ storagePaths }) {
158
- const { rootDir, storagePath, recoveryKeyPath } = storagePaths;
159
- const cryptoMigrationPath = path.join(rootDir, MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME);
160
- const hasAccountScopedLegacyStorageFile = fs.existsSync(storagePath);
161
- const syncCache = hasAccountScopedLegacyStorageFile ? await import("./sync-cache-state-C6sEmvJK.mjs").then((n) => n.s) : null;
162
- const hasAccountScopedLegacyStorage = hasAccountScopedLegacyStorageFile && await syncCache?.readLegacyMatrixSyncCacheState(rootDir) !== null;
163
- const hasAccountScopedRecoveryKey = fs.existsSync(recoveryKeyPath);
164
- const hasAccountScopedLegacyCryptoMigration = fs.existsSync(cryptoMigrationPath);
165
- if (!hasAccountScopedLegacyStorage && !hasAccountScopedRecoveryKey && !hasAccountScopedLegacyCryptoMigration) return;
166
- const logger = getMatrixRuntime().logging.getChildLogger({ module: "matrix-storage" });
167
- fs.mkdirSync(rootDir, { recursive: true });
168
- const migrations = [];
169
- let archiveSyncCache = false;
170
- try {
171
- if (syncCache && hasAccountScopedLegacyStorage) {
172
- const persisted = await syncCache.readLegacyMatrixSyncCacheState(rootDir);
173
- if (persisted) {
174
- const store = getMatrixRuntime().state.openKeyedStore(syncCache.openMatrixSyncCacheStoreOptions(rootDir));
175
- if (!await syncCache.hasMatrixSyncCacheStateInStore({
176
- storageRootDir: rootDir,
177
- store
178
- })) {
179
- await syncCache.writeMatrixSyncCacheStateToStore({
180
- storageRootDir: rootDir,
181
- payload: persisted,
182
- store
183
- });
184
- await claimCurrentTokenStorageState({ rootDir });
185
- migrations.push(`- account sync cache: ${storagePath} -> ${rootDir} SQLite sync cache`);
186
- }
187
- archiveSyncCache = true;
188
- }
189
- }
190
- if (hasAccountScopedRecoveryKey) {
191
- await migrateLegacyMatrixRecoveryKeyFilePathToStoreAsync(recoveryKeyPath, getMatrixRuntime().state);
192
- migrations.push(`- recovery key: ${recoveryKeyPath} -> ${rootDir} SQLite recovery key state`);
193
- }
194
- if (hasAccountScopedLegacyCryptoMigration) {
195
- await migrateLegacyMatrixLegacyCryptoMigrationFileToStore(rootDir);
196
- migrations.push(`- legacy crypto migration: ${cryptoMigrationPath} -> ${rootDir} SQLite legacy crypto migration state`);
197
- }
198
- } catch (err) {
199
- throw new Error(`Failed migrating legacy Matrix client storage: ${String(err)}`, { cause: err });
200
- }
201
- const archivePath = `${storagePath}.migrated`;
202
- const skippedArchive = archiveSyncCache && fs.existsSync(archivePath);
203
- if (archiveSyncCache && !skippedArchive) fs.renameSync(storagePath, archivePath);
204
- if (migrations.length > 0) logger.info(`matrix: migrated legacy client storage into ${rootDir}\n${migrations.join("\n")}`);
205
- if (skippedArchive) logger.warn?.(`matrix: legacy client storage files were left in place because their migrated targets already existed.
206
- - account sync cache remains at ${storagePath} because ${archivePath} already exists`);
207
- }
208
- function prepareStorageMetaMutation(metadata, mutation) {
209
- if (mutation.kind !== "initialize" && !metadata.accessTokenHash?.trim()) return null;
210
- return normalizeMatrixStorageMetadata({
211
- ...mutation.kind === "initialize" ? mutation.metadata : metadata,
212
- accountId: mutation.kind === "initialize" ? mutation.metadata.accountId : metadata.accountId ?? DEFAULT_ACCOUNT_KEY,
213
- deviceId: mutation.kind === "device" ? mutation.deviceId : mutation.kind === "initialize" ? mutation.metadata.deviceId ?? metadata.deviceId : metadata.deviceId,
214
- currentTokenStateClaimed: mutation.kind === "claim" || (mutation.kind === "initialize" ? mutation.metadata.currentTokenStateClaimed ?? metadata.currentTokenStateClaimed === true : metadata.currentTokenStateClaimed === true),
215
- createdAt: metadata.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
216
- });
217
- }
218
- async function mutateStorageMeta(rootDir, mutation) {
219
- try {
220
- const store = openStorageMetaStore(rootDir);
221
- const decode = (value) => normalizeMatrixStorageMetadata(value) ?? normalizeMatrixStorageMetadata(loadJsonFile(path.join(rootDir, STORAGE_META_FILENAME))) ?? {};
222
- if (!store.observe || !store.compareAndApply) {
223
- const legacyStore = getMatrixRuntime().state.openSyncKeyedStore(openMatrixStorageMetaStoreOptions(rootDir));
224
- const next = prepareStorageMetaMutation(decode(legacyStore.lookup(STORAGE_META_STATE_KEY)), mutation);
225
- if (!next) return false;
226
- legacyStore.register(STORAGE_META_STATE_KEY, next);
227
- return true;
228
- }
229
- let observation = await store.observe(STORAGE_META_STATE_KEY);
230
- for (;;) {
231
- const next = prepareStorageMetaMutation(decode(observation.value), mutation);
232
- if (!next) return false;
233
- const result = await store.compareAndApply(STORAGE_META_STATE_KEY, observation.comparison, {
234
- operation: "update",
235
- action: "set",
236
- value: next
237
- });
238
- if (result.status !== "conflict") return true;
239
- observation = result.current;
240
- }
241
- } catch {
242
- return false;
243
- }
244
- }
245
- async function writeStorageMeta(params) {
246
- return mutateStorageMeta(params.storagePaths.rootDir, {
247
- kind: "initialize",
248
- metadata: {
249
- homeserver: params.homeserver,
250
- userId: params.userId,
251
- accountId: params.accountId ?? DEFAULT_ACCOUNT_KEY,
252
- accessTokenHash: params.storagePaths.tokenHash,
253
- deviceId: params.deviceId ?? null,
254
- currentTokenStateClaimed: params.currentTokenStateClaimed
255
- }
256
- });
257
- }
258
- async function claimCurrentTokenStorageState(params) {
259
- return mutateStorageMeta(params.rootDir, { kind: "claim" });
260
- }
261
- async function recordCurrentStorageMetaDeviceId(params) {
262
- const rootDir = params.rootDir;
263
- const deviceId = params.deviceId.trim();
264
- if (!deviceId || !(await readStoredRootMetadata(rootDir)).accessTokenHash?.trim()) return false;
265
- return mutateStorageMeta(rootDir, {
266
- kind: "device",
267
- deviceId
268
- });
269
- }
270
- async function repairCurrentTokenStorageMetaDeviceId(params) {
271
- const { homeserver, userId, accessToken, accountId, deviceId, env, stateDir } = params;
272
- return writeStorageMeta({
273
- storagePaths: await resolveMatrixStoragePaths({
274
- homeserver,
275
- userId,
276
- accessToken,
277
- accountId,
278
- env,
279
- stateDir
280
- }),
281
- homeserver,
282
- userId,
283
- accountId,
284
- deviceId
285
- });
286
- }
287
- //#endregion
288
- export { resolveMatrixStateFilePath as a, repairCurrentTokenStorageMetaDeviceId as i, maybeMigrateLegacyStorage as n, resolveMatrixStoragePaths as o, recordCurrentStorageMetaDeviceId as r, writeStorageMeta as s, claimCurrentTokenStorageState as t };
@@ -1,371 +0,0 @@
1
- import { t as getMatrixRuntime } from "./runtime-1kn1P6io.mjs";
2
- import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
3
- import { createHash, randomUUID } from "node:crypto";
4
- import path from "node:path";
5
- import fs from "node:fs";
6
- import os from "node:os";
7
- //#region extensions/matrix/src/matrix/chunked-state.ts
8
- function chunkMatrixStateJson(value, maxBytes, maxChunks, limitMessage) {
9
- const chunks = [];
10
- const pushChunk = (chunk) => {
11
- if (chunks.length >= maxChunks) throw new Error(limitMessage);
12
- chunks.push(chunk);
13
- };
14
- let current = "";
15
- let currentBytes = 0;
16
- for (const char of value) {
17
- const charBytes = Buffer.byteLength(char, "utf8");
18
- if (current && currentBytes + charBytes > maxBytes) {
19
- pushChunk(current);
20
- current = "";
21
- currentBytes = 0;
22
- }
23
- current += char;
24
- currentBytes += charBytes;
25
- }
26
- if (current) pushChunk(current);
27
- return chunks;
28
- }
29
- async function readMatrixStateChunks(store, keys, kind) {
30
- const records = await store.lookupMany?.(keys);
31
- const chunks = [];
32
- for (let index = 0; index < keys.length; index += 1) {
33
- const result = records?.[index];
34
- if (result && !result.ok) throw result.error;
35
- const chunk = records ? result?.value : await store.lookup(keys[index]);
36
- if (!isRecord(chunk) || chunk.kind !== kind || chunk.index !== index || typeof chunk.data !== "string") return null;
37
- chunks.push(chunk.data);
38
- }
39
- return chunks;
40
- }
41
- async function writeMatrixStateChunks(store, rows, chunkKeyPrefix) {
42
- for (const row of rows.chunks) await store.register(row.key, row.value);
43
- await store.register(rows.meta.key, rows.meta.value);
44
- for (const row of await store.entries()) if (row.key.startsWith(chunkKeyPrefix) && !rows.nextChunkKeys.has(row.key)) await store.delete(row.key);
45
- }
46
- //#endregion
47
- //#region extensions/matrix/src/matrix/sqlite-state.ts
48
- function resolveStateDirOverride(options) {
49
- if (!options) return;
50
- return options.stateDir || options.stateRootDir || getMatrixRuntime().state.resolveStateDir(options.env ?? process.env, os.homedir);
51
- }
52
- function resolveMatrixSqliteStateKey(options) {
53
- return resolveStateDirOverride(options) ?? "";
54
- }
55
- function resolveMatrixSqliteStateEnv(options) {
56
- const stateDir = resolveStateDirOverride(options);
57
- if (!stateDir) return options?.env;
58
- return {
59
- ...options?.env ?? process.env,
60
- OPENCLAW_STATE_DIR: stateDir
61
- };
62
- }
63
- //#endregion
64
- //#region extensions/matrix/src/matrix/crypto-state-store.ts
65
- const STATE_KEY = "current";
66
- const RECOVERY_KEY_NAMESPACE = "recovery-key";
67
- const LEGACY_CRYPTO_MIGRATION_NAMESPACE = "legacy-crypto-migration";
68
- const IDB_SNAPSHOT_NAMESPACE = "idb-snapshot";
69
- const SMALL_STATE_MAX_ENTRIES = 10;
70
- const IDB_SNAPSHOT_MAX_ENTRIES = 2e4;
71
- const IDB_SNAPSHOT_MAX_CHUNKS = Math.floor(19999 / 2);
72
- const IDB_SNAPSHOT_CHUNK_BYTES = 24e3;
73
- const MATRIX_RECOVERY_KEY_FILENAME = "recovery-key.json";
74
- const MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME = "legacy-crypto-migration.json";
75
- const MATRIX_IDB_SNAPSHOT_FILENAME = "crypto-idb-snapshot.json";
76
- function openMatrixRecoveryKeyStoreOptions(storageRootDir) {
77
- return {
78
- namespace: RECOVERY_KEY_NAMESPACE,
79
- maxEntries: SMALL_STATE_MAX_ENTRIES,
80
- env: resolveMatrixSqliteStateEnv({ stateDir: storageRootDir })
81
- };
82
- }
83
- function openMatrixLegacyCryptoMigrationStoreOptions(storageRootDir) {
84
- return {
85
- namespace: LEGACY_CRYPTO_MIGRATION_NAMESPACE,
86
- maxEntries: SMALL_STATE_MAX_ENTRIES,
87
- env: resolveMatrixSqliteStateEnv({ stateDir: storageRootDir })
88
- };
89
- }
90
- function openMatrixIdbSnapshotStoreOptions(storageRootDir) {
91
- return {
92
- namespace: IDB_SNAPSHOT_NAMESPACE,
93
- maxEntries: IDB_SNAPSHOT_MAX_ENTRIES,
94
- env: resolveMatrixSqliteStateEnv({ stateDir: storageRootDir })
95
- };
96
- }
97
- async function readMatrixRecoveryKeyStateForPathAsync(recoveryKeyPath, stateRuntime) {
98
- return normalizeMatrixStoredRecoveryKey(await stateRuntime.openKeyedStore(openMatrixRecoveryKeyStoreOptions(path.dirname(recoveryKeyPath))).lookup(resolveRecoveryKeyStateKeyForPath(recoveryKeyPath)));
99
- }
100
- async function writeMatrixRecoveryKeyStateForPathAsync(params) {
101
- const payload = normalizeMatrixStoredRecoveryKey(params.payload);
102
- if (!payload) throw new Error("Invalid Matrix recovery key state");
103
- if (params.preserveEncodedPrivateKey) {
104
- await updateMatrixRecoveryKeyState(params, (current) => normalizeMatrixStoredRecoveryKey({
105
- ...payload,
106
- encodedPrivateKey: normalizeMatrixStoredRecoveryKey(current)?.encodedPrivateKey
107
- }) ?? void 0);
108
- return;
109
- }
110
- await params.stateRuntime.openKeyedStore(openMatrixRecoveryKeyStoreOptions(path.dirname(params.recoveryKeyPath))).register(resolveRecoveryKeyStateKeyForPath(params.recoveryKeyPath), payload);
111
- }
112
- async function updateMatrixRecoveryKeyState(params, update) {
113
- const store = params.stateRuntime.openKeyedStore(openMatrixRecoveryKeyStoreOptions(path.dirname(params.recoveryKeyPath)));
114
- const key = resolveRecoveryKeyStateKeyForPath(params.recoveryKeyPath);
115
- if (!store.observe || !store.compareAndApply) {
116
- if (!store.update) throw new Error("Matrix recovery key store does not support atomic updates");
117
- await store.update(key, update);
118
- return;
119
- }
120
- let observation = await store.observe(key);
121
- for (;;) {
122
- const value = update(observation.value);
123
- const result = await store.compareAndApply(key, observation.comparison, value === void 0 ? {
124
- operation: "update",
125
- action: "keep"
126
- } : {
127
- operation: "update",
128
- action: "set",
129
- value
130
- });
131
- if (result.status !== "conflict") return;
132
- observation = result.current;
133
- }
134
- }
135
- async function hasMatrixRecoveryKeyStateInStore(params) {
136
- return normalizeMatrixStoredRecoveryKey(await params.store.lookup(STATE_KEY)) !== null;
137
- }
138
- async function writeMatrixRecoveryKeyStateToStore(params) {
139
- const payload = normalizeMatrixStoredRecoveryKey(params.payload);
140
- if (!payload) throw new Error("Invalid Matrix recovery key state");
141
- await params.store.register(STATE_KEY, payload);
142
- }
143
- async function readMatrixLegacyCryptoMigrationState(storageRootDir) {
144
- return normalizeMatrixLegacyCryptoMigrationState(await getMatrixRuntime().state.openKeyedStore(openMatrixLegacyCryptoMigrationStoreOptions(storageRootDir)).lookup(STATE_KEY));
145
- }
146
- async function hasMatrixLegacyCryptoMigrationStateInStore(params) {
147
- return normalizeMatrixLegacyCryptoMigrationState(await params.store.lookup(STATE_KEY)) !== null;
148
- }
149
- async function writeMatrixLegacyCryptoMigrationStateToStore(params) {
150
- const state = normalizeMatrixLegacyCryptoMigrationState(params.state);
151
- if (!state) throw new Error("Invalid Matrix legacy crypto migration state");
152
- await params.store.register(STATE_KEY, state);
153
- }
154
- async function readMatrixIdbSnapshotJson(storageRootDir, stateRuntime = getMatrixRuntime().state) {
155
- return await readMatrixIdbSnapshotJsonFromStore({ store: stateRuntime.openKeyedStore(openMatrixIdbSnapshotStoreOptions(storageRootDir)) });
156
- }
157
- async function hasMatrixIdbSnapshotState(storageRootDir) {
158
- return isIdbSnapshotMeta(await getMatrixRuntime().state.openKeyedStore(openMatrixIdbSnapshotStoreOptions(storageRootDir)).lookup(idbMetaKey()));
159
- }
160
- async function writeMatrixIdbSnapshotJson(params) {
161
- await writeMatrixIdbSnapshotJsonToStore({
162
- snapshotJson: params.snapshotJson,
163
- databaseCount: params.databaseCount,
164
- store: (params.stateRuntime ?? getMatrixRuntime().state).openKeyedStore(openMatrixIdbSnapshotStoreOptions(params.storageRootDir))
165
- });
166
- }
167
- async function readMatrixIdbSnapshotJsonFromStore(params) {
168
- const meta = await params.store.lookup(idbMetaKey());
169
- if (!isIdbSnapshotMeta(meta)) return null;
170
- const chunks = await readMatrixStateChunks(params.store, Array.from({ length: meta.chunkCount }, (_, index) => idbChunkKey(meta.generation, index)), "snapshot-chunk");
171
- if (!chunks) return null;
172
- const snapshotJson = chunks.join("");
173
- return meta.digest === digestText(snapshotJson) ? snapshotJson : null;
174
- }
175
- async function writeMatrixIdbSnapshotJsonToStore(params) {
176
- const rows = buildIdbSnapshotRows(params.snapshotJson, params.databaseCount);
177
- await writeMatrixStateChunks(params.store, rows, idbChunkKeyPrefix());
178
- }
179
- async function migrateLegacyMatrixRecoveryKeyFilePathToStoreAsync(recoveryKeyPath, stateRuntime) {
180
- const legacy = readLegacyMatrixRecoveryKeyFile(recoveryKeyPath);
181
- if (legacy) await updateMatrixRecoveryKeyState({
182
- recoveryKeyPath,
183
- stateRuntime
184
- }, (current) => normalizeMatrixStoredRecoveryKey(current) ? void 0 : legacy);
185
- else await readMatrixRecoveryKeyStateForPathAsync(recoveryKeyPath, stateRuntime);
186
- return archiveLegacyStateFileIfPossible(recoveryKeyPath);
187
- }
188
- async function migrateLegacyMatrixLegacyCryptoMigrationFileToStore(storageRootDir) {
189
- const options = openMatrixLegacyCryptoMigrationStoreOptions(storageRootDir);
190
- const store = getMatrixRuntime().state.openKeyedStore(options);
191
- const legacy = readLegacyMatrixLegacyCryptoMigrationState(storageRootDir);
192
- if (!legacy) await store.lookup(STATE_KEY);
193
- else if (!store.observe || !store.compareAndApply) {
194
- const legacyStore = getMatrixRuntime().state.openSyncKeyedStore(options);
195
- if (!normalizeMatrixLegacyCryptoMigrationState(legacyStore.lookup(STATE_KEY))) legacyStore.register(STATE_KEY, legacy);
196
- } else {
197
- let observation = await store.observe(STATE_KEY);
198
- for (;;) {
199
- if (normalizeMatrixLegacyCryptoMigrationState(observation.value)) break;
200
- const result = await store.compareAndApply(STATE_KEY, observation.comparison, {
201
- operation: "update",
202
- action: "set",
203
- value: legacy
204
- });
205
- if (result.status !== "conflict") break;
206
- observation = result.current;
207
- }
208
- }
209
- return archiveLegacyStateFileIfPossible(path.join(storageRootDir, MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME));
210
- }
211
- function readLegacyMatrixRecoveryKeyState(storageRootDir) {
212
- return readLegacyMatrixRecoveryKeyFile(path.join(storageRootDir, MATRIX_RECOVERY_KEY_FILENAME));
213
- }
214
- function readLegacyMatrixRecoveryKeyFile(filePath) {
215
- return readJsonFileSync(filePath, normalizeMatrixStoredRecoveryKey);
216
- }
217
- function readLegacyMatrixLegacyCryptoMigrationState(storageRootDir) {
218
- return readJsonFileSync(path.join(storageRootDir, MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME), normalizeMatrixLegacyCryptoMigrationState);
219
- }
220
- async function scoreMatrixCryptoStateInStore(storageRootDir) {
221
- if (!matrixCryptoStateDatabaseExists(storageRootDir)) return 0;
222
- let score = 0;
223
- try {
224
- if (await readMatrixLegacyCryptoMigrationState(storageRootDir)) score += 3;
225
- } catch {}
226
- try {
227
- if (await readMatrixRecoveryKeyStateForPathAsync(path.join(storageRootDir, "recovery-key.json"), getMatrixRuntime().state)) score += 2;
228
- } catch {}
229
- try {
230
- if (await hasMatrixIdbSnapshotState(storageRootDir)) score += 2;
231
- } catch {}
232
- return score;
233
- }
234
- function matrixCryptoStateDatabaseExists(storageRootDir) {
235
- return fs.existsSync(path.join(storageRootDir, "state", "openclaw.sqlite"));
236
- }
237
- function resolveRecoveryKeyStateKeyForPath(recoveryKeyPath) {
238
- const basename = path.basename(recoveryKeyPath);
239
- if (basename === "recovery-key.json") return STATE_KEY;
240
- return `file:${createHash("sha256").update(basename, "utf8").digest("hex").slice(0, 32)}`;
241
- }
242
- function normalizeMatrixStoredRecoveryKey(value) {
243
- if (!isRecord(value) || value.version !== 1 || typeof value.createdAt !== "string" || typeof value.privateKeyBase64 !== "string" || !value.privateKeyBase64.trim()) return null;
244
- return {
245
- version: 1,
246
- createdAt: value.createdAt,
247
- keyId: typeof value.keyId === "string" ? value.keyId : null,
248
- ...typeof value.encodedPrivateKey === "string" ? { encodedPrivateKey: value.encodedPrivateKey } : {},
249
- privateKeyBase64: value.privateKeyBase64,
250
- ...isRecord(value.keyInfo) ? { keyInfo: {
251
- ...value.keyInfo.passphrase !== void 0 ? { passphrase: value.keyInfo.passphrase } : {},
252
- ...typeof value.keyInfo.name === "string" ? { name: value.keyInfo.name } : {}
253
- } } : {}
254
- };
255
- }
256
- function normalizeMatrixLegacyCryptoMigrationState(value) {
257
- if (!isRecord(value) || value.version !== 1 || typeof value.accountId !== "string") return null;
258
- if (value.restoreStatus !== "pending" && value.restoreStatus !== "completed" && value.restoreStatus !== "manual-action-required") return null;
259
- const roomKeyCounts = isRecord(value.roomKeyCounts) && typeof value.roomKeyCounts.total === "number" && typeof value.roomKeyCounts.backedUp === "number" ? {
260
- total: value.roomKeyCounts.total,
261
- backedUp: value.roomKeyCounts.backedUp
262
- } : null;
263
- return {
264
- version: 1,
265
- ...value.source === "matrix-bot-sdk-rust" ? { source: value.source } : {},
266
- accountId: value.accountId,
267
- ...typeof value.deviceId === "string" || value.deviceId === null ? { deviceId: value.deviceId } : {},
268
- roomKeyCounts,
269
- ...typeof value.backupVersion === "string" || value.backupVersion === null ? { backupVersion: value.backupVersion } : {},
270
- ...typeof value.decryptionKeyImported === "boolean" ? { decryptionKeyImported: value.decryptionKeyImported } : {},
271
- restoreStatus: value.restoreStatus,
272
- ...typeof value.detectedAt === "string" ? { detectedAt: value.detectedAt } : {},
273
- ...typeof value.restoredAt === "string" ? { restoredAt: value.restoredAt } : {},
274
- ...typeof value.importedCount === "number" ? { importedCount: value.importedCount } : {},
275
- ...typeof value.totalCount === "number" ? { totalCount: value.totalCount } : {},
276
- ...typeof value.lastError === "string" || value.lastError === null ? { lastError: value.lastError } : {}
277
- };
278
- }
279
- function readJsonFileSync(filePath, normalize) {
280
- try {
281
- return normalize(JSON.parse(fs.readFileSync(filePath, "utf8")));
282
- } catch {
283
- return null;
284
- }
285
- }
286
- function archiveLegacyStateFileIfPossible(filePath) {
287
- if (!fs.existsSync(filePath)) return false;
288
- const archivedPath = `${filePath}.migrated`;
289
- if (fs.existsSync(archivedPath)) return false;
290
- fs.renameSync(filePath, archivedPath);
291
- return true;
292
- }
293
- function buildIdbSnapshotRows(snapshotJson, databaseCount) {
294
- const generation = randomUUID().replaceAll("-", "");
295
- const chunks = chunkMatrixStateJson(snapshotJson, IDB_SNAPSHOT_CHUNK_BYTES, IDB_SNAPSHOT_MAX_CHUNKS, "Matrix IndexedDB snapshot exceeds SQLite chunk limit").map((data, index) => ({
296
- key: idbChunkKey(generation, index),
297
- value: {
298
- kind: "snapshot-chunk",
299
- index,
300
- data
301
- }
302
- }));
303
- return {
304
- chunks,
305
- nextChunkKeys: new Set(chunks.map((chunk) => chunk.key)),
306
- meta: {
307
- key: idbMetaKey(),
308
- value: {
309
- kind: "meta",
310
- version: 1,
311
- generation,
312
- chunkCount: chunks.length,
313
- digest: digestText(snapshotJson),
314
- databaseCount,
315
- persistedAt: (/* @__PURE__ */ new Date()).toISOString()
316
- }
317
- }
318
- };
319
- }
320
- function idbMetaKey() {
321
- return `${STATE_KEY}:meta`;
322
- }
323
- function idbChunkKeyPrefix() {
324
- return `${STATE_KEY}:snapshot:`;
325
- }
326
- function idbChunkKey(generation, index) {
327
- return `${idbChunkKeyPrefix()}${generation}:${index}`;
328
- }
329
- function digestText(value) {
330
- return createHash("sha256").update(value, "utf8").digest("hex");
331
- }
332
- function isIdbSnapshotMeta(value) {
333
- return isRecord(value) && value.kind === "meta" && value.version === 1 && typeof value.generation === "string" && value.generation.trim() !== "" && typeof value.chunkCount === "number" && Number.isSafeInteger(value.chunkCount) && value.chunkCount >= 0 && value.chunkCount <= IDB_SNAPSHOT_MAX_CHUNKS && typeof value.digest === "string" && typeof value.databaseCount === "number" && Number.isSafeInteger(value.databaseCount) && value.databaseCount >= 0 && typeof value.persistedAt === "string";
334
- }
335
- //#endregion
336
- //#region extensions/matrix/src/matrix/client/storage-metadata.ts
337
- const STORAGE_META_NAMESPACE = "storage-meta";
338
- const STORAGE_META_STATE_KEY = "current";
339
- const STORAGE_META_MAX_ENTRIES = 10;
340
- function openMatrixStorageMetaStoreOptions(storageRootDir) {
341
- return {
342
- namespace: STORAGE_META_NAMESPACE,
343
- maxEntries: STORAGE_META_MAX_ENTRIES,
344
- env: resolveMatrixSqliteStateEnv({ stateDir: storageRootDir })
345
- };
346
- }
347
- function normalizeMatrixStorageMetadata(value) {
348
- if (!isRecord(value)) return null;
349
- const metadata = {};
350
- for (const field of [
351
- "homeserver",
352
- "userId",
353
- "accountId",
354
- "accessTokenHash",
355
- "deviceId",
356
- "createdAt"
357
- ]) {
358
- const entry = value[field];
359
- if (typeof entry === "string" && entry.trim()) metadata[field] = entry.trim();
360
- }
361
- if (value.currentTokenStateClaimed === true) metadata.currentTokenStateClaimed = true;
362
- return Object.keys(metadata).length > 0 ? metadata : null;
363
- }
364
- async function hasMatrixStorageMetaStateInStore(params) {
365
- return normalizeMatrixStorageMetadata(await params.store.lookup(STORAGE_META_STATE_KEY)) !== null;
366
- }
367
- async function writeMatrixStorageMetaStateToStore(params) {
368
- await params.store.register(STORAGE_META_STATE_KEY, params.payload);
369
- }
370
- //#endregion
371
- export { chunkMatrixStateJson as A, writeMatrixIdbSnapshotJson as C, writeMatrixRecoveryKeyStateToStore as D, writeMatrixRecoveryKeyStateForPathAsync as E, writeMatrixStateChunks as M, resolveMatrixSqliteStateEnv as O, scoreMatrixCryptoStateInStore as S, writeMatrixLegacyCryptoMigrationStateToStore as T, readLegacyMatrixRecoveryKeyFile as _, writeMatrixStorageMetaStateToStore as a, readMatrixIdbSnapshotJsonFromStore as b, MATRIX_RECOVERY_KEY_FILENAME as c, migrateLegacyMatrixLegacyCryptoMigrationFileToStore as d, migrateLegacyMatrixRecoveryKeyFilePathToStoreAsync as f, readLegacyMatrixLegacyCryptoMigrationState as g, openMatrixRecoveryKeyStoreOptions as h, openMatrixStorageMetaStoreOptions as i, readMatrixStateChunks as j, resolveMatrixSqliteStateKey as k, hasMatrixLegacyCryptoMigrationStateInStore as l, openMatrixLegacyCryptoMigrationStoreOptions as m, hasMatrixStorageMetaStateInStore as n, MATRIX_IDB_SNAPSHOT_FILENAME as o, openMatrixIdbSnapshotStoreOptions as p, normalizeMatrixStorageMetadata as r, MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME as s, STORAGE_META_STATE_KEY as t, hasMatrixRecoveryKeyStateInStore as u, readLegacyMatrixRecoveryKeyState as v, writeMatrixIdbSnapshotJsonToStore as w, readMatrixRecoveryKeyStateForPathAsync as x, readMatrixIdbSnapshotJson as y };
@@ -1,6 +0,0 @@
1
- import { type RootContext } from "./root-context.js";
2
- import type { NativeWatchBatch } from "./watch-native.js";
3
- import type { WatchSnapshot } from "./watch-scan.js";
4
- import type { WatchChange, WatchScope } from "./watch-types.js";
5
- /** Resolve native spelling aliases without treating case folding as identity. */
6
- export declare function admittedNativeChanges(root: RootContext, scopes: readonly WatchScope[], before: WatchSnapshot | undefined, after: WatchSnapshot, batch: NativeWatchBatch, signal: AbortSignal, limit: number): Promise<WatchChange[] | undefined>;