kontexta 7.0.0 → 7.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/bundle/standalone/CHANGELOG.md +22 -0
  2. package/bundle/standalone/apps/web/.next/BUILD_ID +1 -1
  3. package/bundle/standalone/apps/web/.next/app-build-manifest.json +46 -46
  4. package/bundle/standalone/apps/web/.next/app-path-routes-manifest.json +11 -11
  5. package/bundle/standalone/apps/web/.next/build-manifest.json +2 -2
  6. package/bundle/standalone/apps/web/.next/prerender-manifest.json +18 -18
  7. package/bundle/standalone/apps/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  8. package/bundle/standalone/apps/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  9. package/bundle/standalone/apps/web/.next/server/app/_not-found.html +1 -1
  10. package/bundle/standalone/apps/web/.next/server/app/_not-found.rsc +1 -1
  11. package/bundle/standalone/apps/web/.next/server/app/api/about/route.js.nft.json +1 -1
  12. package/bundle/standalone/apps/web/.next/server/app/api/about/route_client-reference-manifest.js +1 -1
  13. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/hooks/route.js.nft.json +1 -1
  14. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/hooks/route_client-reference-manifest.js +1 -1
  15. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/mcp/route.js.nft.json +1 -1
  16. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/mcp/route_client-reference-manifest.js +1 -1
  17. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/route.js.nft.json +1 -1
  18. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/route_client-reference-manifest.js +1 -1
  19. package/bundle/standalone/apps/web/.next/server/app/api/agents/route.js.nft.json +1 -1
  20. package/bundle/standalone/apps/web/.next/server/app/api/agents/route_client-reference-manifest.js +1 -1
  21. package/bundle/standalone/apps/web/.next/server/app/api/auth/login/route.js.nft.json +1 -1
  22. package/bundle/standalone/apps/web/.next/server/app/api/auth/login/route_client-reference-manifest.js +1 -1
  23. package/bundle/standalone/apps/web/.next/server/app/api/auth/logout/route.js.nft.json +1 -1
  24. package/bundle/standalone/apps/web/.next/server/app/api/auth/logout/route_client-reference-manifest.js +1 -1
  25. package/bundle/standalone/apps/web/.next/server/app/api/auth/setup/route.js.nft.json +1 -1
  26. package/bundle/standalone/apps/web/.next/server/app/api/auth/setup/route_client-reference-manifest.js +1 -1
  27. package/bundle/standalone/apps/web/.next/server/app/api/auth/status/route.js.nft.json +1 -1
  28. package/bundle/standalone/apps/web/.next/server/app/api/auth/status/route_client-reference-manifest.js +1 -1
  29. package/bundle/standalone/apps/web/.next/server/app/api/auth/token/route.js.nft.json +1 -1
  30. package/bundle/standalone/apps/web/.next/server/app/api/auth/token/route_client-reference-manifest.js +1 -1
  31. package/bundle/standalone/apps/web/.next/server/app/api/brain/machines/[machineId]/route.js.nft.json +1 -1
  32. package/bundle/standalone/apps/web/.next/server/app/api/brain/machines/[machineId]/route_client-reference-manifest.js +1 -1
  33. package/bundle/standalone/apps/web/.next/server/app/api/brain/route.js.nft.json +1 -1
  34. package/bundle/standalone/apps/web/.next/server/app/api/brain/route_client-reference-manifest.js +1 -1
  35. package/bundle/standalone/apps/web/.next/server/app/api/brain/share/route.js.nft.json +1 -1
  36. package/bundle/standalone/apps/web/.next/server/app/api/brain/share/route_client-reference-manifest.js +1 -1
  37. package/bundle/standalone/apps/web/.next/server/app/api/calendar/conflicts/route.js.nft.json +1 -1
  38. package/bundle/standalone/apps/web/.next/server/app/api/calendar/conflicts/route_client-reference-manifest.js +1 -1
  39. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/[id]/route.js.nft.json +1 -1
  40. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/[id]/route_client-reference-manifest.js +1 -1
  41. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/route.js.nft.json +1 -1
  42. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/route_client-reference-manifest.js +1 -1
  43. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/[id]/route.js.nft.json +1 -1
  44. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/[id]/route_client-reference-manifest.js +1 -1
  45. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/route.js.nft.json +1 -1
  46. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/route_client-reference-manifest.js +1 -1
  47. package/bundle/standalone/apps/web/.next/server/app/api/calendar/ics/route.js.nft.json +1 -1
  48. package/bundle/standalone/apps/web/.next/server/app/api/calendar/ics/route_client-reference-manifest.js +1 -1
  49. package/bundle/standalone/apps/web/.next/server/app/api/calendar/links/route.js.nft.json +1 -1
  50. package/bundle/standalone/apps/web/.next/server/app/api/calendar/links/route_client-reference-manifest.js +1 -1
  51. package/bundle/standalone/apps/web/.next/server/app/api/calendar/settings/route.js.nft.json +1 -1
  52. package/bundle/standalone/apps/web/.next/server/app/api/calendar/settings/route_client-reference-manifest.js +1 -1
  53. package/bundle/standalone/apps/web/.next/server/app/api/clip/route.js.nft.json +1 -1
  54. package/bundle/standalone/apps/web/.next/server/app/api/clip/route_client-reference-manifest.js +1 -1
  55. package/bundle/standalone/apps/web/.next/server/app/api/conflicts/[gid]/route.js.nft.json +1 -1
  56. package/bundle/standalone/apps/web/.next/server/app/api/conflicts/[gid]/route_client-reference-manifest.js +1 -1
  57. package/bundle/standalone/apps/web/.next/server/app/api/conflicts/route.js.nft.json +1 -1
  58. package/bundle/standalone/apps/web/.next/server/app/api/conflicts/route_client-reference-manifest.js +1 -1
  59. package/bundle/standalone/apps/web/.next/server/app/api/docker-config/route.js.nft.json +1 -1
  60. package/bundle/standalone/apps/web/.next/server/app/api/docker-config/route_client-reference-manifest.js +1 -1
  61. package/bundle/standalone/apps/web/.next/server/app/api/export/zip/route.js +1 -1
  62. package/bundle/standalone/apps/web/.next/server/app/api/export/zip/route.js.nft.json +1 -1
  63. package/bundle/standalone/apps/web/.next/server/app/api/export/zip/route_client-reference-manifest.js +1 -1
  64. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/backlinks/route.js.nft.json +1 -1
  65. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/backlinks/route_client-reference-manifest.js +1 -1
  66. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/download/route.js.nft.json +1 -1
  67. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/download/route_client-reference-manifest.js +1 -1
  68. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-html/route.js.nft.json +1 -1
  69. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-html/route_client-reference-manifest.js +1 -1
  70. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-pdf/route.js.nft.json +1 -1
  71. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-pdf/route_client-reference-manifest.js +1 -1
  72. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/restore/route.js.nft.json +1 -1
  73. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/restore/route_client-reference-manifest.js +1 -1
  74. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/route.js.nft.json +1 -1
  75. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/route_client-reference-manifest.js +1 -1
  76. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/move/route.js.nft.json +1 -1
  77. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/move/route_client-reference-manifest.js +1 -1
  78. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/route.js +1 -1
  79. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/route.js.nft.json +1 -1
  80. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/route_client-reference-manifest.js +1 -1
  81. package/bundle/standalone/apps/web/.next/server/app/api/files/route.js +1 -1
  82. package/bundle/standalone/apps/web/.next/server/app/api/files/route.js.nft.json +1 -1
  83. package/bundle/standalone/apps/web/.next/server/app/api/files/route_client-reference-manifest.js +1 -1
  84. package/bundle/standalone/apps/web/.next/server/app/api/files/upload/route.js.nft.json +1 -1
  85. package/bundle/standalone/apps/web/.next/server/app/api/files/upload/route_client-reference-manifest.js +1 -1
  86. package/bundle/standalone/apps/web/.next/server/app/api/folders/route.js +1 -1
  87. package/bundle/standalone/apps/web/.next/server/app/api/folders/route.js.nft.json +1 -1
  88. package/bundle/standalone/apps/web/.next/server/app/api/folders/route_client-reference-manifest.js +1 -1
  89. package/bundle/standalone/apps/web/.next/server/app/api/hands/test-pattern/route.js.nft.json +1 -1
  90. package/bundle/standalone/apps/web/.next/server/app/api/hands/test-pattern/route_client-reference-manifest.js +1 -1
  91. package/bundle/standalone/apps/web/.next/server/app/api/hands/validate/route.js.nft.json +1 -1
  92. package/bundle/standalone/apps/web/.next/server/app/api/hands/validate/route_client-reference-manifest.js +1 -1
  93. package/bundle/standalone/apps/web/.next/server/app/api/health/route.js.nft.json +1 -1
  94. package/bundle/standalone/apps/web/.next/server/app/api/health/route_client-reference-manifest.js +1 -1
  95. package/bundle/standalone/apps/web/.next/server/app/api/install-snippets/route.js.nft.json +1 -1
  96. package/bundle/standalone/apps/web/.next/server/app/api/install-snippets/route_client-reference-manifest.js +1 -1
  97. package/bundle/standalone/apps/web/.next/server/app/api/mcp-tools/route.js.nft.json +1 -1
  98. package/bundle/standalone/apps/web/.next/server/app/api/mcp-tools/route_client-reference-manifest.js +1 -1
  99. package/bundle/standalone/apps/web/.next/server/app/api/profile/route.js.nft.json +1 -1
  100. package/bundle/standalone/apps/web/.next/server/app/api/profile/route_client-reference-manifest.js +1 -1
  101. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/hands-config/route.js.nft.json +1 -1
  102. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/hands-config/route_client-reference-manifest.js +1 -1
  103. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-config/route.js.nft.json +1 -1
  104. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-config/route_client-reference-manifest.js +1 -1
  105. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-status/route.js.nft.json +1 -1
  106. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-status/route_client-reference-manifest.js +1 -1
  107. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/onboard/route.js.nft.json +1 -1
  108. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/onboard/route_client-reference-manifest.js +1 -1
  109. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/refresh/route.js.nft.json +1 -1
  110. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/refresh/route_client-reference-manifest.js +1 -1
  111. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/route.js.nft.json +1 -1
  112. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/route_client-reference-manifest.js +1 -1
  113. package/bundle/standalone/apps/web/.next/server/app/api/projects/onboard/route.js.nft.json +1 -1
  114. package/bundle/standalone/apps/web/.next/server/app/api/projects/onboard/route_client-reference-manifest.js +1 -1
  115. package/bundle/standalone/apps/web/.next/server/app/api/projects/route.js.nft.json +1 -1
  116. package/bundle/standalone/apps/web/.next/server/app/api/projects/route_client-reference-manifest.js +1 -1
  117. package/bundle/standalone/apps/web/.next/server/app/api/publish/html/route.js.nft.json +1 -1
  118. package/bundle/standalone/apps/web/.next/server/app/api/publish/html/route_client-reference-manifest.js +1 -1
  119. package/bundle/standalone/apps/web/.next/server/app/api/publish/route.js.nft.json +1 -1
  120. package/bundle/standalone/apps/web/.next/server/app/api/publish/route_client-reference-manifest.js +1 -1
  121. package/bundle/standalone/apps/web/.next/server/app/api/refresh/route.js.nft.json +1 -1
  122. package/bundle/standalone/apps/web/.next/server/app/api/refresh/route_client-reference-manifest.js +1 -1
  123. package/bundle/standalone/apps/web/.next/server/app/api/reindex/route.js.nft.json +1 -1
  124. package/bundle/standalone/apps/web/.next/server/app/api/reindex/route_client-reference-manifest.js +1 -1
  125. package/bundle/standalone/apps/web/.next/server/app/api/reports/resources/[name]/route.js.nft.json +1 -1
  126. package/bundle/standalone/apps/web/.next/server/app/api/reports/resources/[name]/route_client-reference-manifest.js +1 -1
  127. package/bundle/standalone/apps/web/.next/server/app/api/search/route.js.nft.json +1 -1
  128. package/bundle/standalone/apps/web/.next/server/app/api/search/route_client-reference-manifest.js +1 -1
  129. package/bundle/standalone/apps/web/.next/server/app/api/tags/route.js.nft.json +1 -1
  130. package/bundle/standalone/apps/web/.next/server/app/api/tags/route_client-reference-manifest.js +1 -1
  131. package/bundle/standalone/apps/web/.next/server/app/api/version-check/route.js.nft.json +1 -1
  132. package/bundle/standalone/apps/web/.next/server/app/api/version-check/route_client-reference-manifest.js +1 -1
  133. package/bundle/standalone/apps/web/.next/server/app/api/welcome/route.js.nft.json +1 -1
  134. package/bundle/standalone/apps/web/.next/server/app/api/welcome/route_client-reference-manifest.js +1 -1
  135. package/bundle/standalone/apps/web/.next/server/app/api/ws-config/route.js.nft.json +1 -1
  136. package/bundle/standalone/apps/web/.next/server/app/api/ws-config/route_client-reference-manifest.js +1 -1
  137. package/bundle/standalone/apps/web/.next/server/app/apple-icon.png/route.js.nft.json +1 -1
  138. package/bundle/standalone/apps/web/.next/server/app/brain/page.js.nft.json +1 -1
  139. package/bundle/standalone/apps/web/.next/server/app/brain/page_client-reference-manifest.js +1 -1
  140. package/bundle/standalone/apps/web/.next/server/app/calendar/page.js.nft.json +1 -1
  141. package/bundle/standalone/apps/web/.next/server/app/calendar/page_client-reference-manifest.js +1 -1
  142. package/bundle/standalone/apps/web/.next/server/app/conflicts/page.js.nft.json +1 -1
  143. package/bundle/standalone/apps/web/.next/server/app/conflicts/page_client-reference-manifest.js +1 -1
  144. package/bundle/standalone/apps/web/.next/server/app/favicon.ico/route.js.nft.json +1 -1
  145. package/bundle/standalone/apps/web/.next/server/app/icon.png/route.js.nft.json +1 -1
  146. package/bundle/standalone/apps/web/.next/server/app/login/page.js.nft.json +1 -1
  147. package/bundle/standalone/apps/web/.next/server/app/login/page_client-reference-manifest.js +1 -1
  148. package/bundle/standalone/apps/web/.next/server/app/page.js +1 -1
  149. package/bundle/standalone/apps/web/.next/server/app/page.js.nft.json +1 -1
  150. package/bundle/standalone/apps/web/.next/server/app/page_client-reference-manifest.js +1 -1
  151. package/bundle/standalone/apps/web/.next/server/app/preview/motifs/page.js.nft.json +1 -1
  152. package/bundle/standalone/apps/web/.next/server/app/preview/motifs/page_client-reference-manifest.js +1 -1
  153. package/bundle/standalone/apps/web/.next/server/app/preview/motifs.html +2 -2
  154. package/bundle/standalone/apps/web/.next/server/app/preview/motifs.rsc +1 -1
  155. package/bundle/standalone/apps/web/.next/server/app-paths-manifest.json +11 -11
  156. package/bundle/standalone/apps/web/.next/server/pages/404.html +1 -1
  157. package/bundle/standalone/apps/web/.next/server/pages/500.html +1 -1
  158. package/bundle/standalone/apps/web/.next/server/pages/_app.js.nft.json +1 -1
  159. package/bundle/standalone/apps/web/.next/server/pages/_document.js.nft.json +1 -1
  160. package/bundle/standalone/apps/web/.next/server/pages/_error.js.nft.json +1 -1
  161. package/bundle/standalone/apps/web/.next/server/server-reference-manifest.json +1 -1
  162. package/bundle/standalone/apps/web/.next/static/chunks/app/{page-c6c62b21883416e0.js → page-8935aa659bb421a6.js} +1 -1
  163. package/bundle/standalone/apps/web/package.json +4 -4
  164. package/bundle/standalone/node_modules/kontexta-mcp/dist/index.js +78 -31
  165. package/bundle/standalone/node_modules/kontexta-mcp/dist/index.js.map +1 -1
  166. package/bundle/standalone/node_modules/kontexta-mcp/dist/migrations/020-inline-content.sql +30 -0
  167. package/bundle/standalone/node_modules/kontexta-mcp/dist/transfer-cli.d.ts +3 -0
  168. package/bundle/standalone/node_modules/kontexta-mcp/dist/transfer-cli.d.ts.map +1 -0
  169. package/bundle/standalone/node_modules/kontexta-mcp/dist/transfer-cli.js +111 -0
  170. package/bundle/standalone/node_modules/kontexta-mcp/dist/transfer-cli.js.map +1 -0
  171. package/bundle/standalone/node_modules/kontexta-mcp/package.json +1 -1
  172. package/bundle/standalone/node_modules/kxta-core/dist/db/index.d.ts.map +1 -1
  173. package/bundle/standalone/node_modules/kxta-core/dist/db/index.js +7 -0
  174. package/bundle/standalone/node_modules/kxta-core/dist/db/index.js.map +1 -1
  175. package/bundle/standalone/node_modules/kxta-core/dist/db/inline-migration.d.ts +6 -0
  176. package/bundle/standalone/node_modules/kxta-core/dist/db/inline-migration.d.ts.map +1 -0
  177. package/bundle/standalone/node_modules/kxta-core/dist/db/inline-migration.js +77 -0
  178. package/bundle/standalone/node_modules/kxta-core/dist/db/inline-migration.js.map +1 -0
  179. package/bundle/standalone/node_modules/kxta-core/dist/db/migrations/020-inline-content.sql +30 -0
  180. package/bundle/standalone/node_modules/kxta-core/dist/files/index.d.ts +6 -2
  181. package/bundle/standalone/node_modules/kxta-core/dist/files/index.d.ts.map +1 -1
  182. package/bundle/standalone/node_modules/kxta-core/dist/files/index.js +213 -109
  183. package/bundle/standalone/node_modules/kxta-core/dist/files/index.js.map +1 -1
  184. package/bundle/standalone/node_modules/kxta-core/dist/git/index.d.ts.map +1 -1
  185. package/bundle/standalone/node_modules/kxta-core/dist/git/index.js +38 -0
  186. package/bundle/standalone/node_modules/kxta-core/dist/git/index.js.map +1 -1
  187. package/bundle/standalone/node_modules/kxta-core/dist/index.d.ts +1 -0
  188. package/bundle/standalone/node_modules/kxta-core/dist/index.d.ts.map +1 -1
  189. package/bundle/standalone/node_modules/kxta-core/dist/index.js +1 -0
  190. package/bundle/standalone/node_modules/kxta-core/dist/index.js.map +1 -1
  191. package/bundle/standalone/node_modules/kxta-core/dist/journal/distill.d.ts.map +1 -1
  192. package/bundle/standalone/node_modules/kxta-core/dist/journal/distill.js +84 -15
  193. package/bundle/standalone/node_modules/kxta-core/dist/journal/distill.js.map +1 -1
  194. package/bundle/standalone/node_modules/kxta-core/dist/journal/housekeep.d.ts.map +1 -1
  195. package/bundle/standalone/node_modules/kxta-core/dist/journal/housekeep.js +12 -2
  196. package/bundle/standalone/node_modules/kxta-core/dist/journal/housekeep.js.map +1 -1
  197. package/bundle/standalone/node_modules/kxta-core/dist/journal/patterns/tool-classes.d.ts.map +1 -1
  198. package/bundle/standalone/node_modules/kxta-core/dist/journal/patterns/tool-classes.js +4 -2
  199. package/bundle/standalone/node_modules/kxta-core/dist/journal/patterns/tool-classes.js.map +1 -1
  200. package/bundle/standalone/node_modules/kxta-core/dist/metadata/index.d.ts.map +1 -1
  201. package/bundle/standalone/node_modules/kxta-core/dist/metadata/index.js +26 -18
  202. package/bundle/standalone/node_modules/kxta-core/dist/metadata/index.js.map +1 -1
  203. package/bundle/standalone/node_modules/kxta-core/dist/revisions/index.d.ts +52 -0
  204. package/bundle/standalone/node_modules/kxta-core/dist/revisions/index.d.ts.map +1 -0
  205. package/bundle/standalone/node_modules/kxta-core/dist/revisions/index.js +151 -0
  206. package/bundle/standalone/node_modules/kxta-core/dist/revisions/index.js.map +1 -0
  207. package/bundle/standalone/node_modules/kxta-core/dist/storage/apply.d.ts.map +1 -1
  208. package/bundle/standalone/node_modules/kxta-core/dist/storage/apply.js +38 -16
  209. package/bundle/standalone/node_modules/kxta-core/dist/storage/apply.js.map +1 -1
  210. package/bundle/standalone/node_modules/kxta-core/dist/storage/conflicts.d.ts.map +1 -1
  211. package/bundle/standalone/node_modules/kxta-core/dist/storage/conflicts.js +105 -49
  212. package/bundle/standalone/node_modules/kxta-core/dist/storage/conflicts.js.map +1 -1
  213. package/bundle/standalone/node_modules/kxta-core/dist/storage/journal-merge.d.ts.map +1 -1
  214. package/bundle/standalone/node_modules/kxta-core/dist/storage/journal-merge.js +20 -5
  215. package/bundle/standalone/node_modules/kxta-core/dist/storage/journal-merge.js.map +1 -1
  216. package/bundle/standalone/node_modules/kxta-core/dist/transfer/index.d.ts +70 -0
  217. package/bundle/standalone/node_modules/kxta-core/dist/transfer/index.d.ts.map +1 -0
  218. package/bundle/standalone/node_modules/kxta-core/dist/transfer/index.js +197 -0
  219. package/bundle/standalone/node_modules/kxta-core/dist/transfer/index.js.map +1 -0
  220. package/bundle/standalone/node_modules/kxta-core/dist/types.d.ts +2 -0
  221. package/bundle/standalone/node_modules/kxta-core/dist/types.d.ts.map +1 -1
  222. package/bundle/standalone/node_modules/kxta-core/dist/watcher/index.d.ts.map +1 -1
  223. package/bundle/standalone/node_modules/kxta-core/dist/watcher/index.js +27 -4
  224. package/bundle/standalone/node_modules/kxta-core/dist/watcher/index.js.map +1 -1
  225. package/bundle/standalone/node_modules/kxta-core/package.json +1 -1
  226. package/bundle/standalone/node_modules/kxta-publish/package.json +2 -2
  227. package/bundle/standalone/package.json +1 -1
  228. package/dist/index.js +7 -0
  229. package/dist/transfer-4YWEYHIM.js +25 -0
  230. package/package.json +1 -1
  231. /package/bundle/standalone/apps/web/.next/static/{_69cGZl0_6kXnJ03xwWXc → l6iKcydtZjucH1-UGakb2}/_buildManifest.js +0 -0
  232. /package/bundle/standalone/apps/web/.next/static/{_69cGZl0_6kXnJ03xwWXc → l6iKcydtZjucH1-UGakb2}/_ssgManifest.js +0 -0
