@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
@@ -0,0 +1,464 @@
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 { c as chunkMatrixStateJson, i as assertMatrixSupportedStateRoot, l as readMatrixStateChunks, o as resolveMatrixSqliteStateEnv, r as assertMatrixSupportedStateFile, u as writeMatrixStateChunks } from "./retired-state-BXUQ2I-C.mjs";
4
+ import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
5
+ import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
6
+ import { createHash, randomUUID } from "node:crypto";
7
+ import path from "node:path";
8
+ import fs from "node:fs";
9
+ import os from "node:os";
10
+ //#region extensions/matrix/src/matrix/crypto-state-store.ts
11
+ const STATE_KEY = "current";
12
+ const RECOVERY_KEY_NAMESPACE = "recovery-key";
13
+ const LEGACY_CRYPTO_MIGRATION_NAMESPACE = "legacy-crypto-migration";
14
+ const IDB_SNAPSHOT_NAMESPACE = "idb-snapshot";
15
+ const SMALL_STATE_MAX_ENTRIES = 10;
16
+ const IDB_SNAPSHOT_MAX_ENTRIES = 2e4;
17
+ const IDB_SNAPSHOT_MAX_CHUNKS = Math.floor(19999 / 2);
18
+ const IDB_SNAPSHOT_CHUNK_BYTES = 24e3;
19
+ const MATRIX_RECOVERY_KEY_FILENAME = "recovery-key.json";
20
+ const MATRIX_IDB_SNAPSHOT_FILENAME = "crypto-idb-snapshot.json";
21
+ function openMatrixRecoveryKeyStoreOptions(storageRootDir) {
22
+ return {
23
+ namespace: RECOVERY_KEY_NAMESPACE,
24
+ maxEntries: SMALL_STATE_MAX_ENTRIES,
25
+ env: resolveMatrixSqliteStateEnv({ stateDir: storageRootDir })
26
+ };
27
+ }
28
+ function openMatrixLegacyCryptoMigrationStoreOptions(storageRootDir) {
29
+ return {
30
+ namespace: LEGACY_CRYPTO_MIGRATION_NAMESPACE,
31
+ maxEntries: SMALL_STATE_MAX_ENTRIES,
32
+ env: resolveMatrixSqliteStateEnv({ stateDir: storageRootDir })
33
+ };
34
+ }
35
+ function openMatrixIdbSnapshotStoreOptions(storageRootDir) {
36
+ return {
37
+ namespace: IDB_SNAPSHOT_NAMESPACE,
38
+ maxEntries: IDB_SNAPSHOT_MAX_ENTRIES,
39
+ env: resolveMatrixSqliteStateEnv({ stateDir: storageRootDir })
40
+ };
41
+ }
42
+ async function readMatrixRecoveryKeyStateForPathAsync(recoveryKeyPath, stateRuntime) {
43
+ return normalizeMatrixStoredRecoveryKey(await stateRuntime.openKeyedStore(openMatrixRecoveryKeyStoreOptions(path.dirname(recoveryKeyPath))).lookup(resolveRecoveryKeyStateKeyForPath(recoveryKeyPath)));
44
+ }
45
+ async function writeMatrixRecoveryKeyStateForPathAsync(params) {
46
+ const payload = normalizeMatrixStoredRecoveryKey(params.payload);
47
+ if (!payload) throw new Error("Invalid Matrix recovery key state");
48
+ if (params.preserveEncodedPrivateKey) {
49
+ await updateMatrixRecoveryKeyState(params, (current) => normalizeMatrixStoredRecoveryKey({
50
+ ...payload,
51
+ encodedPrivateKey: normalizeMatrixStoredRecoveryKey(current)?.encodedPrivateKey
52
+ }) ?? void 0);
53
+ return;
54
+ }
55
+ await params.stateRuntime.openKeyedStore(openMatrixRecoveryKeyStoreOptions(path.dirname(params.recoveryKeyPath))).register(resolveRecoveryKeyStateKeyForPath(params.recoveryKeyPath), payload);
56
+ }
57
+ async function updateMatrixRecoveryKeyState(params, update) {
58
+ const store = params.stateRuntime.openKeyedStore(openMatrixRecoveryKeyStoreOptions(path.dirname(params.recoveryKeyPath)));
59
+ const key = resolveRecoveryKeyStateKeyForPath(params.recoveryKeyPath);
60
+ if (!store.observe || !store.compareAndApply) {
61
+ if (!store.update) throw new Error("Matrix recovery key store does not support atomic updates");
62
+ await store.update(key, update);
63
+ return;
64
+ }
65
+ let observation = await store.observe(key);
66
+ for (;;) {
67
+ const value = update(observation.value);
68
+ const result = await store.compareAndApply(key, observation.comparison, value === void 0 ? {
69
+ operation: "update",
70
+ action: "keep"
71
+ } : {
72
+ operation: "update",
73
+ action: "set",
74
+ value
75
+ });
76
+ if (result.status !== "conflict") return;
77
+ observation = result.current;
78
+ }
79
+ }
80
+ async function readMatrixIdbSnapshotJson(storageRootDir, stateRuntime = getMatrixRuntime().state) {
81
+ const store = stateRuntime.openKeyedStore(openMatrixIdbSnapshotStoreOptions(storageRootDir));
82
+ const meta = await store.lookup(idbMetaKey());
83
+ if (!isIdbSnapshotMeta(meta)) return null;
84
+ const chunks = await readMatrixStateChunks(store, Array.from({ length: meta.chunkCount }, (_, index) => idbChunkKey(meta.generation, index)), "snapshot-chunk");
85
+ if (!chunks) return null;
86
+ const snapshotJson = chunks.join("");
87
+ return meta.digest === digestText(snapshotJson) ? snapshotJson : null;
88
+ }
89
+ async function hasMatrixIdbSnapshotState(storageRootDir) {
90
+ return isIdbSnapshotMeta(await getMatrixRuntime().state.openKeyedStore(openMatrixIdbSnapshotStoreOptions(storageRootDir)).lookup(idbMetaKey()));
91
+ }
92
+ async function writeMatrixIdbSnapshotJson(params) {
93
+ const store = (params.stateRuntime ?? getMatrixRuntime().state).openKeyedStore(openMatrixIdbSnapshotStoreOptions(params.storageRootDir));
94
+ const rows = buildIdbSnapshotRows(params.snapshotJson, params.databaseCount);
95
+ await writeMatrixStateChunks(store, rows, idbChunkKeyPrefix());
96
+ }
97
+ async function scoreMatrixCryptoStateInStore(storageRootDir) {
98
+ if (!matrixCryptoStateDatabaseExists(storageRootDir)) return 0;
99
+ let score = 0;
100
+ try {
101
+ const migration = await getMatrixRuntime().state.openKeyedStore(openMatrixLegacyCryptoMigrationStoreOptions(storageRootDir)).lookup(STATE_KEY);
102
+ if (isRecord(migration) && migration.version === 1 && typeof migration.accountId === "string" && (migration.restoreStatus === "pending" || migration.restoreStatus === "completed" || migration.restoreStatus === "manual-action-required")) score += 3;
103
+ } catch {}
104
+ try {
105
+ if (await readMatrixRecoveryKeyStateForPathAsync(path.join(storageRootDir, "recovery-key.json"), getMatrixRuntime().state)) score += 2;
106
+ } catch {}
107
+ try {
108
+ if (await hasMatrixIdbSnapshotState(storageRootDir)) score += 2;
109
+ } catch {}
110
+ return score;
111
+ }
112
+ function matrixCryptoStateDatabaseExists(storageRootDir) {
113
+ return fs.existsSync(path.join(storageRootDir, "state", "openclaw.sqlite"));
114
+ }
115
+ function resolveRecoveryKeyStateKeyForPath(recoveryKeyPath) {
116
+ const basename = path.basename(recoveryKeyPath);
117
+ if (basename === "recovery-key.json") return STATE_KEY;
118
+ return `file:${createHash("sha256").update(basename, "utf8").digest("hex").slice(0, 32)}`;
119
+ }
120
+ function normalizeMatrixStoredRecoveryKey(value) {
121
+ if (!isRecord(value) || value.version !== 1 || typeof value.createdAt !== "string" || typeof value.privateKeyBase64 !== "string" || !value.privateKeyBase64.trim()) return null;
122
+ return {
123
+ version: 1,
124
+ createdAt: value.createdAt,
125
+ keyId: typeof value.keyId === "string" ? value.keyId : null,
126
+ ...typeof value.encodedPrivateKey === "string" ? { encodedPrivateKey: value.encodedPrivateKey } : {},
127
+ privateKeyBase64: value.privateKeyBase64,
128
+ ...isRecord(value.keyInfo) ? { keyInfo: {
129
+ ...value.keyInfo.passphrase !== void 0 ? { passphrase: value.keyInfo.passphrase } : {},
130
+ ...typeof value.keyInfo.name === "string" ? { name: value.keyInfo.name } : {}
131
+ } } : {}
132
+ };
133
+ }
134
+ function buildIdbSnapshotRows(snapshotJson, databaseCount) {
135
+ const generation = randomUUID().replaceAll("-", "");
136
+ const chunks = chunkMatrixStateJson(snapshotJson, IDB_SNAPSHOT_CHUNK_BYTES, IDB_SNAPSHOT_MAX_CHUNKS, "Matrix IndexedDB snapshot exceeds SQLite chunk limit").map((data, index) => ({
137
+ key: idbChunkKey(generation, index),
138
+ value: {
139
+ kind: "snapshot-chunk",
140
+ index,
141
+ data
142
+ }
143
+ }));
144
+ return {
145
+ chunks,
146
+ nextChunkKeys: new Set(chunks.map((chunk) => chunk.key)),
147
+ meta: {
148
+ key: idbMetaKey(),
149
+ value: {
150
+ kind: "meta",
151
+ version: 1,
152
+ generation,
153
+ chunkCount: chunks.length,
154
+ digest: digestText(snapshotJson),
155
+ databaseCount,
156
+ persistedAt: (/* @__PURE__ */ new Date()).toISOString()
157
+ }
158
+ }
159
+ };
160
+ }
161
+ function idbMetaKey() {
162
+ return `${STATE_KEY}:meta`;
163
+ }
164
+ function idbChunkKeyPrefix() {
165
+ return `${STATE_KEY}:snapshot:`;
166
+ }
167
+ function idbChunkKey(generation, index) {
168
+ return `${idbChunkKeyPrefix()}${generation}:${index}`;
169
+ }
170
+ function digestText(value) {
171
+ return createHash("sha256").update(value, "utf8").digest("hex");
172
+ }
173
+ function isIdbSnapshotMeta(value) {
174
+ 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";
175
+ }
176
+ //#endregion
177
+ //#region extensions/matrix/src/matrix/client/storage-metadata.ts
178
+ const STORAGE_META_NAMESPACE = "storage-meta";
179
+ const STORAGE_META_STATE_KEY = "current";
180
+ const STORAGE_META_MAX_ENTRIES = 10;
181
+ function openMatrixStorageMetaStoreOptions(storageRootDir) {
182
+ return {
183
+ namespace: STORAGE_META_NAMESPACE,
184
+ maxEntries: STORAGE_META_MAX_ENTRIES,
185
+ env: resolveMatrixSqliteStateEnv({ stateDir: storageRootDir })
186
+ };
187
+ }
188
+ function normalizeMatrixStorageMetadata(value) {
189
+ if (!isRecord(value)) return null;
190
+ const metadata = {};
191
+ for (const field of [
192
+ "homeserver",
193
+ "userId",
194
+ "accountId",
195
+ "accessTokenHash",
196
+ "deviceId",
197
+ "createdAt"
198
+ ]) {
199
+ const entry = value[field];
200
+ if (typeof entry === "string" && entry.trim()) metadata[field] = entry.trim();
201
+ }
202
+ if (value.currentTokenStateClaimed === true) metadata.currentTokenStateClaimed = true;
203
+ return Object.keys(metadata).length > 0 ? metadata : null;
204
+ }
205
+ //#endregion
206
+ //#region extensions/matrix/src/matrix/client/storage.ts
207
+ const DEFAULT_ACCOUNT_KEY = "default";
208
+ const STORAGE_META_FILENAME = "storage-meta.json";
209
+ function openStorageMetaStore(rootDir) {
210
+ return getMatrixRuntime().state.openKeyedStore(openMatrixStorageMetaStoreOptions(rootDir));
211
+ }
212
+ async function scoreStorageRoot(rootDir, metadata) {
213
+ let score = 0;
214
+ if (Object.keys(metadata).length > 0) score += 1;
215
+ if (metadata.currentTokenStateClaimed === true) score += 8;
216
+ if (fs.existsSync(path.join(rootDir, "crypto"))) score += 8;
217
+ score += await scoreMatrixCryptoStateInStore(rootDir);
218
+ return score;
219
+ }
220
+ function resolveStorageRootMtimeMs(rootDir) {
221
+ try {
222
+ return fs.statSync(rootDir).mtimeMs;
223
+ } catch {
224
+ return 0;
225
+ }
226
+ }
227
+ async function readStoredRootMetadata(rootDir) {
228
+ await assertMatrixSupportedStateFile(path.join(rootDir, STORAGE_META_FILENAME));
229
+ if (fs.existsSync(path.join(rootDir, "state", "openclaw.sqlite"))) try {
230
+ const stored = normalizeMatrixStorageMetadata(await openStorageMetaStore(rootDir).lookup(STORAGE_META_STATE_KEY));
231
+ if (stored) return stored;
232
+ } catch {}
233
+ return {};
234
+ }
235
+ function isCompatibleStorageRoot(params) {
236
+ const { metadata } = params;
237
+ if (metadata.homeserver && metadata.homeserver !== params.homeserver) return false;
238
+ if (metadata.userId && metadata.userId !== params.userId) return false;
239
+ if (metadata.accountId && normalizeAccountId(metadata.accountId) !== normalizeAccountId(params.accountKey)) return false;
240
+ return metadata.deviceId?.trim() === params.deviceId.trim();
241
+ }
242
+ async function resolvePreferredMatrixStorageRoot(params) {
243
+ const canonical = {
244
+ rootDir: params.canonicalRootDir,
245
+ tokenHash: params.canonicalTokenHash
246
+ };
247
+ const deviceId = params.deviceId?.trim();
248
+ if (!deviceId) return canonical;
249
+ const canonicalMetadata = await readStoredRootMetadata(params.canonicalRootDir);
250
+ if (canonicalMetadata.accessTokenHash === params.canonicalTokenHash && canonicalMetadata.deviceId?.trim() === deviceId && canonicalMetadata.currentTokenStateClaimed === true) return canonical;
251
+ const parentDir = path.dirname(params.canonicalRootDir);
252
+ const bestCurrentScore = await scoreStorageRoot(params.canonicalRootDir, canonicalMetadata);
253
+ const bestCurrentMtimeMs = resolveStorageRootMtimeMs(params.canonicalRootDir);
254
+ let best = {
255
+ rootDir: params.canonicalRootDir,
256
+ tokenHash: params.canonicalTokenHash,
257
+ score: bestCurrentScore,
258
+ mtimeMs: bestCurrentMtimeMs
259
+ };
260
+ let siblingEntries;
261
+ try {
262
+ siblingEntries = fs.readdirSync(parentDir, { withFileTypes: true });
263
+ } catch {
264
+ return {
265
+ rootDir: best.rootDir,
266
+ tokenHash: best.tokenHash
267
+ };
268
+ }
269
+ const compatiblePopulatedSiblings = [];
270
+ const populatedTokenHashes = bestCurrentScore > 0 ? [params.canonicalTokenHash] : [];
271
+ for (const entry of siblingEntries.toSorted((a, b) => a.name.localeCompare(b.name))) {
272
+ if (!entry.isDirectory()) continue;
273
+ if (entry.name === params.canonicalTokenHash) continue;
274
+ if (!isMatrixActiveTokenRootDirectory(entry.name)) continue;
275
+ const candidateRootDir = path.join(parentDir, entry.name);
276
+ const metadata = await readStoredRootMetadata(candidateRootDir);
277
+ if (!isCompatibleStorageRoot({
278
+ metadata,
279
+ homeserver: params.homeserver,
280
+ userId: params.userId,
281
+ accountKey: params.accountKey,
282
+ deviceId
283
+ })) continue;
284
+ const candidateScore = await scoreStorageRoot(candidateRootDir, metadata);
285
+ if (candidateScore <= 0) continue;
286
+ populatedTokenHashes.push(entry.name);
287
+ compatiblePopulatedSiblings.push({
288
+ rootDir: candidateRootDir,
289
+ tokenHash: entry.name,
290
+ score: candidateScore,
291
+ mtimeMs: resolveStorageRootMtimeMs(candidateRootDir)
292
+ });
293
+ }
294
+ for (const candidate of compatiblePopulatedSiblings) if (candidate.score > best.score || best.rootDir !== params.canonicalRootDir && candidate.score === best.score && candidate.mtimeMs > best.mtimeMs) best = candidate;
295
+ if (populatedTokenHashes.length > 1) getMatrixRuntime().logging.getChildLogger({ module: "matrix-storage" }).warn("matrix: multiple populated token-hash storage roots detected", {
296
+ parentDir,
297
+ canonicalTokenHash: params.canonicalTokenHash,
298
+ selectedTokenHash: best.tokenHash,
299
+ populatedTokenHashes,
300
+ populatedSiblingTokenHashes: compatiblePopulatedSiblings.map((root) => root.tokenHash),
301
+ populatedRootCount: populatedTokenHashes.length
302
+ });
303
+ return {
304
+ rootDir: best.rootDir,
305
+ tokenHash: best.tokenHash
306
+ };
307
+ }
308
+ async function resolveMatrixStoragePaths(params) {
309
+ const env = params.env ?? process.env;
310
+ const stateDir = params.stateDir ?? getMatrixRuntime().state.resolveStateDir(env, os.homedir);
311
+ const canonical = resolveMatrixAccountStorageRoot({
312
+ stateDir,
313
+ homeserver: params.homeserver,
314
+ userId: params.userId,
315
+ accessToken: params.accessToken,
316
+ accountId: params.accountId
317
+ });
318
+ const { rootDir, tokenHash } = await resolvePreferredMatrixStorageRoot({
319
+ canonicalRootDir: canonical.rootDir,
320
+ canonicalTokenHash: canonical.tokenHash,
321
+ homeserver: params.homeserver,
322
+ userId: params.userId,
323
+ accountKey: canonical.accountKey,
324
+ deviceId: params.deviceId
325
+ });
326
+ return {
327
+ rootDir,
328
+ storagePath: path.join(rootDir, "bot-storage.json"),
329
+ cryptoPath: path.join(rootDir, "crypto"),
330
+ recoveryKeyPath: path.join(rootDir, MATRIX_RECOVERY_KEY_FILENAME),
331
+ idbSnapshotPath: path.join(rootDir, MATRIX_IDB_SNAPSHOT_FILENAME),
332
+ accountKey: canonical.accountKey,
333
+ tokenHash
334
+ };
335
+ }
336
+ async function resolveMatrixStateFilePath(params) {
337
+ const storagePaths = await resolveMatrixStoragePaths({
338
+ homeserver: params.auth.homeserver,
339
+ userId: params.auth.userId,
340
+ accessToken: params.auth.accessToken,
341
+ accountId: params.accountId ?? params.auth.accountId,
342
+ deviceId: params.auth.deviceId,
343
+ env: params.env,
344
+ stateDir: params.stateDir
345
+ });
346
+ return path.join(storagePaths.rootDir, params.filename);
347
+ }
348
+ async function maybeMigrateLegacyStorage({ storagePaths }) {
349
+ const { rootDir, storagePath } = storagePaths;
350
+ await assertMatrixSupportedStateRoot(rootDir);
351
+ if (!fs.existsSync(storagePath)) return;
352
+ const syncCache = await import("./sync-cache-state-C2z64uyk.mjs").then((n) => n.o);
353
+ if (!await syncCache.readLegacyMatrixSyncCacheState(rootDir)) return;
354
+ const logger = getMatrixRuntime().logging.getChildLogger({ module: "matrix-storage" });
355
+ fs.mkdirSync(rootDir, { recursive: true });
356
+ let migrated = false;
357
+ try {
358
+ const persisted = await syncCache.readLegacyMatrixSyncCacheState(rootDir);
359
+ if (!persisted) return;
360
+ const store = getMatrixRuntime().state.openKeyedStore(syncCache.openMatrixSyncCacheStoreOptions(rootDir));
361
+ if (!await syncCache.hasMatrixSyncCacheStateInStore({
362
+ storageRootDir: rootDir,
363
+ store
364
+ })) {
365
+ await syncCache.writeMatrixSyncCacheStateToStore({
366
+ storageRootDir: rootDir,
367
+ payload: persisted,
368
+ store
369
+ });
370
+ await claimCurrentTokenStorageState({ rootDir });
371
+ migrated = true;
372
+ }
373
+ } catch (err) {
374
+ throw new Error(`Failed migrating legacy Matrix client storage: ${String(err)}`, { cause: err });
375
+ }
376
+ const archivePath = `${storagePath}.migrated`;
377
+ const skippedArchive = fs.existsSync(archivePath);
378
+ if (!skippedArchive) fs.renameSync(storagePath, archivePath);
379
+ if (migrated) logger.info(`matrix: migrated legacy client storage into ${rootDir}\n- account sync cache: ${storagePath} -> ${rootDir} SQLite sync cache`);
380
+ if (skippedArchive) logger.warn?.(`matrix: legacy client storage files were left in place because their migrated targets already existed.
381
+ - account sync cache remains at ${storagePath} because ${archivePath} already exists`);
382
+ }
383
+ function prepareStorageMetaMutation(metadata, mutation) {
384
+ if (mutation.kind !== "initialize" && !metadata.accessTokenHash?.trim()) return null;
385
+ return normalizeMatrixStorageMetadata({
386
+ ...mutation.kind === "initialize" ? mutation.metadata : metadata,
387
+ accountId: mutation.kind === "initialize" ? mutation.metadata.accountId : metadata.accountId ?? DEFAULT_ACCOUNT_KEY,
388
+ deviceId: mutation.kind === "device" ? mutation.deviceId : mutation.kind === "initialize" ? mutation.metadata.deviceId ?? metadata.deviceId : metadata.deviceId,
389
+ currentTokenStateClaimed: mutation.kind === "claim" || (mutation.kind === "initialize" ? mutation.metadata.currentTokenStateClaimed ?? metadata.currentTokenStateClaimed === true : metadata.currentTokenStateClaimed === true),
390
+ createdAt: metadata.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
391
+ });
392
+ }
393
+ async function mutateStorageMeta(rootDir, mutation) {
394
+ await assertMatrixSupportedStateFile(path.join(rootDir, STORAGE_META_FILENAME));
395
+ try {
396
+ const store = openStorageMetaStore(rootDir);
397
+ const decode = (value) => normalizeMatrixStorageMetadata(value) ?? {};
398
+ if (!store.observe || !store.compareAndApply) {
399
+ const legacyStore = getMatrixRuntime().state.openSyncKeyedStore(openMatrixStorageMetaStoreOptions(rootDir));
400
+ const next = prepareStorageMetaMutation(decode(legacyStore.lookup(STORAGE_META_STATE_KEY)), mutation);
401
+ if (!next) return false;
402
+ legacyStore.register(STORAGE_META_STATE_KEY, next);
403
+ return true;
404
+ }
405
+ let observation = await store.observe(STORAGE_META_STATE_KEY);
406
+ for (;;) {
407
+ const next = prepareStorageMetaMutation(decode(observation.value), mutation);
408
+ if (!next) return false;
409
+ const result = await store.compareAndApply(STORAGE_META_STATE_KEY, observation.comparison, {
410
+ operation: "update",
411
+ action: "set",
412
+ value: next
413
+ });
414
+ if (result.status !== "conflict") return true;
415
+ observation = result.current;
416
+ }
417
+ } catch {
418
+ return false;
419
+ }
420
+ }
421
+ async function writeStorageMeta(params) {
422
+ return mutateStorageMeta(params.storagePaths.rootDir, {
423
+ kind: "initialize",
424
+ metadata: {
425
+ homeserver: params.homeserver,
426
+ userId: params.userId,
427
+ accountId: params.accountId ?? DEFAULT_ACCOUNT_KEY,
428
+ accessTokenHash: params.storagePaths.tokenHash,
429
+ deviceId: params.deviceId ?? null,
430
+ currentTokenStateClaimed: params.currentTokenStateClaimed
431
+ }
432
+ });
433
+ }
434
+ async function claimCurrentTokenStorageState(params) {
435
+ return mutateStorageMeta(params.rootDir, { kind: "claim" });
436
+ }
437
+ async function recordCurrentStorageMetaDeviceId(params) {
438
+ const rootDir = params.rootDir;
439
+ const deviceId = params.deviceId.trim();
440
+ if (!deviceId || !(await readStoredRootMetadata(rootDir)).accessTokenHash?.trim()) return false;
441
+ return mutateStorageMeta(rootDir, {
442
+ kind: "device",
443
+ deviceId
444
+ });
445
+ }
446
+ async function repairCurrentTokenStorageMetaDeviceId(params) {
447
+ const { homeserver, userId, accessToken, accountId, deviceId, env, stateDir } = params;
448
+ return writeStorageMeta({
449
+ storagePaths: await resolveMatrixStoragePaths({
450
+ homeserver,
451
+ userId,
452
+ accessToken,
453
+ accountId,
454
+ env,
455
+ stateDir
456
+ }),
457
+ homeserver,
458
+ userId,
459
+ accountId,
460
+ deviceId
461
+ });
462
+ }
463
+ //#endregion
464
+ export { resolveMatrixStateFilePath as a, readMatrixIdbSnapshotJson as c, writeMatrixRecoveryKeyStateForPathAsync as d, repairCurrentTokenStorageMetaDeviceId as i, readMatrixRecoveryKeyStateForPathAsync as l, maybeMigrateLegacyStorage as n, resolveMatrixStoragePaths as o, recordCurrentStorageMetaDeviceId as r, writeStorageMeta as s, claimCurrentTokenStorageState as t, writeMatrixIdbSnapshotJson as u };
@@ -1,5 +1,5 @@
1
- import { i as __exportAll } from "./doctor-contract-De6geW0h.mjs";
2
- import { A as chunkMatrixStateJson, M as writeMatrixStateChunks, O as resolveMatrixSqliteStateEnv, j as readMatrixStateChunks } from "./storage-metadata-BDRZ7vpX.mjs";
1
+ import { i as __exportAll } from "./doctor-contract-CsTNmbMa.mjs";
2
+ import { c as chunkMatrixStateJson, l as readMatrixStateChunks, o as resolveMatrixSqliteStateEnv, u as writeMatrixStateChunks } from "./retired-state-BXUQ2I-C.mjs";
3
3
  import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