@@ -10,6 +10,7 @@ import { getDatabase } from "../db/index.js";
10
10
  import { formatGid } from "../identity/gid.js";
11
11
  import { getMachineId } from "../identity/machine.js";
12
12
  import { commitFile, commitDelete } from "../git/index.js";
13
+ import { createRevision } from "../revisions/index.js";
13
14
  import { assertPathInside, escapeLike, withLock, fileLockKey } from "../util/safety.js";
14
15
  import { profileRelPath, repairProfile } from "../profile/index.js";
15
16
  import { sanitizeHtml } from "../reports/sanitize.js";
@@ -23,9 +24,11 @@ import { gidOfRow } from "../storage/gids.js";
23
24
  /**
24
25
  * List all folders in a project (recursively)
25
26
  */
26
- export function listProjectFolders(projectPath) {
27
- const folders = [];
27
+ export function listProjectFolders(projectPath, opts) {
28
+ const folders = new Set();
28
29
  function scan(dir, currentRel) {
30
+ if (!existsSync(dir))
31
+ return;
29
32
  const entries = readdirSync(dir);
30
33
  for (const entry of entries) {
31
34
  if (entry.startsWith(".") || entry === "node_modules")
@@ -38,7 +41,7 @@ export function listProjectFolders(projectPath) {
38
41
  if (lst.isSymbolicLink())
39
42
  continue;
40
43
  if (lst.isDirectory()) {
41
- folders.push(relPath);
44
+ folders.add(relPath);
42
45
  scan(fullPath, relPath);
43
46
  }
44
47
  }
@@ -53,13 +56,34 @@ export function listProjectFolders(projectPath) {
53
56
  catch (e) {
54
57
  console.error("Failed to scan project folders:", e);
55
58
  }
56
- return folders;
59
+ // Include virtual folders and folder prefixes from SQLite
60
+ try {
61
+ const db = getDatabase();
62
+ const vRows = db.prepare("SELECT path FROM virtual_folders").all();
63
+ for (const r of vRows) {
64
+ folders.add(r.path);
65
+ }
66
+ // Also include folders derived from file paths
67
+ const fileRows = db.prepare("SELECT path FROM files WHERE storage_type = 'local'").all();
68
+ const root = opts?.dataDir ? resolve(opts.dataDir, "knowledge") : resolve(projectPath);
69
+ for (const fr of fileRows) {
70
+ const rel = relative(root, fr.path);
71
+ if (!rel.startsWith("..") && !isAbsolute(rel)) {
72
+ const parts = rel.split(/[/\\]/);
73
+ for (let i = 1; i < parts.length; i++) {
74
+ folders.add(parts.slice(0, i).join("/"));
75
+ }
76
+ }
77
+ }
78
+ }
79
+ catch { }
80
+ return Array.from(folders).sort();
57
81
  }
58
82
  /**
59
83
  * List all folders in a project that contain at least one .md or .mmd file.
60
84
  * Returns only non-empty folders (useful for publish UI).
61
85
  */
62
- export function listProjectFoldersWithFiles(projectPath) {
86
+ export function listProjectFoldersWithFiles(projectPath, opts) {
63
87
  const folderFileCount = new Map();
64
88
  function scan(dir, currentRel) {
65
89
  const entries = readdirSync(dir);
@@ -97,6 +121,25 @@ export function listProjectFoldersWithFiles(projectPath) {
97
121
  catch (e) {
98
122
  console.error("Failed to scan project folders with files:", e);
99
123
  }
124
+ // Include non-empty folders from SQLite for inline/local files
125
+ try {
126
+ const db = getDatabase();
127
+ const fileRows = db.prepare("SELECT path FROM files WHERE storage_type = 'local'").all();
128
+ const root = opts?.dataDir ? resolve(opts.dataDir, "knowledge") : resolve(projectPath);
129
+ for (const fr of fileRows) {
130
+ if (isIndexedFile(fr.path)) {
131
+ const rel = relative(root, fr.path);
132
+ if (!rel.startsWith("..") && !isAbsolute(rel)) {
133
+ const parts = rel.split(/[/\\]/);
134
+ for (let i = 0; i < parts.length - 1; i++) {
135
+ const ancestor = parts.slice(0, i + 1).join("/");
136
+ folderFileCount.set(ancestor, (folderFileCount.get(ancestor) ?? 0) + 1);
137
+ }
138
+ }
139
+ }
140
+ }
141
+ }
142
+ catch { }
100
143
  // Return only folders with at least one .md/.mmd file
101
144
  const result = [];
102
145
  for (const [folder, count] of folderFileCount.entries()) {
@@ -201,12 +244,11 @@ export async function createFile(opts) {
201
244
  // UPSERT, and the FTS index can land with the watcher's interpretation
202
245
  // of the file (no tags, default title) instead of the caller's.
203
246
  return withLock(fileLockKey(filePath), async () => {
204
- mkdirSync(dirname(filePath), { recursive: true });
205
247
  // Stash pre-existing content (if any) so we can fully restore on a
206
248
  // DB-txn failure — otherwise writeFileSync below would leave the
207
249
  // caller's content sitting under a row that points elsewhere.
208
250
  let preExistingContent = null;
209
- if (existsSync(filePath)) {
251
+ if (storageType === "reference" && existsSync(filePath)) {
210
252
  try {
211
253
  preExistingContent = readFileSync(filePath);
212
254
  }
@@ -224,13 +266,16 @@ export async function createFile(opts) {
224
266
  }
225
267
  if (format === "html" && !skipHtmlSanitize)
226
268
  content = await sanitizeHtml(content);
227
- writeFileSync(filePath, content, "utf8");
269
+ if (storageType === "reference") {
270
+ mkdirSync(dirname(filePath), { recursive: true });
271
+ writeFileSync(filePath, content, "utf8");
272
+ }
228
273
  const contentHash = computeHash(content);
229
274
  const contentClass = computeContentClass({ storageType, path: filePath, dataDir });
230
275
  // ON CONFLICT(path) absorbs the watcher's stub row if chokidar's `add` won the race.
231
276
  const upsertStmt = db.prepare(`
232
- INSERT INTO files (path, title, project_id, storage_type, content_class, source_path, content_hash)
233
- VALUES (?, ?, ?, ?, ?, ?, ?)
277
+ INSERT INTO files (path, title, project_id, storage_type, content_class, source_path, content_hash, content)
278
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
234
279
  ON CONFLICT(path) DO UPDATE SET
235
280
  title = excluded.title,
236
281
  project_id = excluded.project_id,
@@ -238,6 +283,7 @@ export async function createFile(opts) {
238
283
  content_class = excluded.content_class,
239
284
  source_path = excluded.source_path,
240
285
  content_hash = excluded.content_hash,
286
+ content = excluded.content,
241
287
  updated_at = datetime('now')
242
288
  `);
243
289
  const getIdByPathStmt = db.prepare("SELECT id FROM files WHERE path = ?");
@@ -251,12 +297,12 @@ export async function createFile(opts) {
251
297
  const setGidStmt = db.prepare("UPDATE files SET gid = ? WHERE id = ?");
252
298
  // Snapshot for rollback — upsert may overwrite an existing row.
253
299
  const priorRow = db
254
- .prepare("SELECT id, title, project_id, storage_type, content_class, source_path, content_hash, updated_at FROM files WHERE path = ?")
300
+ .prepare("SELECT id, title, project_id, storage_type, content_class, source_path, content_hash, content, updated_at FROM files WHERE path = ?")
255
301
  .get(filePath);
256
302
  let fileId;
257
303
  try {
258
304
  fileId = db.transaction(() => {
259
- upsertStmt.run(filePath, title, projectId || null, storageType, contentClass, sourcePath || null, contentHash);
305
+ upsertStmt.run(filePath, title, projectId || null, storageType, contentClass, sourcePath || null, contentHash, content);
260
306
  const row = getIdByPathStmt.get(filePath);
261
307
  if (!row)
262
308
  throw new Error(`createFile: row missing after upsert for ${filePath}`);
@@ -266,6 +312,14 @@ export async function createFile(opts) {
266
312
  // corrects a watcher stub row that this upsert just absorbed.
267
313
  const gid = formatGid(id, getMachineId());
268
314
  setGidStmt.run(gid, id);
315
+ // Snapshot revision for local files
316
+ if (storageType === "local") {
317
+ createRevision(db, {
318
+ fileId: id,
319
+ content,
320
+ message: `Create context file: ${title}`,
321
+ });
322
+ }
269
323
  if (tags.length > 0) {
270
324
  for (const tagName of tags) {
271
325
  insertTagStmt.run(tagName);
@@ -304,24 +358,26 @@ export async function createFile(opts) {
304
358
  })();
305
359
  }
306
360
  catch (dbError) {
307
- if (preExistingContent !== null) {
308
- try {
309
- writeFileSync(filePath, preExistingContent);
310
- }
311
- catch (e) {
312
- console.error("createFile: failed to restore pre-existing content after DB error:", e);
361
+ if (storageType === "reference") {
362
+ if (preExistingContent !== null) {
363
+ try {
364
+ writeFileSync(filePath, preExistingContent);
365
+ }
366
+ catch (e) {
367
+ console.error("createFile: failed to restore pre-existing content after DB error:", e);
368
+ }
313
369
  }
314
- }
315
- else {
316
- try {
317
- unlinkSync(filePath);
370
+ else {
371
+ try {
372
+ unlinkSync(filePath);
373
+ }
374
+ catch { }
318
375
  }
319
- catch { }
320
376
  }
321
377
  // Roll DB back to priorRow (if any) or delete the freshly-inserted row.
322
378
  try {
323
379
  if (priorRow) {
324
- db.prepare("UPDATE files SET title=?, project_id=?, storage_type=?, content_class=?, source_path=?, content_hash=?, updated_at=? WHERE id=?").run(priorRow.title, priorRow.project_id, priorRow.storage_type, priorRow.content_class, priorRow.source_path, priorRow.content_hash, priorRow.updated_at, priorRow.id);
380
+ db.prepare("UPDATE files SET title=?, project_id=?, storage_type=?, content_class=?, source_path=?, content_hash=?, content=?, updated_at=? WHERE id=?").run(priorRow.title, priorRow.project_id, priorRow.storage_type, priorRow.content_class, priorRow.source_path, priorRow.content_hash, priorRow.content ?? null, priorRow.updated_at, priorRow.id);
325
381
  }
326
382
  else {
327
383
  db.prepare("DELETE FROM files WHERE path = ?").run(filePath);
@@ -335,18 +391,20 @@ export async function createFile(opts) {
335
391
  const fileRecord = db.prepare("SELECT * FROM files WHERE id = ?").get(fileId);
336
392
  // Reference files version against their project's own git, not the data dir.
337
393
  let gitWarning;
338
- try {
339
- let repoDir = dataDir;
340
- if (storageType === "reference" && projectId) {
341
- const project = db.prepare("SELECT path FROM projects WHERE id = ?").get(projectId);
342
- if (project?.path)
343
- repoDir = project.path;
394
+ if (storageType === "reference") {
395
+ try {
396
+ let repoDir = dataDir;
397
+ if (projectId) {
398
+ const project = db.prepare("SELECT path FROM projects WHERE id = ?").get(projectId);
399
+ if (project?.path)
400
+ repoDir = project.path;
401
+ }
402
+ await commitFile(repoDir, filePath, `Create context file: ${title}`);
403
+ }
404
+ catch (error) {
405
+ gitWarning = error instanceof Error ? error.message : String(error);
406
+ console.warn("Git auto-commit failed during creation:", error);
344
407
  }
345
- await commitFile(repoDir, filePath, `Create context file: ${title}`);
346
- }
347
- catch (error) {
348
- gitWarning = error instanceof Error ? error.message : String(error);
349
- console.warn("Git auto-commit failed during creation:", error);
350
408
  }
351
409
  return {
352
410
  ...fileRecord,
@@ -364,7 +422,13 @@ export function readFile(id) {
364
422
  if (!fileRecord) {
365
423
  throw new Error(`File not found: ${id}`);
366
424
  }
367
- const content = readFileSync(fileRecord.path, "utf8");
425
+ let content;
426
+ if (fileRecord.storage_type === "local" && fileRecord.content !== undefined && fileRecord.content !== null) {
427
+ content = fileRecord.content;
428
+ }
429
+ else {
430
+ content = readFileSync(fileRecord.path, "utf8");
431
+ }
368
432
  return {
369
433
  ...fileRecord,
370
434
  content,
@@ -388,7 +452,7 @@ export async function updateFile(id, content, dataDir) {
388
452
  // under a row whose content_hash and FTS index still reflect the old
389
453
  // content, leaving permanent drift.
390
454
  let preExistingContent = null;
391
- if (existsSync(fileRecord.path)) {
455
+ if (fileRecord.storage_type === "reference" && existsSync(fileRecord.path)) {
392
456
  try {
393
457
  preExistingContent = readFileSync(fileRecord.path);
394
458
  }
@@ -398,12 +462,14 @@ export async function updateFile(id, content, dataDir) {
398
462
  }
399
463
  if (fileRecord.path.endsWith(".html"))
400
464
  content = await sanitizeHtml(content);
401
- writeFileSync(fileRecord.path, content, "utf8");
465
+ if (fileRecord.storage_type === "reference") {
466
+ writeFileSync(fileRecord.path, content, "utf8");
467
+ }
402
468
  const contentHash = computeHash(content);
403
469
  // Atomic so a partial failure can't leave the FTS index pointing at stale content.
404
470
  const updateStmt = db.prepare(`
405
471
  UPDATE files
406
- SET content_hash = ?, updated_at = datetime('now')
472
+ SET content = ?, content_hash = ?, updated_at = datetime('now')
407
473
  WHERE id = ?
408
474
  `);
409
475
  const deleteFtsStmt = db.prepare("DELETE FROM fts_index WHERE rowid = ?");
@@ -413,9 +479,17 @@ export async function updateFile(id, content, dataDir) {
413
479
  const gid = fileRecord.gid ?? formatGid(fileRecord.id, getMachineId());
414
480
  try {
415
481
  db.transaction(() => {
416
- updateStmt.run(contentHash, id);
482
+ updateStmt.run(content, contentHash, id);
417
483
  deleteFtsStmt.run(id);
418
484
  insertFtsStmt.run(id, fileRecord.title, content);
485
+ // Snapshot revision for local files
486
+ if (fileRecord.storage_type === "local") {
487
+ createRevision(db, {
488
+ fileId: id,
489
+ content,
490
+ message: `Update context file: ${fileRecord.title}`,
491
+ });
492
+ }
419
493
  // Enqueue the outbound op atomically with the write (spec 1.3); no-op
420
494
  // while applying a remote op (echo suppression, spec 1.4).
421
495
  enqueueFileOp({
@@ -435,7 +509,7 @@ export async function updateFile(id, content, dataDir) {
435
509
  })();
436
510
  }
437
511
  catch (dbError) {
438
- if (preExistingContent !== null) {
512
+ if (fileRecord.storage_type === "reference" && preExistingContent !== null) {
439
513
  try {
440
514
  writeFileSync(fileRecord.path, preExistingContent);
441
515
  }
@@ -446,18 +520,20 @@ export async function updateFile(id, content, dataDir) {
446
520
  throw dbError;
447
521
  }
448
522
  let gitWarning;
449
- try {
450
- let repoDir = dataDir;
451
- if (fileRecord.storage_type === "reference" && fileRecord.project_id) {
452
- const project = db.prepare("SELECT path FROM projects WHERE id = ?").get(fileRecord.project_id);
453
- if (project?.path)
454
- repoDir = project.path;
523
+ if (fileRecord.storage_type === "reference") {
524
+ try {
525
+ let repoDir = dataDir;
526
+ if (fileRecord.project_id) {
527
+ const project = db.prepare("SELECT path FROM projects WHERE id = ?").get(fileRecord.project_id);
528
+ if (project?.path)
529
+ repoDir = project.path;
530
+ }
531
+ await commitFile(repoDir, fileRecord.path, `Update context file: ${fileRecord.title}`);
532
+ }
533
+ catch (error) {
534
+ gitWarning = error instanceof Error ? error.message : String(error);
535
+ console.warn("Git auto-commit failed during update:", error);
455
536
  }
456
- await commitFile(repoDir, fileRecord.path, `Update context file: ${fileRecord.title}`);
457
- }
458
- catch (error) {
459
- gitWarning = error instanceof Error ? error.message : String(error);
460
- console.warn("Git auto-commit failed during update:", error);
461
537
  }
462
538
  const updatedRecord = db.prepare("SELECT * FROM files WHERE id = ?").get(id);
463
539
  return {
@@ -479,19 +555,18 @@ export async function updateFile(id, content, dataDir) {
479
555
  */
480
556
  export async function deleteFile(id, dataDir) {
481
557
  const db = getDatabase();
482
- const file = db.prepare("SELECT path, project_id, gid FROM files WHERE id = ?").get(id);
558
+ const file = db.prepare("SELECT path, project_id, storage_type, gid FROM files WHERE id = ?").get(id);
483
559
  if (!file) {
484
560
  throw new Error(`File not found: ${id}`);
485
561
  }
486
562
  let unlinked = false;
487
- let inKnowledge = false;
488
563
  let filePathResolved = file.path;
489
- if (dataDir) {
564
+ // Only reference files on disk need explicit unlinking/commitDelete if applicable
565
+ if (dataDir && file.storage_type === "reference") {
490
566
  const knowledgeRoot = resolve(dataDir, "knowledge");
491
567
  filePathResolved = isAbsolute(file.path) ? file.path : resolve(dataDir, file.path);
492
- inKnowledge =
493
- filePathResolved === knowledgeRoot ||
494
- filePathResolved.startsWith(knowledgeRoot + sep);
568
+ const inKnowledge = filePathResolved === knowledgeRoot ||
569
+ filePathResolved.startsWith(knowledgeRoot + sep);
495
570
  if (file.project_id === null && inKnowledge) {
496
571
  try {
497
572
  if (existsSync(filePathResolved)) {
@@ -504,7 +579,7 @@ export async function deleteFile(id, dataDir) {
504
579
  }
505
580
  }
506
581
  }
507
- // CASCADE handles file_tags + favorites via the files row deletion.
582
+ // CASCADE handles file_tags + favorites + file_revisions via the files row deletion.
508
583
  const deleteFtsStmt = db.prepare("DELETE FROM fts_index WHERE rowid = ?");
509
584
  const deleteStmt = db.prepare("DELETE FROM files WHERE id = ?");
510
585
  // Read the record's gid (not recomputed) so a REMOTE file's deletion carries
@@ -524,11 +599,8 @@ export async function deleteFile(id, dataDir) {
524
599
  deleteFtsStmt.run(id);
525
600
  deleteStmt.run(id);
526
601
  })();
527
- // Commit the deletion to git so the file doesn't resurrect from HEAD on
528
- // the next pull/restore/stash pop. Only relevant for KB files (we
529
- // actually unlinked them) — for project files we leave the source tree
530
- // untouched. Best-effort; failures don't block the delete.
531
- if (unlinked && dataDir) {
602
+ // Commit the deletion to git if it was on disk
603
+ if (unlinked && dataDir && file.storage_type === "reference") {
532
604
  try {
533
605
  await commitDelete(dataDir, filePathResolved, `Delete context file: ${basename(filePathResolved)}`);
534
606
  }
@@ -542,10 +614,17 @@ export async function deleteFile(id, dataDir) {
542
614
  */
543
615
  export function createFolder(projectPath, folderName, opts) {
544
616
  const fullPath = assertPathInside(projectPath, folderName);
617
+ const db = getDatabase();
545
618
  if (opts?.dataDir) {
546
619
  const knowledgeDir = resolve(opts.dataDir, "knowledge");
547
620
  if (resolve(projectPath) === knowledgeDir) {
548
621
  validateKnowledgeWrite(folderName, "folder");
622
+ // Record virtual folder in SQLite
623
+ try {
624
+ db.prepare("INSERT OR IGNORE INTO virtual_folders (path) VALUES (?)").run(folderName);
625
+ }
626
+ catch { }
627
+ return fullPath;
549
628
  }
550
629
  }
551
630
  mkdirSync(fullPath, { recursive: true });
@@ -556,6 +635,7 @@ export function createFolder(projectPath, folderName, opts) {
556
635
  */
557
636
  export function deleteFolder(projectPath, folderName, opts) {
558
637
  const fullPath = assertPathInside(projectPath, folderName);
638
+ const db = getDatabase();
559
639
  if (opts?.dataDir) {
560
640
  const knowledgeDir = resolve(opts.dataDir, "knowledge");
561
641
  if (resolve(projectPath) === knowledgeDir) {
@@ -563,9 +643,36 @@ export function deleteFolder(projectPath, folderName, opts) {
563
643
  if (segments.length <= 1) {
564
644
  throw new Error(`Cannot delete root knowledge folder '${folderName}'.`);
565
645
  }
646
+ try {
647
+ db.prepare("DELETE FROM virtual_folders WHERE path = ? OR path LIKE ?").run(folderName, `${folderName}/%`);
648
+ // Also cascade delete files inside this virtual folder from SQLite, fts_index, and enqueue outbox ops
649
+ const pattern = `${knowledgeDir}/${folderName}/%`;
650
+ const patternWin = `${knowledgeDir}\\${folderName}\\%`;
651
+ const matchingFiles = db
652
+ .prepare("SELECT id, path, gid FROM files WHERE path LIKE ? OR path LIKE ?")
653
+ .all(pattern, patternWin);
654
+ db.transaction(() => {
655
+ for (const mf of matchingFiles) {
656
+ const gid = mf.gid ?? formatGid(mf.id, getMachineId());
657
+ enqueueFileOp({
658
+ gid,
659
+ kind: "file.delete",
660
+ origin: getMachineId(),
661
+ base_version: 0,
662
+ payload: { path: mf.path, rel_path: toRelPath(mf.path) ?? undefined },
663
+ created_at: Date.now(),
664
+ });
665
+ db.prepare("DELETE FROM fts_index WHERE rowid = ?").run(mf.id);
666
+ db.prepare("DELETE FROM files WHERE id = ?").run(mf.id);
667
+ }
668
+ })();
669
+ }
670
+ catch { }
566
671
  }
567
672
  }
568
- rmSync(fullPath, { recursive: true, force: true });
673
+ if (existsSync(fullPath)) {
674
+ rmSync(fullPath, { recursive: true, force: true });
675
+ }
569
676
  }
570
677
  /**
571
678
  * List files with optional filters
@@ -710,50 +817,45 @@ export function moveFile(id, newPath, dataDir) {
710
817
  }
711
818
  }
712
819
  const oldPath = fileRecord.path;
713
- if (newPath !== oldPath && existsSync(newPath)) {
714
- throw new Error(`moveFile: destination already exists: ${newPath}`);
715
- }
716
- mkdirSync(dirname(newPath), { recursive: true });
717
- try {
718
- renameSync(oldPath, newPath);
719
- }
720
- catch (err) {
721
- if (err?.code === "EXDEV") {
722
- // Cross-device move (e.g. Docker bind mount → tmpfs). renameSync can't
723
- // span devices on POSIX; fall back to copy + unlink, atomic on the
724
- // destination via .tmp + rename trick.
725
- const tmpDest = `${newPath}.${process.pid}.${Date.now()}.tmp`;
726
- try {
727
- const buf = readFileSync(oldPath);
728
- writeFileSync(tmpDest, buf);
729
- renameSync(tmpDest, newPath);
730
- unlinkSync(oldPath);
731
- }
732
- catch (copyErr) {
820
+ if (fileRecord.storage_type === "reference") {
821
+ if (newPath !== oldPath && existsSync(newPath)) {
822
+ throw new Error(`moveFile: destination already exists: ${newPath}`);
823
+ }
824
+ mkdirSync(dirname(newPath), { recursive: true });
825
+ try {
826
+ renameSync(oldPath, newPath);
827
+ }
828
+ catch (err) {
829
+ if (err?.code === "EXDEV") {
830
+ // Cross-device move (e.g. Docker bind mount → tmpfs). renameSync can't
831
+ // span devices on POSIX; fall back to copy + unlink, atomic on the
832
+ // destination via .tmp + rename trick.
833
+ const tmpDest = `${newPath}.${process.pid}.${Date.now()}.tmp`;
733
834
  try {
734
- if (existsSync(tmpDest))
735
- unlinkSync(tmpDest);
835
+ const buf = readFileSync(oldPath);
836
+ writeFileSync(tmpDest, buf);
837
+ renameSync(tmpDest, newPath);
838
+ unlinkSync(oldPath);
736
839
  }
737
- catch { }
738
- try {
739
- if (existsSync(newPath) && !existsSync(oldPath))
740
- renameSync(newPath, oldPath);
840
+ catch (copyErr) {
841
+ try {
842
+ if (existsSync(tmpDest))
843
+ unlinkSync(tmpDest);
844
+ }
845
+ catch { }
846
+ try {
847
+ if (existsSync(newPath) && !existsSync(oldPath))
848
+ renameSync(newPath, oldPath);
849
+ }
850
+ catch { }
851
+ throw copyErr;
741
852
  }
742
- catch { }
743
- throw copyErr;
744
853
  }
745
- }
746
- else {
747
- throw err;
854
+ else {
855
+ throw err;
856
+ }
748
857
  }
749
858
  }
750
- // If the DB UPDATE fails (UNIQUE conflict, etc.) we'd be left with the
751
- // file at newPath but the row pointing at oldPath — in the web app the
752
- // watcher would then unlink the row (losing tags/favorites). Roll the
753
- // disk rename back so the system stays consistent. (Best-effort: if the
754
- // original move went EXDEV the rollback path may also need a copy
755
- // fallback, but in practice rollback is on the same device that just
756
- // hosted the file.)
757
859
  // Only touch content_class when dataDir is known — otherwise preserve the existing value rather than silently wiping it to null.
758
860
  try {
759
861
  // Read the record's gid (not recomputed) so a REMOTE file's move carries
@@ -790,12 +892,14 @@ export function moveFile(id, newPath, dataDir) {
790
892
  })();
791
893
  }
792
894
  catch (e) {
793
- try {
794
- renameSync(newPath, oldPath);
795
- }
796
- catch (rollbackErr) {
797
- throw new Error(`moveFile failed and rollback also failed; disk and DB are out of sync. ` +
798
- `update error: ${e?.message ?? e}; rollback error: ${rollbackErr?.message ?? rollbackErr}`);
895
+ if (fileRecord.storage_type === "reference") {
896
+ try {
897
+ renameSync(newPath, oldPath);
898
+ }
899
+ catch (rollbackErr) {
900
+ throw new Error(`moveFile failed and rollback also failed; disk and DB are out of sync. ` +
901
+ `update error: ${e?.message ?? e}; rollback error: ${rollbackErr?.message ?? rollbackErr}`);
902
+ }
799
903
  }
800
904
  throw e;
801
905
  }