4
4
  import { createHash, randomUUID } from "node:crypto";
5
5
  import path from "node:path";
@@ -15,7 +15,6 @@ var sync_cache_state_exports = /* @__PURE__ */ __exportAll({
15
15
  readPersistedStoreFromStore: () => readPersistedStoreFromStore,
16
16
  writeMatrixSyncCacheStateToStore: () => writeMatrixSyncCacheStateToStore
17
17
  });
18
- const MATRIX_SYNC_CACHE_VERSION = 1;
19
18
  const SYNC_CACHE_NAMESPACE = "sync-cache";
20
19
  const SYNC_CACHE_MAX_ENTRIES = 2e4;
21
20
  const SYNC_CACHE_MAX_CHUNKS = Math.floor(19999 / 2);
@@ -80,32 +79,19 @@ async function readPersistedStore(store) {
80
79
  const meta = await store.lookup(metaKey(stateKey));
81
80
  if (!isSyncCacheMeta(meta)) return null;
82
81
  const chunks = await readMatrixStateChunks(store, Array.from({ length: meta.chunkCount }, (_, index) => chunkKey(stateKey, meta.generation, index)), "sync-chunk");
83
- if (!chunks) return normalizePersistedStore({
84
- version: 1,
85
- savedSync: null,
86
- clientOptions: meta.clientOptions,
87
- cleanShutdown: false
88
- });
82
+ const syncJson = chunks?.join("") ?? "";
83
+ const intact = chunks !== null && (chunks.length === 0 || meta.syncDigest === digestText(syncJson));
89
84
  let savedSync = null;
90
- if (chunks.length > 0) {
91
- const syncJson = chunks.join("");
92
- if (meta.syncDigest !== digestText(syncJson)) return normalizePersistedStore({
93
- version: 1,
94
- savedSync: null,
95
- clientOptions: meta.clientOptions,
96
- cleanShutdown: false
97
- });
98
- try {
99
- savedSync = toPersistedSyncData(JSON.parse(syncJson));
100
- } catch {
101
- savedSync = null;
102
- }
85
+ if (intact && chunks.length > 0) try {
86
+ savedSync = toPersistedSyncData(JSON.parse(syncJson));
87
+ } catch {
88
+ savedSync = null;
103
89
  }
104
90
  return normalizePersistedStore({
105
91
  version: 1,
106
92
  savedSync,
107
93
  clientOptions: meta.clientOptions,
108
- cleanShutdown: meta.cleanShutdown
94
+ cleanShutdown: intact && meta.cleanShutdown
109
95
  });
110
96
  }
111
97
  function metaKey(stateKey) {
@@ -189,4 +175,4 @@ async function deleteMatrixSyncCacheStateFromStore(params) {
189
175
  });
190
176
  }
191
177
  //#endregion
192
- export { readLegacyMatrixSyncCacheState as a, writeMatrixSyncCacheStateToStore as c, openMatrixSyncCacheStoreOptions as i, deleteMatrixSyncCacheStateFromStore as n, readPersistedStoreFromStore as o, hasMatrixSyncCacheStateInStore as r, sync_cache_state_exports as s, MATRIX_SYNC_CACHE_VERSION as t };
178
+ export { readPersistedStoreFromStore as a, readLegacyMatrixSyncCacheState as i, hasMatrixSyncCacheStateInStore as n, sync_cache_state_exports as o, openMatrixSyncCacheStoreOptions as r, writeMatrixSyncCacheStateToStore as s, deleteMatrixSyncCacheStateFromStore as t };