kontexta 4.7.1 → 5.1.0

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 (499) hide show
  1. package/bundle/standalone/CHANGELOG.md +38 -0
  2. package/bundle/standalone/apps/web/.next/BUILD_ID +1 -1
  3. package/bundle/standalone/apps/web/.next/app-build-manifest.json +109 -88
  4. package/bundle/standalone/apps/web/.next/app-path-routes-manifest.json +15 -12
  5. package/bundle/standalone/apps/web/.next/build-manifest.json +2 -2
  6. package/bundle/standalone/apps/web/.next/prerender-manifest.json +13 -13
  7. package/bundle/standalone/apps/web/.next/required-server-files.json +1 -0
  8. package/bundle/standalone/apps/web/.next/routes-manifest.json +16 -0
  9. package/bundle/standalone/apps/web/.next/server/app/_not-found/page.js +1 -1
  10. package/bundle/standalone/apps/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  11. package/bundle/standalone/apps/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  12. package/bundle/standalone/apps/web/.next/server/app/_not-found.html +1 -1
  13. package/bundle/standalone/apps/web/.next/server/app/_not-found.rsc +4 -4
  14. package/bundle/standalone/apps/web/.next/server/app/api/about/route.js.nft.json +1 -1
  15. package/bundle/standalone/apps/web/.next/server/app/api/about/route_client-reference-manifest.js +1 -1
  16. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/hooks/route.js +1 -0
  17. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/hooks/route.js.nft.json +1 -0
  18. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/hooks/route_client-reference-manifest.js +1 -0
  19. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/route.js +1 -0
  20. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/route.js.nft.json +1 -0
  21. package/bundle/standalone/apps/web/.next/server/app/api/agents/[id]/route_client-reference-manifest.js +1 -0
  22. package/bundle/standalone/apps/web/.next/server/app/api/agents/route.js +1 -0
  23. package/bundle/standalone/apps/web/.next/server/app/api/agents/route.js.nft.json +1 -0
  24. package/bundle/standalone/apps/web/.next/server/app/api/agents/route_client-reference-manifest.js +1 -0
  25. package/bundle/standalone/apps/web/.next/server/app/api/auth/login/route.js +1 -1
  26. package/bundle/standalone/apps/web/.next/server/app/api/auth/login/route.js.nft.json +1 -1
  27. package/bundle/standalone/apps/web/.next/server/app/api/auth/login/route_client-reference-manifest.js +1 -1
  28. package/bundle/standalone/apps/web/.next/server/app/api/auth/logout/route.js.nft.json +1 -1
  29. package/bundle/standalone/apps/web/.next/server/app/api/auth/logout/route_client-reference-manifest.js +1 -1
  30. package/bundle/standalone/apps/web/.next/server/app/api/auth/setup/route.js +1 -1
  31. package/bundle/standalone/apps/web/.next/server/app/api/auth/setup/route.js.nft.json +1 -1
  32. package/bundle/standalone/apps/web/.next/server/app/api/auth/setup/route_client-reference-manifest.js +1 -1
  33. package/bundle/standalone/apps/web/.next/server/app/api/auth/status/route.js +1 -1
  34. package/bundle/standalone/apps/web/.next/server/app/api/auth/status/route.js.nft.json +1 -1
  35. package/bundle/standalone/apps/web/.next/server/app/api/auth/status/route_client-reference-manifest.js +1 -1
  36. package/bundle/standalone/apps/web/.next/server/app/api/auth/token/route.js +1 -1
  37. package/bundle/standalone/apps/web/.next/server/app/api/auth/token/route.js.nft.json +1 -1
  38. package/bundle/standalone/apps/web/.next/server/app/api/auth/token/route_client-reference-manifest.js +1 -1
  39. package/bundle/standalone/apps/web/.next/server/app/api/calendar/conflicts/route.js +1 -1
  40. package/bundle/standalone/apps/web/.next/server/app/api/calendar/conflicts/route.js.nft.json +1 -1
  41. package/bundle/standalone/apps/web/.next/server/app/api/calendar/conflicts/route_client-reference-manifest.js +1 -1
  42. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/[id]/route.js +1 -1
  43. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/[id]/route.js.nft.json +1 -1
  44. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/[id]/route_client-reference-manifest.js +1 -1
  45. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/route.js +1 -1
  46. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/route.js.nft.json +1 -1
  47. package/bundle/standalone/apps/web/.next/server/app/api/calendar/entities/route_client-reference-manifest.js +1 -1
  48. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/[id]/route.js +1 -1
  49. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/[id]/route.js.nft.json +1 -1
  50. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/[id]/route_client-reference-manifest.js +1 -1
  51. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/route.js +1 -1
  52. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/route.js.nft.json +1 -1
  53. package/bundle/standalone/apps/web/.next/server/app/api/calendar/events/route_client-reference-manifest.js +1 -1
  54. package/bundle/standalone/apps/web/.next/server/app/api/calendar/ics/route.js +1 -1
  55. package/bundle/standalone/apps/web/.next/server/app/api/calendar/ics/route.js.nft.json +1 -1
  56. package/bundle/standalone/apps/web/.next/server/app/api/calendar/ics/route_client-reference-manifest.js +1 -1
  57. package/bundle/standalone/apps/web/.next/server/app/api/calendar/links/route.js +1 -1
  58. package/bundle/standalone/apps/web/.next/server/app/api/calendar/links/route.js.nft.json +1 -1
  59. package/bundle/standalone/apps/web/.next/server/app/api/calendar/links/route_client-reference-manifest.js +1 -1
  60. package/bundle/standalone/apps/web/.next/server/app/api/calendar/settings/route.js +1 -1
  61. package/bundle/standalone/apps/web/.next/server/app/api/calendar/settings/route.js.nft.json +1 -1
  62. package/bundle/standalone/apps/web/.next/server/app/api/calendar/settings/route_client-reference-manifest.js +1 -1
  63. package/bundle/standalone/apps/web/.next/server/app/api/clip/route.js +1 -1
  64. package/bundle/standalone/apps/web/.next/server/app/api/clip/route.js.nft.json +1 -1
  65. package/bundle/standalone/apps/web/.next/server/app/api/clip/route_client-reference-manifest.js +1 -1
  66. package/bundle/standalone/apps/web/.next/server/app/api/docker-config/route.js +1 -1
  67. package/bundle/standalone/apps/web/.next/server/app/api/docker-config/route.js.nft.json +1 -1
  68. package/bundle/standalone/apps/web/.next/server/app/api/docker-config/route_client-reference-manifest.js +1 -1
  69. package/bundle/standalone/apps/web/.next/server/app/api/export/zip/route.js +1 -1
  70. package/bundle/standalone/apps/web/.next/server/app/api/export/zip/route.js.nft.json +1 -1
  71. package/bundle/standalone/apps/web/.next/server/app/api/export/zip/route_client-reference-manifest.js +1 -1
  72. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/backlinks/route.js +1 -1
  73. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/backlinks/route.js.nft.json +1 -1
  74. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/backlinks/route_client-reference-manifest.js +1 -1
  75. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/download/route.js +1 -1
  76. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/download/route.js.nft.json +1 -1
  77. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/download/route_client-reference-manifest.js +1 -1
  78. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-html/route.js +1 -1
  79. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-html/route.js.nft.json +1 -1
  80. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-html/route_client-reference-manifest.js +1 -1
  81. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-pdf/route.js +1 -1
  82. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-pdf/route.js.nft.json +1 -1
  83. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/export-pdf/route_client-reference-manifest.js +1 -1
  84. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/restore/route.js +1 -1
  85. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/restore/route.js.nft.json +1 -1
  86. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/restore/route_client-reference-manifest.js +1 -1
  87. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/route.js +1 -1
  88. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/route.js.nft.json +1 -1
  89. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/history/route_client-reference-manifest.js +1 -1
  90. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/move/route.js +1 -1
  91. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/move/route.js.nft.json +1 -1
  92. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/move/route_client-reference-manifest.js +1 -1
  93. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/route.js +1 -1
  94. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/route.js.nft.json +1 -1
  95. package/bundle/standalone/apps/web/.next/server/app/api/files/[id]/route_client-reference-manifest.js +1 -1
  96. package/bundle/standalone/apps/web/.next/server/app/api/files/route.js +1 -1
  97. package/bundle/standalone/apps/web/.next/server/app/api/files/route.js.nft.json +1 -1
  98. package/bundle/standalone/apps/web/.next/server/app/api/files/route_client-reference-manifest.js +1 -1
  99. package/bundle/standalone/apps/web/.next/server/app/api/files/upload/route.js +1 -1
  100. package/bundle/standalone/apps/web/.next/server/app/api/files/upload/route.js.nft.json +1 -1
  101. package/bundle/standalone/apps/web/.next/server/app/api/files/upload/route_client-reference-manifest.js +1 -1
  102. package/bundle/standalone/apps/web/.next/server/app/api/folders/route.js +1 -1
  103. package/bundle/standalone/apps/web/.next/server/app/api/folders/route.js.nft.json +1 -1
  104. package/bundle/standalone/apps/web/.next/server/app/api/folders/route_client-reference-manifest.js +1 -1
  105. package/bundle/standalone/apps/web/.next/server/app/api/git/remote/route.js +1 -1
  106. package/bundle/standalone/apps/web/.next/server/app/api/git/remote/route.js.nft.json +1 -1
  107. package/bundle/standalone/apps/web/.next/server/app/api/git/remote/route_client-reference-manifest.js +1 -1
  108. package/bundle/standalone/apps/web/.next/server/app/api/git/sync-all/route.js +1 -1
  109. package/bundle/standalone/apps/web/.next/server/app/api/git/sync-all/route.js.nft.json +1 -1
  110. package/bundle/standalone/apps/web/.next/server/app/api/git/sync-all/route_client-reference-manifest.js +1 -1
  111. package/bundle/standalone/apps/web/.next/server/app/api/hands/test-pattern/route.js.nft.json +1 -1
  112. package/bundle/standalone/apps/web/.next/server/app/api/hands/test-pattern/route_client-reference-manifest.js +1 -1
  113. package/bundle/standalone/apps/web/.next/server/app/api/hands/validate/route.js.nft.json +1 -1
  114. package/bundle/standalone/apps/web/.next/server/app/api/hands/validate/route_client-reference-manifest.js +1 -1
  115. package/bundle/standalone/apps/web/.next/server/app/api/health/route.js +1 -1
  116. package/bundle/standalone/apps/web/.next/server/app/api/health/route.js.nft.json +1 -1
  117. package/bundle/standalone/apps/web/.next/server/app/api/health/route_client-reference-manifest.js +1 -1
  118. package/bundle/standalone/apps/web/.next/server/app/api/install-snippets/route.js +2 -2
  119. package/bundle/standalone/apps/web/.next/server/app/api/install-snippets/route.js.nft.json +1 -1
  120. package/bundle/standalone/apps/web/.next/server/app/api/install-snippets/route_client-reference-manifest.js +1 -1
  121. package/bundle/standalone/apps/web/.next/server/app/api/mcp-tools/route.js +1 -1
  122. package/bundle/standalone/apps/web/.next/server/app/api/mcp-tools/route.js.nft.json +1 -1
  123. package/bundle/standalone/apps/web/.next/server/app/api/mcp-tools/route_client-reference-manifest.js +1 -1
  124. package/bundle/standalone/apps/web/.next/server/app/api/profile/route.js.nft.json +1 -1
  125. package/bundle/standalone/apps/web/.next/server/app/api/profile/route_client-reference-manifest.js +1 -1
  126. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/hands-config/route.js +1 -1
  127. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/hands-config/route.js.nft.json +1 -1
  128. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/hands-config/route_client-reference-manifest.js +1 -1
  129. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-config/route.js +1 -1
  130. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-config/route.js.nft.json +1 -1
  131. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-config/route_client-reference-manifest.js +1 -1
  132. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-status/route.js +1 -1
  133. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-status/route.js.nft.json +1 -1
  134. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/journal-status/route_client-reference-manifest.js +1 -1
  135. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/onboard/route.js +1 -1
  136. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/onboard/route.js.nft.json +1 -1
  137. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/onboard/route_client-reference-manifest.js +1 -1
  138. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/refresh/route.js +1 -1
  139. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/refresh/route.js.nft.json +1 -1
  140. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/refresh/route_client-reference-manifest.js +1 -1
  141. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/route.js +1 -1
  142. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/route.js.nft.json +1 -1
  143. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/route_client-reference-manifest.js +1 -1
  144. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/sync/route.js +1 -1
  145. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/sync/route.js.nft.json +1 -1
  146. package/bundle/standalone/apps/web/.next/server/app/api/projects/[id]/sync/route_client-reference-manifest.js +1 -1
  147. package/bundle/standalone/apps/web/.next/server/app/api/projects/onboard/route.js +1 -1
  148. package/bundle/standalone/apps/web/.next/server/app/api/projects/onboard/route.js.nft.json +1 -1
  149. package/bundle/standalone/apps/web/.next/server/app/api/projects/onboard/route_client-reference-manifest.js +1 -1
  150. package/bundle/standalone/apps/web/.next/server/app/api/projects/route.js +1 -1
  151. package/bundle/standalone/apps/web/.next/server/app/api/projects/route.js.nft.json +1 -1
  152. package/bundle/standalone/apps/web/.next/server/app/api/projects/route_client-reference-manifest.js +1 -1
  153. package/bundle/standalone/apps/web/.next/server/app/api/publish/html/route.js.nft.json +1 -1
  154. package/bundle/standalone/apps/web/.next/server/app/api/publish/html/route_client-reference-manifest.js +1 -1
  155. package/bundle/standalone/apps/web/.next/server/app/api/publish/route.js.nft.json +1 -1
  156. package/bundle/standalone/apps/web/.next/server/app/api/publish/route_client-reference-manifest.js +1 -1
  157. package/bundle/standalone/apps/web/.next/server/app/api/refresh/route.js +1 -1
  158. package/bundle/standalone/apps/web/.next/server/app/api/refresh/route.js.nft.json +1 -1
  159. package/bundle/standalone/apps/web/.next/server/app/api/refresh/route_client-reference-manifest.js +1 -1
  160. package/bundle/standalone/apps/web/.next/server/app/api/reindex/route.js +1 -1
  161. package/bundle/standalone/apps/web/.next/server/app/api/reindex/route.js.nft.json +1 -1
  162. package/bundle/standalone/apps/web/.next/server/app/api/reindex/route_client-reference-manifest.js +1 -1
  163. package/bundle/standalone/apps/web/.next/server/app/api/reports/resources/[name]/route.js +1 -1
  164. package/bundle/standalone/apps/web/.next/server/app/api/reports/resources/[name]/route.js.nft.json +1 -1
  165. package/bundle/standalone/apps/web/.next/server/app/api/reports/resources/[name]/route_client-reference-manifest.js +1 -1
  166. package/bundle/standalone/apps/web/.next/server/app/api/search/route.js +1 -1
  167. package/bundle/standalone/apps/web/.next/server/app/api/search/route.js.nft.json +1 -1
  168. package/bundle/standalone/apps/web/.next/server/app/api/search/route_client-reference-manifest.js +1 -1
  169. package/bundle/standalone/apps/web/.next/server/app/api/tags/route.js +1 -1
  170. package/bundle/standalone/apps/web/.next/server/app/api/tags/route.js.nft.json +1 -1
  171. package/bundle/standalone/apps/web/.next/server/app/api/tags/route_client-reference-manifest.js +1 -1
  172. package/bundle/standalone/apps/web/.next/server/app/api/version-check/route.js +1 -1
  173. package/bundle/standalone/apps/web/.next/server/app/api/version-check/route.js.nft.json +1 -1
  174. package/bundle/standalone/apps/web/.next/server/app/api/version-check/route_client-reference-manifest.js +1 -1
  175. package/bundle/standalone/apps/web/.next/server/app/api/welcome/route.js.nft.json +1 -1
  176. package/bundle/standalone/apps/web/.next/server/app/api/welcome/route_client-reference-manifest.js +1 -1
  177. package/bundle/standalone/apps/web/.next/server/app/api/ws-config/route.js.nft.json +1 -1
  178. package/bundle/standalone/apps/web/.next/server/app/api/ws-config/route_client-reference-manifest.js +1 -1
  179. package/bundle/standalone/apps/web/.next/server/app/apple-icon.png/route.js.nft.json +1 -1
  180. package/bundle/standalone/apps/web/.next/server/app/calendar/page.js +1 -1
  181. package/bundle/standalone/apps/web/.next/server/app/calendar/page.js.nft.json +1 -1
  182. package/bundle/standalone/apps/web/.next/server/app/calendar/page_client-reference-manifest.js +1 -1
  183. package/bundle/standalone/apps/web/.next/server/app/favicon.ico/route.js.nft.json +1 -1
  184. package/bundle/standalone/apps/web/.next/server/app/icon.png/route.js.nft.json +1 -1
  185. package/bundle/standalone/apps/web/.next/server/app/login/page.js +2 -2
  186. package/bundle/standalone/apps/web/.next/server/app/login/page.js.nft.json +1 -1
  187. package/bundle/standalone/apps/web/.next/server/app/login/page_client-reference-manifest.js +1 -1
  188. package/bundle/standalone/apps/web/.next/server/app/page.js +4 -4
  189. package/bundle/standalone/apps/web/.next/server/app/page.js.nft.json +1 -1
  190. package/bundle/standalone/apps/web/.next/server/app/page_client-reference-manifest.js +1 -1
  191. package/bundle/standalone/apps/web/.next/server/app/preview/motifs/page.js +1 -1
  192. package/bundle/standalone/apps/web/.next/server/app/preview/motifs/page.js.nft.json +1 -1
  193. package/bundle/standalone/apps/web/.next/server/app/preview/motifs/page_client-reference-manifest.js +1 -1
  194. package/bundle/standalone/apps/web/.next/server/app/preview/motifs.html +2 -2
  195. package/bundle/standalone/apps/web/.next/server/app/preview/motifs.rsc +23 -22
  196. package/bundle/standalone/apps/web/.next/server/app-paths-manifest.json +15 -12
  197. package/bundle/standalone/apps/web/.next/server/chunks/6680.js +1 -1
  198. package/bundle/standalone/apps/web/.next/server/pages/404.html +1 -1
  199. package/bundle/standalone/apps/web/.next/server/pages/500.html +1 -1
  200. package/bundle/standalone/apps/web/.next/server/pages/_app.js.nft.json +1 -1
  201. package/bundle/standalone/apps/web/.next/server/pages/_document.js.nft.json +1 -1
  202. package/bundle/standalone/apps/web/.next/server/pages/_error.js.nft.json +1 -1
  203. package/bundle/standalone/apps/web/.next/server/server-reference-manifest.json +1 -1
  204. package/bundle/standalone/apps/web/.next/static/IxgiSiK05GtQGxU41f-Mx/_buildManifest.js +1 -0
  205. package/bundle/standalone/apps/web/.next/static/chunks/771-863c84c2b052163a.js +1 -0
  206. package/bundle/standalone/apps/web/.next/static/chunks/app/api/about/route-0cc6597bb67aea3b.js +1 -0
  207. package/bundle/standalone/apps/web/.next/static/chunks/app/api/agents/[id]/hooks/route-0cc6597bb67aea3b.js +1 -0
  208. package/bundle/standalone/apps/web/.next/static/chunks/app/api/agents/[id]/route-0cc6597bb67aea3b.js +1 -0
  209. package/bundle/standalone/apps/web/.next/static/chunks/app/api/agents/route-0cc6597bb67aea3b.js +1 -0
  210. package/bundle/standalone/apps/web/.next/static/chunks/app/api/auth/login/route-0cc6597bb67aea3b.js +1 -0
  211. package/bundle/standalone/apps/web/.next/static/chunks/app/api/auth/logout/route-0cc6597bb67aea3b.js +1 -0
  212. package/bundle/standalone/apps/web/.next/static/chunks/app/api/auth/setup/route-0cc6597bb67aea3b.js +1 -0
  213. package/bundle/standalone/apps/web/.next/static/chunks/app/api/auth/status/route-0cc6597bb67aea3b.js +1 -0
  214. package/bundle/standalone/apps/web/.next/static/chunks/app/api/auth/token/route-0cc6597bb67aea3b.js +1 -0
  215. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/conflicts/route-0cc6597bb67aea3b.js +1 -0
  216. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/entities/[id]/route-0cc6597bb67aea3b.js +1 -0
  217. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/entities/route-0cc6597bb67aea3b.js +1 -0
  218. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/events/[id]/route-0cc6597bb67aea3b.js +1 -0
  219. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/events/route-0cc6597bb67aea3b.js +1 -0
  220. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/ics/route-0cc6597bb67aea3b.js +1 -0
  221. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/links/route-0cc6597bb67aea3b.js +1 -0
  222. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/settings/route-0cc6597bb67aea3b.js +1 -0
  223. package/bundle/standalone/apps/web/.next/static/chunks/app/api/clip/route-0cc6597bb67aea3b.js +1 -0
  224. package/bundle/standalone/apps/web/.next/static/chunks/app/api/docker-config/route-0cc6597bb67aea3b.js +1 -0
  225. package/bundle/standalone/apps/web/.next/static/chunks/app/api/export/zip/route-0cc6597bb67aea3b.js +1 -0
  226. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/backlinks/route-0cc6597bb67aea3b.js +1 -0
  227. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/download/route-0cc6597bb67aea3b.js +1 -0
  228. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/export-html/route-0cc6597bb67aea3b.js +1 -0
  229. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/export-pdf/route-0cc6597bb67aea3b.js +1 -0
  230. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/history/restore/route-0cc6597bb67aea3b.js +1 -0
  231. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/history/route-0cc6597bb67aea3b.js +1 -0
  232. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/move/route-0cc6597bb67aea3b.js +1 -0
  233. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/route-0cc6597bb67aea3b.js +1 -0
  234. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/route-0cc6597bb67aea3b.js +1 -0
  235. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/upload/route-0cc6597bb67aea3b.js +1 -0
  236. package/bundle/standalone/apps/web/.next/static/chunks/app/api/folders/route-0cc6597bb67aea3b.js +1 -0
  237. package/bundle/standalone/apps/web/.next/static/chunks/app/api/git/remote/route-0cc6597bb67aea3b.js +1 -0
  238. package/bundle/standalone/apps/web/.next/static/chunks/app/api/git/sync-all/route-0cc6597bb67aea3b.js +1 -0
  239. package/bundle/standalone/apps/web/.next/static/chunks/app/api/hands/test-pattern/route-0cc6597bb67aea3b.js +1 -0
  240. package/bundle/standalone/apps/web/.next/static/chunks/app/api/hands/validate/route-0cc6597bb67aea3b.js +1 -0
  241. package/bundle/standalone/apps/web/.next/static/chunks/app/api/health/route-0cc6597bb67aea3b.js +1 -0
  242. package/bundle/standalone/apps/web/.next/static/chunks/app/api/install-snippets/route-0cc6597bb67aea3b.js +1 -0
  243. package/bundle/standalone/apps/web/.next/static/chunks/app/api/mcp-tools/route-0cc6597bb67aea3b.js +1 -0
  244. package/bundle/standalone/apps/web/.next/static/chunks/app/api/profile/route-0cc6597bb67aea3b.js +1 -0
  245. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/hands-config/route-0cc6597bb67aea3b.js +1 -0
  246. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/journal-config/route-0cc6597bb67aea3b.js +1 -0
  247. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/journal-status/route-0cc6597bb67aea3b.js +1 -0
  248. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/onboard/route-0cc6597bb67aea3b.js +1 -0
  249. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/refresh/route-0cc6597bb67aea3b.js +1 -0
  250. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/route-0cc6597bb67aea3b.js +1 -0
  251. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/sync/route-0cc6597bb67aea3b.js +1 -0
  252. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/onboard/route-0cc6597bb67aea3b.js +1 -0
  253. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/route-0cc6597bb67aea3b.js +1 -0
  254. package/bundle/standalone/apps/web/.next/static/chunks/app/api/publish/html/route-0cc6597bb67aea3b.js +1 -0
  255. package/bundle/standalone/apps/web/.next/static/chunks/app/api/publish/route-0cc6597bb67aea3b.js +1 -0
  256. package/bundle/standalone/apps/web/.next/static/chunks/app/api/refresh/route-0cc6597bb67aea3b.js +1 -0
  257. package/bundle/standalone/apps/web/.next/static/chunks/app/api/reindex/route-0cc6597bb67aea3b.js +1 -0
  258. package/bundle/standalone/apps/web/.next/static/chunks/app/api/reports/resources/[name]/route-0cc6597bb67aea3b.js +1 -0
  259. package/bundle/standalone/apps/web/.next/static/chunks/app/api/search/route-0cc6597bb67aea3b.js +1 -0
  260. package/bundle/standalone/apps/web/.next/static/chunks/app/api/tags/route-0cc6597bb67aea3b.js +1 -0
  261. package/bundle/standalone/apps/web/.next/static/chunks/app/api/version-check/route-0cc6597bb67aea3b.js +1 -0
  262. package/bundle/standalone/apps/web/.next/static/chunks/app/api/welcome/route-0cc6597bb67aea3b.js +1 -0
  263. package/bundle/standalone/apps/web/.next/static/chunks/app/api/ws-config/route-0cc6597bb67aea3b.js +1 -0
  264. package/bundle/standalone/apps/web/.next/static/chunks/app/{layout-3050c58d9809581a.js → layout-da10917c290d5da7.js} +1 -1
  265. package/bundle/standalone/apps/web/.next/static/chunks/app/page-4c19cddc721d832e.js +1 -0
  266. package/bundle/standalone/apps/web/.next/static/chunks/app/preview/motifs/page-0cc6597bb67aea3b.js +1 -0
  267. package/bundle/standalone/apps/web/.next/static/css/198c34172598da00.css +3 -0
  268. package/bundle/standalone/apps/web/package.json +5 -5
  269. package/bundle/standalone/apps/web/server.js +1 -1
  270. package/bundle/standalone/apps/web/src/lib/mcp-tools.json +238 -543
  271. package/bundle/standalone/node_modules/kontexta-mcp/dist/agent-rules/rules-block.md +24 -35
  272. package/bundle/standalone/node_modules/kontexta-mcp/dist/calendar-tools.js +1 -1
  273. package/bundle/standalone/node_modules/kontexta-mcp/dist/hands/formatter.js +1 -1
  274. package/bundle/standalone/node_modules/kontexta-mcp/dist/hands/formatter.js.map +1 -1
  275. package/bundle/standalone/node_modules/kontexta-mcp/dist/hands/schema-doc.js +1 -1
  276. package/bundle/standalone/node_modules/kontexta-mcp/dist/hooks/emit.mjs +397 -0
  277. package/bundle/standalone/node_modules/kontexta-mcp/dist/hooks-block.d.ts +13 -0
  278. package/bundle/standalone/node_modules/kontexta-mcp/dist/hooks-block.d.ts.map +1 -0
  279. package/bundle/standalone/node_modules/kontexta-mcp/dist/hooks-block.js +27 -0
  280. package/bundle/standalone/node_modules/kontexta-mcp/dist/hooks-block.js.map +1 -0
  281. package/bundle/standalone/node_modules/kontexta-mcp/dist/hooks-cli.d.ts +3 -0
  282. package/bundle/standalone/node_modules/kontexta-mcp/dist/hooks-cli.d.ts.map +1 -0
  283. package/bundle/standalone/node_modules/kontexta-mcp/dist/hooks-cli.js +141 -0
  284. package/bundle/standalone/node_modules/kontexta-mcp/dist/hooks-cli.js.map +1 -0
  285. package/bundle/standalone/node_modules/kontexta-mcp/dist/index.js +479 -475
  286. package/bundle/standalone/node_modules/kontexta-mcp/dist/index.js.map +1 -1
  287. package/bundle/standalone/node_modules/kontexta-mcp/dist/journal-capture.d.ts.map +1 -1
  288. package/bundle/standalone/node_modules/kontexta-mcp/dist/journal-capture.js +55 -9
  289. package/bundle/standalone/node_modules/kontexta-mcp/dist/journal-capture.js.map +1 -1
  290. package/bundle/standalone/node_modules/kontexta-mcp/dist/journal-tools.d.ts.map +1 -1
  291. package/bundle/standalone/node_modules/kontexta-mcp/dist/journal-tools.js +1 -27
  292. package/bundle/standalone/node_modules/kontexta-mcp/dist/journal-tools.js.map +1 -1
  293. package/bundle/standalone/node_modules/kontexta-mcp/dist/migrations/010-agents.sql +14 -0
  294. package/bundle/standalone/node_modules/kontexta-mcp/package.json +2 -2
  295. package/bundle/standalone/node_modules/kxta-core/dist/agent-rules/index.js +1 -1
  296. package/bundle/standalone/node_modules/kxta-core/dist/agent-rules/index.js.map +1 -1
  297. package/bundle/standalone/node_modules/kxta-core/dist/agent-rules/rules-block.md +24 -35
  298. package/bundle/standalone/node_modules/kxta-core/dist/db/index.d.ts +1 -0
  299. package/bundle/standalone/node_modules/kxta-core/dist/db/index.d.ts.map +1 -1
  300. package/bundle/standalone/node_modules/kxta-core/dist/db/index.js +19 -4
  301. package/bundle/standalone/node_modules/kxta-core/dist/db/index.js.map +1 -1
  302. package/bundle/standalone/node_modules/kxta-core/dist/db/migrations/010-agents.sql +14 -0
  303. package/bundle/standalone/node_modules/kxta-core/dist/hooks/agents.d.ts +86 -0
  304. package/bundle/standalone/node_modules/kxta-core/dist/hooks/agents.d.ts.map +1 -0
  305. package/bundle/standalone/node_modules/kxta-core/dist/hooks/agents.js +24 -0
  306. package/bundle/standalone/node_modules/kxta-core/dist/hooks/agents.js.map +1 -0
  307. package/bundle/standalone/node_modules/kxta-core/dist/hooks/alerts.d.ts +25 -0
  308. package/bundle/standalone/node_modules/kxta-core/dist/hooks/alerts.d.ts.map +1 -0
  309. package/bundle/standalone/node_modules/kxta-core/dist/hooks/alerts.js +44 -0
  310. package/bundle/standalone/node_modules/kxta-core/dist/hooks/alerts.js.map +1 -0
  311. package/bundle/standalone/node_modules/kxta-core/dist/hooks/emit.mjs +397 -0
  312. package/bundle/standalone/node_modules/kxta-core/dist/hooks/index.d.ts +14 -0
  313. package/bundle/standalone/node_modules/kxta-core/dist/hooks/index.d.ts.map +1 -0
  314. package/bundle/standalone/node_modules/kxta-core/dist/hooks/index.js +8 -0
  315. package/bundle/standalone/node_modules/kxta-core/dist/hooks/index.js.map +1 -0
  316. package/bundle/standalone/node_modules/kxta-core/dist/hooks/install-mode.d.ts +3 -0
  317. package/bundle/standalone/node_modules/kxta-core/dist/hooks/install-mode.d.ts.map +1 -0
  318. package/bundle/standalone/node_modules/kxta-core/dist/hooks/install-mode.js +15 -0
  319. package/bundle/standalone/node_modules/kxta-core/dist/hooks/install-mode.js.map +1 -0
  320. package/bundle/standalone/node_modules/kxta-core/dist/hooks/install.d.ts +30 -0
  321. package/bundle/standalone/node_modules/kxta-core/dist/hooks/install.d.ts.map +1 -0
  322. package/bundle/standalone/node_modules/kxta-core/dist/hooks/install.js +92 -0
  323. package/bundle/standalone/node_modules/kxta-core/dist/hooks/install.js.map +1 -0
  324. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/claude-code.d.ts +2 -0
  325. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/claude-code.d.ts.map +1 -0
  326. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/claude-code.js +13 -0
  327. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/claude-code.js.map +1 -0
  328. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/cline.d.ts +3 -0
  329. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/cline.d.ts.map +1 -0
  330. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/cline.js +51 -0
  331. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/cline.js.map +1 -0
  332. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/codex.d.ts +2 -0
  333. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/codex.d.ts.map +1 -0
  334. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/codex.js +16 -0
  335. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/codex.js.map +1 -0
  336. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/copilot.d.ts +3 -0
  337. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/copilot.d.ts.map +1 -0
  338. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/copilot.js +41 -0
  339. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/copilot.js.map +1 -0
  340. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/flat.d.ts +13 -0
  341. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/flat.d.ts.map +1 -0
  342. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/flat.js +76 -0
  343. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/flat.js.map +1 -0
  344. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/gemini.d.ts +2 -0
  345. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/gemini.d.ts.map +1 -0
  346. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/gemini.js +12 -0
  347. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/gemini.js.map +1 -0
  348. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/grouped.d.ts +16 -0
  349. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/grouped.d.ts.map +1 -0
  350. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/grouped.js +75 -0
  351. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/grouped.js.map +1 -0
  352. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/index.d.ts +5 -0
  353. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/index.d.ts.map +1 -0
  354. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/index.js +19 -0
  355. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/index.js.map +1 -0
  356. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/json-config.d.ts +13 -0
  357. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/json-config.d.ts.map +1 -0
  358. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/json-config.js +80 -0
  359. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/json-config.js.map +1 -0
  360. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/opencode.d.ts +3 -0
  361. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/opencode.d.ts.map +1 -0
  362. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/opencode.js +76 -0
  363. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/opencode.js.map +1 -0
  364. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/types.d.ts +29 -0
  365. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/types.d.ts.map +1 -0
  366. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/types.js +2 -0
  367. package/bundle/standalone/node_modules/kxta-core/dist/hooks/installers/types.js.map +1 -0
  368. package/bundle/standalone/node_modules/kxta-core/dist/hooks/registry.d.ts +20 -0
  369. package/bundle/standalone/node_modules/kxta-core/dist/hooks/registry.d.ts.map +1 -0
  370. package/bundle/standalone/node_modules/kxta-core/dist/hooks/registry.js +58 -0
  371. package/bundle/standalone/node_modules/kxta-core/dist/hooks/registry.js.map +1 -0
  372. package/bundle/standalone/node_modules/kxta-core/dist/hooks/stage.d.ts +18 -0
  373. package/bundle/standalone/node_modules/kxta-core/dist/hooks/stage.d.ts.map +1 -0
  374. package/bundle/standalone/node_modules/kxta-core/dist/hooks/stage.js +115 -0
  375. package/bundle/standalone/node_modules/kxta-core/dist/hooks/stage.js.map +1 -0
  376. package/bundle/standalone/node_modules/kxta-core/dist/index.d.ts +2 -1
  377. package/bundle/standalone/node_modules/kxta-core/dist/index.d.ts.map +1 -1
  378. package/bundle/standalone/node_modules/kxta-core/dist/index.js +2 -1
  379. package/bundle/standalone/node_modules/kxta-core/dist/index.js.map +1 -1
  380. package/bundle/standalone/node_modules/kxta-core/dist/journal/distill.d.ts +5 -0
  381. package/bundle/standalone/node_modules/kxta-core/dist/journal/distill.d.ts.map +1 -1
  382. package/bundle/standalone/node_modules/kxta-core/dist/journal/distill.js +136 -52
  383. package/bundle/standalone/node_modules/kxta-core/dist/journal/distill.js.map +1 -1
  384. package/bundle/standalone/node_modules/kxta-core/dist/journal/git-watcher.js +2 -2
  385. package/bundle/standalone/node_modules/kxta-core/dist/journal/git-watcher.js.map +1 -1
  386. package/bundle/standalone/node_modules/kxta-core/dist/journal/high-water.d.ts +4 -0
  387. package/bundle/standalone/node_modules/kxta-core/dist/journal/high-water.d.ts.map +1 -1
  388. package/bundle/standalone/node_modules/kxta-core/dist/journal/high-water.js.map +1 -1
  389. package/bundle/standalone/node_modules/kxta-core/dist/journal/patterns/exploration.d.ts.map +1 -1
  390. package/bundle/standalone/node_modules/kxta-core/dist/journal/patterns/exploration.js +3 -14
  391. package/bundle/standalone/node_modules/kxta-core/dist/journal/patterns/exploration.js.map +1 -1
  392. package/bundle/standalone/node_modules/kxta-core/dist/journal/patterns/read-only-investigation.d.ts.map +1 -1
  393. package/bundle/standalone/node_modules/kxta-core/dist/journal/patterns/read-only-investigation.js +2 -13
  394. package/bundle/standalone/node_modules/kxta-core/dist/journal/patterns/read-only-investigation.js.map +1 -1
  395. package/bundle/standalone/node_modules/kxta-core/dist/journal/patterns/tool-classes.d.ts +3 -0
  396. package/bundle/standalone/node_modules/kxta-core/dist/journal/patterns/tool-classes.d.ts.map +1 -0
  397. package/bundle/standalone/node_modules/kxta-core/dist/journal/patterns/tool-classes.js +64 -0
  398. package/bundle/standalone/node_modules/kxta-core/dist/journal/patterns/tool-classes.js.map +1 -0
  399. package/bundle/standalone/node_modules/kxta-core/dist/journal/renderer.d.ts +1 -0
  400. package/bundle/standalone/node_modules/kxta-core/dist/journal/renderer.d.ts.map +1 -1
  401. package/bundle/standalone/node_modules/kxta-core/dist/journal/renderer.js +69 -2
  402. package/bundle/standalone/node_modules/kxta-core/dist/journal/renderer.js.map +1 -1
  403. package/bundle/standalone/node_modules/kxta-core/dist/journal/repository.d.ts +4 -0
  404. package/bundle/standalone/node_modules/kxta-core/dist/journal/repository.d.ts.map +1 -1
  405. package/bundle/standalone/node_modules/kxta-core/dist/journal/repository.js +14 -0
  406. package/bundle/standalone/node_modules/kxta-core/dist/journal/repository.js.map +1 -1
  407. package/bundle/standalone/node_modules/kxta-core/dist/journal/strict-mode.d.ts.map +1 -1
  408. package/bundle/standalone/node_modules/kxta-core/dist/journal/strict-mode.js +2 -17
  409. package/bundle/standalone/node_modules/kxta-core/dist/journal/strict-mode.js.map +1 -1
  410. package/bundle/standalone/node_modules/kxta-core/dist/journal/topic-detector.d.ts +14 -1
  411. package/bundle/standalone/node_modules/kxta-core/dist/journal/topic-detector.d.ts.map +1 -1
  412. package/bundle/standalone/node_modules/kxta-core/dist/journal/topic-detector.js +107 -20
  413. package/bundle/standalone/node_modules/kxta-core/dist/journal/topic-detector.js.map +1 -1
  414. package/bundle/standalone/node_modules/kxta-core/dist/journal/types.d.ts +15 -2
  415. package/bundle/standalone/node_modules/kxta-core/dist/journal/types.d.ts.map +1 -1
  416. package/bundle/standalone/node_modules/kxta-core/dist/metadata/index.d.ts.map +1 -1
  417. package/bundle/standalone/node_modules/kxta-core/dist/metadata/index.js +9 -0
  418. package/bundle/standalone/node_modules/kxta-core/dist/metadata/index.js.map +1 -1
  419. package/bundle/standalone/node_modules/kxta-core/dist/profile/index.d.ts.map +1 -1
  420. package/bundle/standalone/node_modules/kxta-core/dist/profile/index.js +14 -3
  421. package/bundle/standalone/node_modules/kxta-core/dist/profile/index.js.map +1 -1
  422. package/bundle/standalone/node_modules/kxta-core/dist/reports/sanitize.d.ts +1 -0
  423. package/bundle/standalone/node_modules/kxta-core/dist/reports/sanitize.d.ts.map +1 -1
  424. package/bundle/standalone/node_modules/kxta-core/dist/reports/sanitize.js +23 -3
  425. package/bundle/standalone/node_modules/kxta-core/dist/reports/sanitize.js.map +1 -1
  426. package/bundle/standalone/node_modules/kxta-core/dist/util/paths.d.ts.map +1 -1
  427. package/bundle/standalone/node_modules/kxta-core/dist/util/paths.js +16 -0
  428. package/bundle/standalone/node_modules/kxta-core/dist/util/paths.js.map +1 -1
  429. package/bundle/standalone/node_modules/kxta-core/package.json +2 -2
  430. package/bundle/standalone/node_modules/kxta-publish/package.json +3 -3
  431. package/bundle/standalone/package.json +2 -2
  432. package/dist/{mcp-DGMGR3MZ.js → chunk-C4XU73GP.js} +2 -0
  433. package/dist/{doctor-NTVE43EI.js → doctor-HQBEQUUQ.js} +10 -1
  434. package/dist/hooks-6RQ5CCTW.js +22 -0
  435. package/dist/index.js +10 -4
  436. package/dist/mcp-VGISMLKH.js +9 -0
  437. package/dist/{start-66WKQRN5.js → start-RJVUJT4B.js} +9 -0
  438. package/package.json +2 -2
  439. package/bundle/standalone/apps/web/.next/static/DWDlM7S8dTnMlrhKW9K_X/_buildManifest.js +0 -1
  440. package/bundle/standalone/apps/web/.next/static/chunks/1480-3e4f4a95f11429a9.js +0 -1
  441. package/bundle/standalone/apps/web/.next/static/chunks/app/api/about/route-f5e054069fb68dd7.js +0 -1
  442. package/bundle/standalone/apps/web/.next/static/chunks/app/api/auth/login/route-f5e054069fb68dd7.js +0 -1
  443. package/bundle/standalone/apps/web/.next/static/chunks/app/api/auth/logout/route-f5e054069fb68dd7.js +0 -1
  444. package/bundle/standalone/apps/web/.next/static/chunks/app/api/auth/setup/route-f5e054069fb68dd7.js +0 -1
  445. package/bundle/standalone/apps/web/.next/static/chunks/app/api/auth/status/route-f5e054069fb68dd7.js +0 -1
  446. package/bundle/standalone/apps/web/.next/static/chunks/app/api/auth/token/route-f5e054069fb68dd7.js +0 -1
  447. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/conflicts/route-f5e054069fb68dd7.js +0 -1
  448. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/entities/[id]/route-f5e054069fb68dd7.js +0 -1
  449. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/entities/route-f5e054069fb68dd7.js +0 -1
  450. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/events/[id]/route-f5e054069fb68dd7.js +0 -1
  451. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/events/route-f5e054069fb68dd7.js +0 -1
  452. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/ics/route-f5e054069fb68dd7.js +0 -1
  453. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/links/route-f5e054069fb68dd7.js +0 -1
  454. package/bundle/standalone/apps/web/.next/static/chunks/app/api/calendar/settings/route-f5e054069fb68dd7.js +0 -1
  455. package/bundle/standalone/apps/web/.next/static/chunks/app/api/clip/route-f5e054069fb68dd7.js +0 -1
  456. package/bundle/standalone/apps/web/.next/static/chunks/app/api/docker-config/route-f5e054069fb68dd7.js +0 -1
  457. package/bundle/standalone/apps/web/.next/static/chunks/app/api/export/zip/route-f5e054069fb68dd7.js +0 -1
  458. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/backlinks/route-f5e054069fb68dd7.js +0 -1
  459. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/download/route-f5e054069fb68dd7.js +0 -1
  460. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/export-html/route-f5e054069fb68dd7.js +0 -1
  461. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/export-pdf/route-f5e054069fb68dd7.js +0 -1
  462. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/history/restore/route-f5e054069fb68dd7.js +0 -1
  463. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/history/route-f5e054069fb68dd7.js +0 -1
  464. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/move/route-f5e054069fb68dd7.js +0 -1
  465. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/[id]/route-f5e054069fb68dd7.js +0 -1
  466. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/route-f5e054069fb68dd7.js +0 -1
  467. package/bundle/standalone/apps/web/.next/static/chunks/app/api/files/upload/route-f5e054069fb68dd7.js +0 -1
  468. package/bundle/standalone/apps/web/.next/static/chunks/app/api/folders/route-f5e054069fb68dd7.js +0 -1
  469. package/bundle/standalone/apps/web/.next/static/chunks/app/api/git/remote/route-f5e054069fb68dd7.js +0 -1
  470. package/bundle/standalone/apps/web/.next/static/chunks/app/api/git/sync-all/route-f5e054069fb68dd7.js +0 -1
  471. package/bundle/standalone/apps/web/.next/static/chunks/app/api/hands/test-pattern/route-f5e054069fb68dd7.js +0 -1
  472. package/bundle/standalone/apps/web/.next/static/chunks/app/api/hands/validate/route-f5e054069fb68dd7.js +0 -1
  473. package/bundle/standalone/apps/web/.next/static/chunks/app/api/health/route-f5e054069fb68dd7.js +0 -1
  474. package/bundle/standalone/apps/web/.next/static/chunks/app/api/install-snippets/route-f5e054069fb68dd7.js +0 -1
  475. package/bundle/standalone/apps/web/.next/static/chunks/app/api/mcp-tools/route-f5e054069fb68dd7.js +0 -1
  476. package/bundle/standalone/apps/web/.next/static/chunks/app/api/profile/route-f5e054069fb68dd7.js +0 -1
  477. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/hands-config/route-f5e054069fb68dd7.js +0 -1
  478. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/journal-config/route-f5e054069fb68dd7.js +0 -1
  479. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/journal-status/route-f5e054069fb68dd7.js +0 -1
  480. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/onboard/route-f5e054069fb68dd7.js +0 -1
  481. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/refresh/route-f5e054069fb68dd7.js +0 -1
  482. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/route-f5e054069fb68dd7.js +0 -1
  483. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/[id]/sync/route-f5e054069fb68dd7.js +0 -1
  484. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/onboard/route-f5e054069fb68dd7.js +0 -1
  485. package/bundle/standalone/apps/web/.next/static/chunks/app/api/projects/route-f5e054069fb68dd7.js +0 -1
  486. package/bundle/standalone/apps/web/.next/static/chunks/app/api/publish/html/route-f5e054069fb68dd7.js +0 -1
  487. package/bundle/standalone/apps/web/.next/static/chunks/app/api/publish/route-f5e054069fb68dd7.js +0 -1
  488. package/bundle/standalone/apps/web/.next/static/chunks/app/api/refresh/route-f5e054069fb68dd7.js +0 -1
  489. package/bundle/standalone/apps/web/.next/static/chunks/app/api/reindex/route-f5e054069fb68dd7.js +0 -1
  490. package/bundle/standalone/apps/web/.next/static/chunks/app/api/reports/resources/[name]/route-f5e054069fb68dd7.js +0 -1
  491. package/bundle/standalone/apps/web/.next/static/chunks/app/api/search/route-f5e054069fb68dd7.js +0 -1
  492. package/bundle/standalone/apps/web/.next/static/chunks/app/api/tags/route-f5e054069fb68dd7.js +0 -1
  493. package/bundle/standalone/apps/web/.next/static/chunks/app/api/version-check/route-f5e054069fb68dd7.js +0 -1
  494. package/bundle/standalone/apps/web/.next/static/chunks/app/api/welcome/route-f5e054069fb68dd7.js +0 -1
  495. package/bundle/standalone/apps/web/.next/static/chunks/app/api/ws-config/route-f5e054069fb68dd7.js +0 -1
  496. package/bundle/standalone/apps/web/.next/static/chunks/app/page-eccc7438c998fcce.js +0 -1
  497. package/bundle/standalone/apps/web/.next/static/chunks/app/preview/motifs/page-f5e054069fb68dd7.js +0 -1
  498. package/bundle/standalone/apps/web/.next/static/css/35a6a6dfd2c31933.css +0 -3
  499. /package/bundle/standalone/apps/web/.next/static/{DWDlM7S8dTnMlrhKW9K_X → IxgiSiK05GtQGxU41f-Mx}/_ssgManifest.js +0 -0
@@ -2,7 +2,7 @@
2
2
  import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
4
  import { z } from "zod";
5
- import { createFile, readFile, updateFile, deleteFile, listFiles, addTags, removeTags, setFavorite, search, FtsQueryError, registerProject, discoverFiles, refreshIndex, listTags, listProjects, syncBackup, bundleSearch, estimateTokensFromBuffer, clipUrl, ClipError, getHistory, getDiff, getDatabase, findRelated, whatsNew, projectMap, getTagsForFiles, restoreVersion, parseOutline, findSection, replaceSection, listProjectFolders, createFolder, deleteFolder, moveFile, detectAgentContextFiles, assertPathInside, syncAgentRules, checkAgentRulesStatus, RULE_BLOCK_VERSION, gracefulShutdown, startDistillEngine, writeResource, listResources, deleteResource, } from "kxta-core";
5
+ import { createFile, readFile, updateFile, deleteFile, listFiles, addTags, removeTags, setFavorite, search, FtsQueryError, registerProject, discoverFiles, refreshIndex, listTags, listProjects, syncBackup, bundleSearch, estimateTokensFromBuffer, clipUrl, ClipError, getHistory, getDiff, getDatabase, findRelated, whatsNew, projectMap, getTagsForFiles, restoreVersion, parseOutline, findSection, replaceSection, listProjectFolders, createFolder, deleteFolder, moveFile, detectAgentContextFiles, assertPathInside, syncAgentRules, checkAgentRulesStatus, RULE_BLOCK_VERSION, gracefulShutdown, startDistillEngine, writeResource, listResources, deleteResource, syncAgentRows, } from "kxta-core";
6
6
  import RE2Class from "./re2-compat.js";
7
7
  import { isAbsolute, join, relative, resolve, sep, dirname } from "node:path";
8
8
  import { statSync, lstatSync, openSync, readSync, closeSync, readFileSync, existsSync, realpathSync } from "node:fs";
@@ -12,8 +12,9 @@ import { HandsRegistry } from "./hands/registry.js";
12
12
  import { buildSchemaDoc } from "./hands/schema-doc.js";
13
13
  import { formatExecResult } from "./hands/formatter.js";
14
14
  import { killAllActiveChildren } from "./hands/executor.js";
15
- import { initCapture, shutdownCapture, wrapHandler, startGitPoller } from "./journal-capture.js";
15
+ import { initCapture, shutdownCapture, wrapHandler, startGitPoller, appendVoluntaryEvent, getCurrentAgent, getCurrentSid } from "./journal-capture.js";
16
16
  import { registerJournalTools } from "./journal-tools.js";
17
+ import { currentHooksBlock, enableAndInstallHooks } from "./hooks-block.js";
17
18
  import { registerCommitUpgradesTool } from "./journal-commit-upgrades-tool.js";
18
19
  import { registerHousekeepTool } from "./journal-housekeep-tool.js";
19
20
  import { registerCalendarTools } from "./calendar-tools.js";
@@ -35,24 +36,43 @@ function getAgentRulesWarning(projectId) {
35
36
  else {
36
37
  projects = db.prepare("SELECT id, path, name FROM projects").all();
37
38
  }
39
+ // Projects with zero detected context files have NEVER been onboarded —
40
+ // distinct from "outdated" (a file exists but predates the current
41
+ // rulesVersion). Both need admin.onboard_agent, so both are surfaced
42
+ // here; without this, a project that skipped its one-shot
43
+ // projects.register nudge would never get flagged again.
44
+ const missingProjects = [];
38
45
  const outdatedProjects = [];
39
46
  for (const p of projects) {
40
47
  if (!p || !p.path || !existsSync(p.path))
41
48
  continue;
42
49
  const contextFiles = detectAgentContextFiles(p.path);
43
- if (contextFiles.length === 0)
50
+ if (contextFiles.length === 0) {
51
+ missingProjects.push(p.name);
44
52
  continue;
53
+ }
45
54
  const statuses = checkAgentRulesStatus(p.path, contextFiles);
46
55
  if (statuses.some((s) => !s.upToDate)) {
47
56
  outdatedProjects.push(p.name);
48
57
  }
49
58
  }
50
- if (outdatedProjects.length === 0)
51
- return null;
59
+ const sentences = [];
60
+ if (missingProjects.length === 1) {
61
+ sentences.push(`Project "${missingProjects[0]}" has no agent instructions file yet.`);
62
+ }
63
+ else if (missingProjects.length > 1) {
64
+ sentences.push(`${missingProjects.length} projects have no agent instructions file yet.`);
65
+ }
52
66
  if (outdatedProjects.length === 1) {
53
- return `Project "${outdatedProjects[0]}" has outdated agent rules (v${RULE_BLOCK_VERSION} available). Run onboard_agent to update.`;
67
+ sentences.push(`Project "${outdatedProjects[0]}" has outdated agent rules (v${RULE_BLOCK_VERSION} available).`);
54
68
  }
55
- return `${outdatedProjects.length} projects have outdated agent rules (v${RULE_BLOCK_VERSION} available). Run onboard_agent for each to update.`;
69
+ else if (outdatedProjects.length > 1) {
70
+ sentences.push(`${outdatedProjects.length} projects have outdated agent rules (v${RULE_BLOCK_VERSION} available).`);
71
+ }
72
+ if (sentences.length === 0)
73
+ return null;
74
+ sentences.push("Run admin.onboard_agent to fix.");
75
+ return sentences.join(" ");
56
76
  }
57
77
  catch (e) {
58
78
  console.error("Error checking agent rules status:", e);
@@ -141,12 +161,43 @@ catch (e) {
141
161
  if (!pkgVersionFound) {
142
162
  console.warn("Could not locate kontexta-mcp package.json by walking up from module dir; defaulting version to 0.0.0");
143
163
  }
144
- function resolveKindFolder({ destination, folder, kind }) {
145
- if (destination !== "knowledge")
164
+ function resolveKindFolder({ destination, folder, kind, format, title }) {
165
+ if (destination !== "knowledge") {
166
+ // HTML reports only make sense in the KB's html/ bucket (see
167
+ // resources.export_report) — silently allowing destination='project'
168
+ // here means a report lands inside the user's own repo instead, with
169
+ // no error and no way to find it via the reports UI.
170
+ if (format === "html") {
171
+ return { error: "format='html' requires destination='knowledge' — HTML reports must live in the KB's html/ bucket, not a project or kontexta destination." };
172
+ }
146
173
  return { folder };
174
+ }
175
+ const norm = folder?.replace(/^\/+|\/+$/g, "") ?? "";
176
+ // Escape hatch: a bare `profile.md` at KB root bypasses kind-routing.
177
+ // It's the one file layout.ts permits directly under knowledge/, and
178
+ // otherwise there is no way to reach KB root through this tool.
179
+ if (norm === "" && title?.trim().toLowerCase() === "profile") {
180
+ return { folder: undefined };
181
+ }
182
+ // HTML reports always live under html/, never nested inside
183
+ // knowledge/dictionary or knowledge/notes (layout.ts requires .md
184
+ // there). `kind` doesn't apply — content_class for html/ paths is
185
+ // inferred as "note" from the path alone (see computeContentClass).
186
+ if (format === "html") {
187
+ const alreadyHtmlScoped = norm === "html" || norm.startsWith("html/");
188
+ return { folder: alreadyHtmlScoped ? folder : (norm ? `html/${norm}` : "html") };
189
+ }
190
+ // Same gap, same fix, for mermaid diagrams: knowledge/ requires .md
191
+ // (layout.ts), so an unrouted .mmd file would always fail at write
192
+ // time. Unlike html, mermaid diagrams committed inside a project's own
193
+ // repo are a legitimate use case, so this only applies to destination
194
+ // === "knowledge" — no destination restriction like html has.
195
+ if (format === "mmd") {
196
+ const alreadyMermaidScoped = norm === "mermaid" || norm.startsWith("mermaid/");
197
+ return { folder: alreadyMermaidScoped ? folder : (norm ? `mermaid/${norm}` : "mermaid") };
198
+ }
147
199
  if (!kind)
148
200
  return { error: "kind is required for destination='knowledge': must be 'dictionary' or 'note'" };
149
- const norm = folder?.replace(/^\/+|\/+$/g, "") ?? "";
150
201
  // Non-KB buckets (html/mermaid) also skip rewrite — their layout forbids nesting under knowledge/.
151
202
  const CLASS_PREFIXES = ["knowledge/dictionary", "knowledge/notes", "knowledge/urlclips", "journal", "html", "mermaid"];
152
203
  const alreadyClassScoped = CLASS_PREFIXES.some((p) => norm === p || norm.startsWith(p + "/"));
@@ -237,7 +288,15 @@ function loadProfileInstructions() {
237
288
  : `📋 PROFILE\n (not set up yet — nudge the user to fill it in at knowledge/profile.md or the dashboard's profile pane)`;
238
289
  const calendarBlock = buildCalendarSection(now);
239
290
  const freshness = profileExists ? profileFreshnessNote(path, empty) : "";
240
- return [header, "", profileBlock, "", calendarBlock, freshness].filter(Boolean).join("\n");
291
+ // Recurring nudge — projects.register's onboarding prompt fires once, at
292
+ // register time; if the calling agent doesn't relay it in the moment
293
+ // there was previously no second chance to see it. Surfacing it here
294
+ // means it comes back every session until admin.onboard_agent is run.
295
+ const rulesWarning = getAgentRulesWarning();
296
+ const rulesBlock = rulesWarning ? `\n⚠️ ${rulesWarning}` : "";
297
+ const hooksNudge = currentHooksBlock(pkgVersion)?.prompt;
298
+ const hooksLine = hooksNudge ? `\n🪝 ${hooksNudge}` : "";
299
+ return [header, "", profileBlock, "", calendarBlock, freshness, rulesBlock, hooksLine].filter(Boolean).join("\n");
241
300
  }
242
301
  const server = new McpServer({ name: "kontexta", version: pkgVersion }, { instructions: loadProfileInstructions() });
243
302
  server.tool("admin.refresh_session_context", "Re-read the session context (profile, upcoming events within 7d, conflicts, freshness nudge) as it stands NOW. Call this when the user just edited their profile or added/moved calendar events and you want the current picture instead of the snapshot taken at session start. Read-only; no side effects. Returns the same block Kontexta sent as MCP instructions at session start.", {}, async () => ({
@@ -250,6 +309,10 @@ const projectSlug = process.env.KONTEXTA_DEFAULT_PROJECT_SLUG ?? "default";
250
309
  const agent = process.env.KONTEXTA_AGENT ?? "unknown";
251
310
  const sid = `${process.pid}-${Date.now().toString(36)}`;
252
311
  initCapture({ projectSlug, baseDir: baseJournalDir, agent, sid });
312
+ try {
313
+ syncAgentRows();
314
+ }
315
+ catch { /* agents table is re-seeded on the next start */ }
253
316
  const distillEngineEnabled = process.env.KONTEXTA_DISTILL_ENGINE !== "off";
254
317
  const distillEngine = distillEngineEnabled
255
318
  ? startDistillEngine({
@@ -294,11 +357,12 @@ process.on("SIGTERM", () => { if (!_shutdownInFlight) {
294
357
  _shutdownInFlight = true;
295
358
  void handleShutdownSignal("SIGTERM");
296
359
  } });
297
- // Auto-wrap every tool registration that follows. journal_append (legacy) is excluded
298
- // because it will be removed in Task 15. Auto-wrap covers all current and future tools.
360
+ // Auto-wrap every tool registration that follows. journal.write is excluded
361
+ // because the auto-wrap re-enters journal recording, and journal.write itself
362
+ // records journal events — including it would loop.
299
363
  const _origServerTool = server.tool.bind(server);
300
364
  server.tool = function (name, ...rest) {
301
- if (name === "journal.append") {
365
+ if (name === "journal.write") {
302
366
  return _origServerTool(name, ...rest);
303
367
  }
304
368
  const handler = rest[rest.length - 1];
@@ -307,86 +371,145 @@ server.tool = function (name, ...rest) {
307
371
  }
308
372
  return _origServerTool(name, ...rest);
309
373
  };
310
- // Legacy journal_append tool — excluded from wrapHandler (line 223) so it
311
- // does NOT get the journal-backlog envelope injected. Kept for backward-compat.
312
- server.tool("journal.append", "Append a timestamped text entry to today's daily journal file in the Knowledge Base. Creates the file if it doesn't already exist. Both calls on the same calendar day return the same file_id. Returns { file_id }.", {
313
- text: z.string().describe("Text to append to today's journal entry"),
314
- project_id: z.number().optional().describe("Optional project ID context"),
315
- }, async ({ text }) => {
316
- try {
317
- const today = new Date().toISOString().slice(0, 10); // YYYY-MM-DD
318
- const journalFolder = "journal";
319
- const title = `journal-${today}`;
320
- const db = getDatabase();
321
- // Try to find an existing journal file for today.
322
- const knowledgeDir = join(dataDir, "knowledge");
323
- const expectedPath = join(knowledgeDir, journalFolder, `${title}.md`);
324
- const existingRow = db
325
- .prepare("SELECT id, path FROM files WHERE path = ? AND project_id IS NULL")
326
- .get(expectedPath);
327
- if (existingRow) {
328
- // Append to existing file.
329
- const existing = readFile(existingRow.id);
330
- const timestamp = new Date().toISOString().replace("T", " ").slice(0, 19);
331
- const newContent = `${existing.content}\n---\n**${timestamp}** ${text}\n`;
332
- await updateFile(existingRow.id, newContent, dataDir);
374
+ // Excluded from wrapHandler (see above) so it does NOT get the
375
+ // journal-backlog envelope injected — it IS the journal write path.
376
+ server.tool("journal.write", "Write one event to the current project's journal. `kind: 'append'` = timestamped entry in today's daily journal file in the Knowledge Base (creates the file if it doesn't exist; both calls on the same calendar day return the same file_id; returns `{file_id}`). `kind: 'note'` = free-form decision/abandonment/observation, stored as an `agent_note` event in Layer 1 (surfaces in distilled task entries; returns `{ok, recorded_at}`). `kind: 'intent'` = topic/intent pivot — use when the user redirects what you're working on so the distillation step splits task buckets correctly (returns `{ok, recorded_at}`). Required fields depend on `kind`: 'append'/'note' need `text`; 'intent' needs `summary`.", {
377
+ kind: z.enum(["append", "note", "intent"]).describe("Event kind. Selects which body fields are required and how the event is stored."),
378
+ text: z.string().optional().describe("Required for kind='append' or kind='note'. Body of the entry."),
379
+ summary: z.string().optional().describe("Required for kind='intent'. One-line summary of the new intent."),
380
+ tags: z.array(z.string()).optional().describe("Optional for kind='note'. Tags for the note."),
381
+ project_id: z.number().optional().describe("Optional for kind='append'. Project ID context."),
382
+ }, async ({ kind, text, summary, tags }) => {
383
+ if (kind === "append") {
384
+ if (!text) {
385
+ return { isError: true, content: [{ type: "text", text: JSON.stringify({ error: "kind='append' requires `text`" }, null, 2) }] };
386
+ }
387
+ try {
388
+ const today = new Date().toISOString().slice(0, 10); // YYYY-MM-DD
389
+ const journalFolder = "journal";
390
+ const title = `journal-${today}`;
391
+ const db = getDatabase();
392
+ // Try to find an existing journal file for today.
393
+ const knowledgeDir = join(dataDir, "knowledge");
394
+ const expectedPath = join(knowledgeDir, journalFolder, `${title}.md`);
395
+ const existingRow = db
396
+ .prepare("SELECT id, path FROM files WHERE path = ? AND project_id IS NULL")
397
+ .get(expectedPath);
398
+ if (existingRow) {
399
+ // Append to existing file.
400
+ const existing = readFile(existingRow.id);
401
+ const timestamp = new Date().toISOString().replace("T", " ").slice(0, 19);
402
+ const newContent = `${existing.content}\n---\n**${timestamp}** ${text}\n`;
403
+ await updateFile(existingRow.id, newContent, dataDir);
404
+ return {
405
+ content: [{ type: "text", text: JSON.stringify({ file_id: existingRow.id }, null, 2) }],
406
+ };
407
+ }
408
+ else {
409
+ // Create a new daily journal file.
410
+ const timestamp = new Date().toISOString().replace("T", " ").slice(0, 19);
411
+ const content = `# Journal — ${today}\n\n---\n**${timestamp}** ${text}\n`;
412
+ const result = await createFile({
413
+ title,
414
+ content,
415
+ destination: "knowledge",
416
+ folder: journalFolder,
417
+ dataDir,
418
+ });
419
+ return {
420
+ content: [{ type: "text", text: JSON.stringify({ file_id: result.id }, null, 2) }],
421
+ };
422
+ }
423
+ }
424
+ catch (e) {
333
425
  return {
334
- content: [{ type: "text", text: JSON.stringify({ file_id: existingRow.id }, null, 2) }],
426
+ isError: true,
427
+ content: [{ type: "text", text: JSON.stringify({ error: e?.message ?? String(e) }, null, 2) }],
335
428
  };
336
429
  }
337
- else {
338
- // Create a new daily journal file.
339
- const timestamp = new Date().toISOString().replace("T", " ").slice(0, 19);
340
- const content = `# Journal — ${today}\n\n---\n**${timestamp}** ${text}\n`;
430
+ }
431
+ if (kind === "note") {
432
+ if (!text) {
433
+ return { isError: true, content: [{ type: "text", text: JSON.stringify({ error: "kind='note' requires `text`" }, null, 2) }] };
434
+ }
435
+ const ev = {
436
+ ts: new Date().toISOString(),
437
+ agent: getCurrentAgent(),
438
+ sid: getCurrentSid(),
439
+ event: "agent_note",
440
+ summary: text,
441
+ tags: tags ?? [],
442
+ };
443
+ appendVoluntaryEvent(ev);
444
+ return { content: [{ type: "text", text: JSON.stringify({ ok: true, recorded_at: ev.ts }) }] };
445
+ }
446
+ // kind === "intent"
447
+ if (!summary) {
448
+ return { isError: true, content: [{ type: "text", text: JSON.stringify({ error: "kind='intent' requires `summary`" }, null, 2) }] };
449
+ }
450
+ const ev = {
451
+ ts: new Date().toISOString(),
452
+ agent: getCurrentAgent(),
453
+ sid: getCurrentSid(),
454
+ event: "user_intent",
455
+ summary,
456
+ };
457
+ appendVoluntaryEvent(ev);
458
+ return { content: [{ type: "text", text: JSON.stringify({ ok: true, recorded_at: ev.ts }) }] };
459
+ });
460
+ server.tool("files.create", "Create one or more markdown, mermaid, or HTML files in the knowledge base or project (up to 200 per call). Pass a single-element `files` array for the one-file case. This operation writes each file to disk and adds it to the local SQLite FTS5 index. Destination can be 'knowledge' (global KB), 'project' (reference file inside a project repo), or 'kontexta' (internal Kontexta schema file). If destination is 'project' or 'kontexta', project_id is strictly required. If destination is 'knowledge', 'kind' is strictly required for md files — pick 'dictionary' (authoritative source-of-truth) or 'note' (informational snapshot); see the kind param for the rubric. No external auth required. Rate limits do not apply (local operation). Per-item failures are isolated to `errors[]` — the rest of the batch still commits; a single-item call still reports its failure the same way. Returns `{created_count, error_count, created, errors}`. If a destination directory does not exist, it will be created automatically. To modify an existing file, use 'files.update' instead. Pass format='mmd' on an item to create a Mermaid diagram file (.mmd) — for destination='knowledge' it's auto-routed to the KB's `mermaid/` bucket (`kind` ignored, not required); for destination='project' it's written wherever `folder` says, same as any project file. Pass format='html' for an HTML report — `destination` MUST be 'knowledge' (html reports are auto-routed to the KB's `html/` bucket; `kind` is ignored and not required for html). Format defaults to 'md'.", {
461
+ files: z
462
+ .array(z.object({
463
+ title: z.string().describe("Title of the file"),
464
+ content: z.string().describe("Content of the file"),
465
+ destination: z.enum(["knowledge", "project", "kontexta"]).describe("Destination type"),
466
+ project_id: z.number().optional().describe("Project ID (required for project/kontexta destinations)"),
467
+ folder: z.string().optional().describe("Optional folder path"),
468
+ tags: z.array(z.string()).optional().describe("Optional array of tags"),
469
+ format: z.enum(["md", "mmd", "html"]).optional().describe("File extension to write. Defaults to 'md'. Use 'html' for HTML reports."),
470
+ kind: z.enum(["dictionary", "note"]).optional()
471
+ .describe("REQUIRED for destination='knowledge'. 'dictionary' = source of truth (mappings, glossaries, runbooks, PR templates). 'note' = snapshot (meeting notes, sprint reviews, PR findings, post-mortems). Test: if this file disagreed with the code, who wins? File wins → dictionary; file loses → note. Ignored for destination='project' or 'kontexta'."),
472
+ }))
473
+ .min(1)
474
+ .max(200)
475
+ .describe("Files to create. Single-element array = one-file case. Max 200 per call."),
476
+ }, async ({ files }) => {
477
+ const created = [];
478
+ const errors = [];
479
+ for (let i = 0; i < files.length; i++) {
480
+ const f = files[i];
481
+ try {
482
+ const resolved = resolveKindFolder({ destination: f.destination, folder: f.folder, kind: f.kind, format: f.format, title: f.title });
483
+ if ("error" in resolved) {
484
+ errors.push({ index: i, title: f.title, error: resolved.error });
485
+ continue;
486
+ }
341
487
  const result = await createFile({
342
- title,
343
- content,
344
- destination: "knowledge",
345
- folder: journalFolder,
488
+ title: f.title,
489
+ content: f.content,
490
+ destination: f.destination,
491
+ projectId: f.project_id,
492
+ folder: resolved.folder,
493
+ tags: f.tags,
346
494
  dataDir,
495
+ format: f.format,
347
496
  });
348
- return {
349
- content: [{ type: "text", text: JSON.stringify({ file_id: result.id }, null, 2) }],
350
- };
497
+ const payload = annotateTokens(result);
498
+ if (resolved.warning)
499
+ payload.warning = resolved.warning;
500
+ created.push(payload);
501
+ }
502
+ catch (e) {
503
+ errors.push({ index: i, title: f.title, error: e?.message ?? String(e) });
351
504
  }
352
505
  }
353
- catch (e) {
354
- return {
355
- isError: true,
356
- content: [{ type: "text", text: JSON.stringify({ error: e?.message ?? String(e) }, null, 2) }],
357
- };
358
- }
359
- });
360
- server.tool("files.create", "Create a new markdown, mermaid, or HTML file in the knowledge base or project. This operation writes a new file to disk and adds it to the local SQLite FTS5 index. Destination can be 'knowledge' (global KB), 'project' (reference file inside a project repo), or 'kontexta' (internal Kontexta schema file). If destination is 'project' or 'kontexta', project_id is strictly required. If destination is 'knowledge', 'kind' is strictly required — pick 'dictionary' (authoritative source-of-truth) or 'note' (informational snapshot); see the kind param for the rubric. No external auth required. Rate limits do not apply (local operation). Returns the created file metadata including its new ID, path, and estimated tokens. If the destination directory does not exist, it will be created automatically. Use this tool to instantiate new contextual documents or notes. To modify an existing file, use 'files.update' instead. Parameters: 'destination' dictates required fields; if 'project' or 'kontexta', 'project_id' must be a valid integer; if 'knowledge', 'kind' must be 'dictionary' or 'note'. 'tags' and 'folder' are optional. Pass format='mmd' to create a Mermaid diagram file (.mmd) or format='html' for HTML reports; defaults to 'md'.", {
361
- title: z.string().describe("Title of the file"),
362
- content: z.string().describe("Content of the file"),
363
- destination: z.enum(["knowledge", "project", "kontexta"]).describe("Destination type"),
364
- project_id: z.number().optional().describe("Project ID (required for project/kontexta destinations)"),
365
- folder: z.string().optional().describe("Optional folder path"),
366
- tags: z.array(z.string()).optional().describe("Optional array of tags"),
367
- format: z.enum(["md", "mmd", "html"]).optional().describe("File extension to write. Defaults to 'md'. Use 'html' for HTML reports."),
368
- kind: z.enum(["dictionary", "note"]).optional()
369
- .describe("REQUIRED for destination='knowledge'. 'dictionary' = source of truth (mappings, glossaries, runbooks, PR templates). 'note' = snapshot (meeting notes, sprint reviews, PR findings, post-mortems). Test: if this file disagreed with the code, who wins? File wins → dictionary; file loses → note. Ignored for destination='project' or 'kontexta'."),
370
- }, async ({ title, content, destination, project_id, folder, tags, format, kind }) => {
371
- const resolved = resolveKindFolder({ destination, folder, kind });
372
- if ("error" in resolved) {
373
- return { isError: true, content: [{ type: "text", text: JSON.stringify({ error: resolved.error }, null, 2) }] };
374
- }
375
- const result = await createFile({
376
- title,
377
- content,
378
- destination,
379
- projectId: project_id,
380
- folder: resolved.folder,
381
- tags,
382
- dataDir,
383
- format,
384
- });
385
- const payload = annotateTokens(result);
386
- if (resolved.warning)
387
- payload.warning = resolved.warning;
388
506
  return {
389
- content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
507
+ content: [
508
+ {
509
+ type: "text",
510
+ text: JSON.stringify({ created_count: created.length, error_count: errors.length, created, errors }, null, 2),
511
+ },
512
+ ],
390
513
  };
391
514
  });
392
515
  server.tool("resources.add_report", "Write an image or other binary resource into the shared reports/resources/ folder. Returns { filename, size, src, url } — embed the report's <img>/<a> tags with `src` exactly as given (e.g. `<img src=\"resources/chart.png\">`); it is the only form that resolves correctly both in the dashboard viewer and in PDF/PNG export. Do not use `url` inside report HTML — it only works in the dashboard. Bytes are passed base64-encoded.", {
@@ -427,33 +550,102 @@ server.tool("resources.export_report", "Export an existing HTML report as PDF or
427
550
  return { content: [{ type: "text", text: JSON.stringify({ url, note: `inline_bytes unavailable in this install: ${e?.message ?? String(e)}` }, null, 2) }] };
428
551
  }
429
552
  });
430
- server.tool("files.read", "Read one file's full body and metadata by ID. Read-only; no side effects, auth, or rate limits. Returns title, path, content, tags, est_tokens (so you can budget context before opening more files), and timestamps. Throws if the ID is unknown. Use for a single known file. Prefer `files.describe` to inspect without paying body tokens; `files.read_many` for batches; `files.read_lines`/`files.read_section` for partial reads; `files.read_by_path` when you only have the absolute path.", {
431
- id: z.number().describe("File ID"),
432
- }, async ({ id }) => {
433
- const result = readFile(id);
434
- return {
435
- content: [{ type: "text", text: JSON.stringify(annotateTokens(result), null, 2) }],
436
- };
437
- });
438
- server.tool("files.read_many", "Batch read up to 200 files by ID in one call. Returns per-file annotated records, an aggregate `total_est_tokens`, and an isolated `errors[]` (one bad ID does NOT abort the batch). Read-only; no side effects, auth, or rate limits. Use instead of looping `files.read` to halve round-trips and get the combined token cost upfront. For >200 IDs, page yourself.", {
439
- ids: z.array(z.number()).min(1).max(200).describe("File IDs to read (max 200 per call)"),
440
- }, async ({ ids }) => {
441
- const files = [];
442
- const errors = [];
443
- let total_est_tokens = 0;
444
- for (const id of ids) {
445
- try {
446
- const r = annotateTokens(readFile(id));
447
- files.push(r);
448
- total_est_tokens += r.est_tokens ?? 0;
553
+ server.tool("files.read", "Read one or more files, in full or in part. Modes: single-by-id (`id`), single-by-path (`path`, absolute on-disk path — must be exactly as indexed), batch-by-id (`ids`, up to 200), partial-by-heading (`id`+`section`), partial-by-line-range (`id`+`lines`). Exactly one of `id`/`path`/`ids` is required. `section` and `lines` are mutually exclusive and only valid with `id` (not `ids` or `path`). Read-only; no side effects, auth, or rate limits. Response shape: a single file object (with `content`, tags, est_tokens) for `id`/`path`; a partial-content object for `section`/`lines`; `{files, total_est_tokens, error_count, errors}` for `ids` (per-ID failures isolated, batch never partial-throws). Prefer `files.describe` to inspect without paying body tokens.", {
554
+ id: z.number().int().positive().optional().describe("Single file by ID."),
555
+ path: z.string().optional().describe("Single file by absolute on-disk path (must match exactly what Kontexta indexed)."),
556
+ ids: z.array(z.number()).min(1).max(200).optional().describe("Batch mode: multiple file IDs (max 200 per call); returns an array plus aggregate token cost."),
557
+ section: z.string().optional().describe("Partial read: return only this heading's body (case-insensitive exact-string after trim). Requires `id`; mutually exclusive with `lines`."),
558
+ lines: z.object({
559
+ from: z.number().int().positive().describe("First line (1-indexed, inclusive)"),
560
+ to: z.number().int().positive().describe("Last line (1-indexed, inclusive)"),
561
+ }).optional().describe("Partial read: 1-indexed inclusive line range. Requires `id`; mutually exclusive with `section`."),
562
+ }, async ({ id, path, ids, section, lines }) => {
563
+ const modeCount = [id !== undefined, path !== undefined, ids !== undefined].filter(Boolean).length;
564
+ if (modeCount !== 1) {
565
+ return { isError: true, content: [{ type: "text", text: JSON.stringify({ error: "Exactly one of `id`, `path`, or `ids` must be present" }, null, 2) }] };
566
+ }
567
+ if (section !== undefined && lines !== undefined) {
568
+ return { isError: true, content: [{ type: "text", text: JSON.stringify({ error: "`section` and `lines` are mutually exclusive" }, null, 2) }] };
569
+ }
570
+ if ((section !== undefined || lines !== undefined) && ids !== undefined) {
571
+ return { isError: true, content: [{ type: "text", text: JSON.stringify({ error: "`section`/`lines` require `id` (single-file mode), not `ids`" }, null, 2) }] };
572
+ }
573
+ if ((section !== undefined || lines !== undefined) && path !== undefined) {
574
+ return { isError: true, content: [{ type: "text", text: JSON.stringify({ error: "`section`/`lines` require `id`, not `path`" }, null, 2) }] };
575
+ }
576
+ try {
577
+ if (ids !== undefined) {
578
+ const files = [];
579
+ const errors = [];
580
+ let total_est_tokens = 0;
581
+ for (const rid of ids) {
582
+ try {
583
+ const r = annotateTokens(readFile(rid));
584
+ files.push(r);
585
+ total_est_tokens += r.est_tokens ?? 0;
586
+ }
587
+ catch (e) {
588
+ errors.push({ id: rid, error: e?.message ?? String(e) });
589
+ }
590
+ }
591
+ return {
592
+ content: [{ type: "text", text: JSON.stringify({ files, total_est_tokens, error_count: errors.length, errors }, null, 2) }],
593
+ };
449
594
  }
450
- catch (e) {
451
- errors.push({ id, error: e?.message ?? String(e) });
595
+ let resolvedId;
596
+ if (path !== undefined) {
597
+ if (path.length === 0)
598
+ throw new Error("path is required");
599
+ const row = getDatabase().prepare("SELECT id FROM files WHERE path = ?").get(path);
600
+ if (!row) {
601
+ return { isError: true, content: [{ type: "text", text: JSON.stringify({ error: `No file indexed at path: ${path}` }, null, 2) }] };
602
+ }
603
+ resolvedId = row.id;
604
+ }
605
+ else {
606
+ resolvedId = id;
452
607
  }
608
+ if (section !== undefined) {
609
+ const file = readFile(resolvedId);
610
+ const node = findSection(file.content, section);
611
+ if (!node) {
612
+ return { isError: true, content: [{ type: "text", text: JSON.stringify({ error: `Section not found: ${section}` }, null, 2) }] };
613
+ }
614
+ const buf = Buffer.from(file.content, "utf8");
615
+ const body = buf.subarray(node.contentStart, node.contentEnd).toString("utf8");
616
+ return {
617
+ content: [{ type: "text", text: JSON.stringify({
618
+ file_id: resolvedId, path: file.path, heading: node.text, level: node.level, line: node.line,
619
+ content: body, size_bytes: Buffer.byteLength(body, "utf8"), est_tokens: estimateTokensFromBuffer(Buffer.from(body, "utf8")),
620
+ }, null, 2) }],
621
+ };
622
+ }
623
+ if (lines !== undefined) {
624
+ if (lines.to < lines.from)
625
+ throw new Error("`lines.to` must be >= `lines.from`");
626
+ const file = readFile(resolvedId);
627
+ const allLines = file.content.split("\n");
628
+ const start = Math.max(0, lines.from - 1);
629
+ const end = Math.min(allLines.length, lines.to);
630
+ const slice = allLines.slice(start, end).join("\n");
631
+ return {
632
+ content: [{ type: "text", text: JSON.stringify({
633
+ file_id: resolvedId, path: file.path, from: start + 1, to: end, total_lines: allLines.length,
634
+ content: slice, size_bytes: Buffer.byteLength(slice, "utf8"), est_tokens: estimateTokensFromBuffer(Buffer.from(slice, "utf8")),
635
+ }, null, 2) }],
636
+ };
637
+ }
638
+ const result = readFile(resolvedId);
639
+ return {
640
+ content: [{ type: "text", text: JSON.stringify(annotateTokens(result), null, 2) }],
641
+ };
642
+ }
643
+ catch (e) {
644
+ return {
645
+ isError: true,
646
+ content: [{ type: "text", text: JSON.stringify({ error: e?.message ?? String(e) }, null, 2) }],
647
+ };
453
648
  }
454
- return {
455
- content: [{ type: "text", text: JSON.stringify({ files, total_est_tokens, error_count: errors.length, errors }, null, 2) }],
456
- };
457
649
  });
458
650
  server.tool("files.describe", "Return everything ABOUT a file without pulling its content (no token cost from the body). Tags, size, est_tokens, history depth, related-file ids, backlinks, project, folder, last edited. Operates locally with no auth or rate limits. Use this when you'd otherwise chain files.read + tags.list + files.get_history + files.find_related just to decide whether to actually read the file. Parameters: 'id' must be a valid integer file ID.", {
459
651
  id: z.number().describe("File ID"),
@@ -575,101 +767,17 @@ server.tool("files.describe", "Return everything ABOUT a file without pulling it
575
767
  };
576
768
  }
577
769
  });
578
- server.tool("files.read_lines", "Return a 1-indexed inclusive line slice of a file. Out-of-range bounds clamp silently to the file's actual length; `to < from` throws. Read-only; no side effects, auth, or rate limits. Returns the snippet plus its size_bytes and est_tokens. Use to inspect a stack-trace region or a chunk of a large file without pulling the whole body. Prefer `read_section` if you know the heading, `grep_in_file` if you know a pattern but not the line number.", {
579
- id: z.number().describe("File ID"),
580
- from: z.number().int().positive().describe("First line (1-indexed, inclusive)"),
581
- to: z.number().int().positive().describe("Last line (1-indexed, inclusive)"),
582
- }, async ({ id, from, to }) => {
583
- try {
584
- if (to < from)
585
- throw new Error("`to` must be >= `from`");
586
- const file = readFile(id);
587
- const lines = file.content.split("\n");
588
- const start = Math.max(0, from - 1);
589
- const end = Math.min(lines.length, to);
590
- const slice = lines.slice(start, end).join("\n");
591
- return {
592
- content: [
593
- {
594
- type: "text",
595
- text: JSON.stringify({
596
- file_id: id,
597
- path: file.path,
598
- from: start + 1,
599
- to: end,
600
- total_lines: lines.length,
601
- content: slice,
602
- size_bytes: Buffer.byteLength(slice, "utf8"),
603
- est_tokens: estimateTokensFromBuffer(Buffer.from(slice, "utf8")),
604
- }, null, 2),
605
- },
606
- ],
607
- };
608
- }
609
- catch (e) {
610
- return {
611
- isError: true,
612
- content: [{ type: "text", text: JSON.stringify({ error: e?.message ?? String(e) }, null, 2) }],
613
- };
614
- }
615
- });
616
- server.tool("files.grep", "Match a JS regex against one file's lines and return matched lines with line numbers (capped: default 100, max 500). Catches what FTS misses: URLs, hyphenated terms, code identifiers. Read-only; no side effects, auth, or rate limits. Invalid regex throws `invalid regex`. Returns `{matches, match_count, truncated}`. Use after `files.read_outline` when you know the file but need a specific reference; for cross-file regex use `files.regex_search`; for keyword/concept search use `files.search`.", {
617
- id: z.number().describe("File ID"),
618
- pattern: z.string().describe("Pattern to match. Treated as a JavaScript RegExp source."),
619
- case_insensitive: z.boolean().optional().describe("Add the 'i' flag (default false)"),
620
- max_matches: z.number().int().positive().max(500).optional().describe("Cap on returned hits (default 100)"),
621
- }, async ({ id, pattern, case_insensitive, max_matches }) => {
622
- try {
623
- let re;
624
- try {
625
- re = new RE2Class(pattern, case_insensitive ? "i" : "");
626
- }
627
- catch (e) {
628
- throw new Error(`invalid regex: ${e?.message ?? e}`);
629
- }
630
- const file = readFile(id);
631
- const lines = file.content.split("\n");
632
- const cap = max_matches ?? 100;
633
- const matches = [];
634
- for (let i = 0; i < lines.length; i++) {
635
- if (re.test(lines[i])) {
636
- matches.push({ line: i + 1, text: lines[i] });
637
- if (matches.length >= cap)
638
- break;
639
- }
640
- }
641
- return {
642
- content: [
643
- {
644
- type: "text",
645
- text: JSON.stringify({
646
- file_id: id,
647
- path: file.path,
648
- pattern,
649
- match_count: matches.length,
650
- truncated: matches.length === cap,
651
- matches,
652
- }, null, 2),
653
- },
654
- ],
655
- };
656
- }
657
- catch (e) {
658
- return {
659
- isError: true,
660
- content: [{ type: "text", text: JSON.stringify({ error: e?.message ?? String(e) }, null, 2) }],
661
- };
662
- }
663
- });
664
- server.tool("files.regex_search", "Match a JS regex against the body of every file in scope (project, KB, or all) and return per-file hits with line numbers. Slower than FTS `search` because it reads each file's content; use only when FTS misses substrings, URLs, or code identifiers. Read-only; no side effects, auth, or rate limits. Capped at 500 files / 10 hits per file by default; the response reports `files_truncated` and per-file truncation so the agent can re-scope. `project_id: null` = KB only; omit = everywhere; `kind` narrows to one content class. Invalid regex throws.", {
770
+ server.tool("files.regex_search", "Match a JS regex against file bodies. Default mode scans every file in scope (project, KB, or all) and returns per-file hits with line numbers — slower than FTS `files.search` because it reads each file's content; use only when FTS misses substrings, URLs, or code identifiers. Pass `file_id` to instead scan just that one file (catches what FTS misses within a single known file); response shape changes to `{file_id, path, pattern, match_count, truncated, matches}`. Read-only; no side effects, auth, or rate limits. Multi-file mode capped at 500 files / 10 hits per file by default (`files_truncated` reports the cap); single-file mode capped at 100 hits by default, max 500. `project_id`/`kind` are ignored when `file_id` is set. Invalid regex throws.", {
665
771
  pattern: z.string().describe("JavaScript RegExp source"),
666
- project_id: z.number().nullable().optional().describe("Scope to one project, null for KB-only, omit for everything"),
772
+ file_id: z.number().optional().describe("Scan only this file instead of every file in scope. When set, `project_id`/`kind`/`max_files`/`max_matches_per_file` are ignored in favor of `max_matches`."),
773
+ project_id: z.number().nullable().optional().describe("Scope to one project, null for KB-only, omit for everything. Ignored when `file_id` is set."),
667
774
  case_insensitive: z.boolean().optional().describe("If true, match pattern case-insensitively (RegExp 'i' flag). Default false."),
668
- max_files: z.number().int().positive().max(2000).optional().describe("Cap on files scanned (default 500)"),
669
- max_matches_per_file: z.number().int().positive().max(100).optional().describe("Per-file hit cap (default 10)"),
775
+ max_files: z.number().int().positive().max(2000).optional().describe("Cap on files scanned (default 500). Ignored when `file_id` is set."),
776
+ max_matches_per_file: z.number().int().positive().max(100).optional().describe("Per-file hit cap in multi-file mode (default 10). Ignored when `file_id` is set."),
777
+ max_matches: z.number().int().positive().max(500).optional().describe("Cap on returned hits in single-file mode (default 100). Only used when `file_id` is set."),
670
778
  kind: z.enum(["dictionary", "note", "journal", "project"]).optional()
671
- .describe("Filter by content class before scanning."),
672
- }, async ({ pattern, project_id, case_insensitive, max_files, max_matches_per_file, kind }) => {
779
+ .describe("Filter by content class before scanning. Ignored when `file_id` is set."),
780
+ }, async ({ pattern, file_id, project_id, case_insensitive, max_files, max_matches_per_file, max_matches, kind }) => {
673
781
  try {
674
782
  let re;
675
783
  try {
@@ -678,6 +786,34 @@ server.tool("files.regex_search", "Match a JS regex against the body of every fi
678
786
  catch (e) {
679
787
  throw new Error(`invalid regex: ${e?.message ?? e}`);
680
788
  }
789
+ if (file_id !== undefined) {
790
+ const file = readFile(file_id);
791
+ const lines = file.content.split("\n");
792
+ const cap = max_matches ?? 100;
793
+ const matches = [];
794
+ for (let i = 0; i < lines.length; i++) {
795
+ if (re.test(lines[i])) {
796
+ matches.push({ line: i + 1, text: lines[i] });
797
+ if (matches.length >= cap)
798
+ break;
799
+ }
800
+ }
801
+ return {
802
+ content: [
803
+ {
804
+ type: "text",
805
+ text: JSON.stringify({
806
+ file_id,
807
+ path: file.path,
808
+ pattern,
809
+ match_count: matches.length,
810
+ truncated: matches.length === cap,
811
+ matches,
812
+ }, null, 2),
813
+ },
814
+ ],
815
+ };
816
+ }
681
817
  const fileCap = max_files ?? 500;
682
818
  const perFileCap = max_matches_per_file ?? 10;
683
819
  const db = getDatabase();
@@ -745,24 +881,53 @@ server.tool("files.regex_search", "Match a JS regex against the body of every fi
745
881
  };
746
882
  }
747
883
  });
748
- server.tool("files.update", "Update the entire content of an existing file by its ID. This replaces the file's content on disk and triggers an FTS5 re-index. Returns the updated file metadata including new estimated token counts. Operates locally with no external auth or rate limits. If you only need to modify a single section without replacing the entire file, use 'files.update_section' instead to save context budget. Parameters: 'id' must be a valid integer file ID. 'content' is the complete markdown string that will replace the file.", {
884
+ server.tool("files.update", "Rewrite a file. Default = full-body replacement: `content` becomes the entire file, triggering disk write + FTS5 re-index. Pass `section` to instead rewrite ONLY that heading's body (case-insensitive exact-string after trim; the heading line itself is preserved, siblings untouched) — saves context budget vs resending the whole file. Throws if `section` is set but the heading doesn't exist (this mode will NOT create a new section — append the section text via a full-body update first). Operates locally with no external auth or rate limits. Returns the updated file metadata including new estimated token counts.", {
749
885
  id: z.number().describe("File ID"),
750
- content: z.string().describe("New content"),
751
- }, async ({ id, content }) => {
752
- const result = await updateFile(id, content, dataDir);
753
- return {
754
- content: [{ type: "text", text: JSON.stringify(annotateTokens(result), null, 2) }],
755
- };
886
+ content: z.string().describe("New content. With `section` set, this replaces just that heading's body; otherwise it becomes the entire file body."),
887
+ section: z.string().optional().describe("Case-insensitive exact-string heading. When set, only this heading's body is rewritten instead of the whole file."),
888
+ }, async ({ id, content, section }) => {
889
+ try {
890
+ let newBody = content;
891
+ if (section !== undefined) {
892
+ const file = readFile(id);
893
+ newBody = replaceSection(file.content, section, content);
894
+ }
895
+ const result = await updateFile(id, newBody, dataDir);
896
+ return {
897
+ content: [{ type: "text", text: JSON.stringify(annotateTokens(result), null, 2) }],
898
+ };
899
+ }
900
+ catch (e) {
901
+ return {
902
+ isError: true,
903
+ content: [{ type: "text", text: JSON.stringify({ error: e?.message ?? String(e) }, null, 2) }],
904
+ };
905
+ }
756
906
  });
757
- server.tool("files.delete", "DESTRUCTIVE. Permanently delete one file by ID. KB files are unlinked from disk AND removed from the FTS5 index; project reference files only have their index entry removed (the file on disk is left alone so the watcher does not fight your editor). Not idempotent — deleting an unknown ID throws. No external auth or rate limits. Returns `{success: true}`. Use only when the file is truly obsolete; to deprioritise without losing data, untag (`tags.remove`) or unfavorite (`tags.set_favorite`) instead. Bulk variant: `files.delete_many`.", {
758
- id: z.number().describe("File ID"),
759
- }, async ({ id }) => {
760
- await deleteFile(id, dataDir);
907
+ server.tool("files.delete", "DESTRUCTIVE. Permanently delete one or more files by ID (up to 500 per call). Pass a single-element `ids` array for the one-file case. KB files are unlinked from disk AND removed from the FTS5 index; project reference files only have their index entry removed (the file on disk is left alone so the watcher does not fight your editor). Not idempotent — deleting an unknown ID surfaces as a per-item error. No external auth or rate limits. Per-ID failures are isolated to `errors[]` and the rest of the batch still commits — partial success is the norm, always inspect `error_count`. Returns `{deleted_count, error_count, deleted, errors}`. Use only when the file is truly obsolete; to deprioritise without losing data, untag (`tags.remove`) or unfavorite (`tags.set_favorite`) instead. To preview the set before deleting, run `files.list` with the same filter and confirm the IDs.", {
908
+ ids: z.array(z.number()).min(1).max(500).describe("File IDs to delete. Single-element array = one-file case. Max 500 per call."),
909
+ }, async ({ ids }) => {
910
+ const deleted = [];
911
+ const errors = [];
912
+ for (const id of ids) {
913
+ try {
914
+ await deleteFile(id, dataDir);
915
+ deleted.push(id);
916
+ }
917
+ catch (e) {
918
+ errors.push({ id, error: e?.message ?? String(e) });
919
+ }
920
+ }
761
921
  return {
762
- content: [{ type: "text", text: JSON.stringify({ success: true }, null, 2) }],
922
+ content: [
923
+ {
924
+ type: "text",
925
+ text: JSON.stringify({ deleted_count: deleted.length, error_count: errors.length, deleted, errors }, null, 2),
926
+ },
927
+ ],
763
928
  };
764
929
  });
765
- server.tool("files.list", "List file metadata with optional filters (project_id, tag, favorite, folder, untagged, kind) and pagination. Read-only; no side effects, auth, or rate limits. Each row is annotated with tags, est_tokens, size_bytes, and content_class; the response includes `total_est_tokens` so you can budget before reading bodies. `project_id: null` returns ONLY Knowledge Base files; omit the field to span everything; `kind` narrows to one content class. Use to browse known structure; for keyword/content lookup use `search`; for a denser whole-vault dump use `project_map`.", {
930
+ server.tool("files.list", "List file metadata with optional filters (project_id, tag, favorite, folder, untagged, kind) and pagination. Read-only; no side effects, auth, or rate limits. Each row is annotated with tags, est_tokens, size_bytes, and content_class; the response includes `total_est_tokens` so you can budget before reading bodies. `project_id: null` returns ONLY Knowledge Base files; omit the field to span everything; `kind` narrows to one content class. Use to browse known structure; for keyword/content lookup use `files.search`; for a denser whole-vault dump use `projects.map`.", {
766
931
  project_id: z.number().nullable().optional().describe("Filter by project ID. Pass null to list ONLY Knowledge Base files (project_id IS NULL)."),
767
932
  tag: z.string().optional().describe("Filter by tag name"),
768
933
  favorite: z.boolean().optional().describe("Filter by favorite status"),
@@ -797,14 +962,17 @@ server.tool("files.list", "List file metadata with optional filters (project_id,
797
962
  content: [{ type: "text", text: JSON.stringify({ files: annotated, total_est_tokens }, null, 2) }],
798
963
  };
799
964
  });
800
- server.tool("files.search", "Full-text (SQLite FTS5) keyword search across files. Returns ranked matches with inline match_excerpt and title_highlight (no follow-up `read_file` needed for snippets) plus tags, est_tokens, size_bytes, content_class, and aggregate `total_est_tokens`. Read-only; no side effects, auth, or rate limits. Ordering: dictionary hits sort above everything else for the same query (dictionary-wins on conflict), then BM25 rank. FTS is tokenised: it WILL miss URLs, hyphenated terms, and partial substrings — fall back to `files.regex_search` for those. `project_id: null` searches only the KB; omit the field to span everything; `tags[]` requires ALL listed tags to match; `kind` narrows to one content class. For prompt-ready bundled bodies use `files.bundle_search`.", {
965
+ server.tool("files.search", "Full-text (SQLite FTS5) keyword search across files. Default mode returns ranked matches with inline match_excerpt and title_highlight (no follow-up `files.read` needed for snippets) plus tags, est_tokens, size_bytes, content_class, and aggregate `total_est_tokens`. Pass `include_bodies: true` to instead get a single prompt-ready bundle: matched bodies concatenated into XML `<document>` blocks or markdown headers + fences (see `format`/`max_tokens`), capped at the token budget — files are added in rank order until the next would exceed it, the rest going to `meta.skipped[]`. Use `include_bodies` instead of `files.search` + N×`files.read` when you need several related files as one context blob. Read-only; no side effects, auth, or rate limits. Ordering: dictionary hits sort above everything else for the same query (dictionary-wins on conflict), then BM25 rank. FTS is tokenised: it WILL miss URLs, hyphenated terms, and partial substrings — fall back to `files.regex_search` for those. `project_id: null` searches only the KB; omit the field to span everything; `tags[]` requires ALL listed tags to match; `kind` narrows to one content class.", {
801
966
  query: z.string().describe("Search query"),
802
967
  project_id: z.number().nullable().optional().describe("Filter by project ID. Pass null to search ONLY Knowledge Base files."),
803
968
  tags: z.array(z.string()).optional().describe("Filter by tags (all must match)"),
804
969
  favorite: z.boolean().optional().describe("Filter by favorite status"),
805
970
  kind: z.enum(["dictionary", "note", "journal", "project"]).optional()
806
971
  .describe("Filter by content class. dictionary = authoritative KB (system IDs, mappings, glossaries), note = informational KB, journal = time-log, project = project file. Omit to see all classes with dictionary-first ordering."),
807
- }, async ({ query, project_id, tags, favorite, kind }) => {
972
+ include_bodies: z.boolean().optional().describe("If true, return a single prompt-ready bundle of matched bodies instead of a match list. Response shape changes to `{bundle, meta: {included, skipped, ...}}`. Default false."),
973
+ format: z.enum(["xml", "markdown"]).optional().describe("Bundle format when `include_bodies` is true. xml = Anthropic-recommended <document> tags (default); markdown = ## headers + fenced blocks. Ignored otherwise."),
974
+ max_tokens: z.number().int().positive().optional().describe("Token budget when `include_bodies` is true (default 50000). Files added in rank order until the next would exceed; remainder go to `meta.skipped[]`. Ignored otherwise."),
975
+ }, async ({ query, project_id, tags, favorite, kind, include_bodies, format, max_tokens }) => {
808
976
  const filters = { query };
809
977
  if (project_id !== undefined)
810
978
  filters.project_id = project_id;
@@ -814,6 +982,21 @@ server.tool("files.search", "Full-text (SQLite FTS5) keyword search across files
814
982
  filters.favorite = favorite;
815
983
  if (kind !== undefined)
816
984
  filters.content_class = kind;
985
+ if (include_bodies) {
986
+ let bundleResult;
987
+ try {
988
+ bundleResult = await bundleSearch(filters, { format: format ?? "xml", max_tokens: max_tokens ?? 50000 });
989
+ }
990
+ catch (e) {
991
+ if (e instanceof FtsQueryError) {
992
+ return { isError: true, content: [{ type: "text", text: e.message }] };
993
+ }
994
+ throw e;
995
+ }
996
+ return {
997
+ content: [{ type: "text", text: JSON.stringify(bundleResult, null, 2) }],
998
+ };
999
+ }
817
1000
  let result;
818
1001
  try {
819
1002
  result = search(filters);
@@ -830,42 +1013,7 @@ server.tool("files.search", "Full-text (SQLite FTS5) keyword search across files
830
1013
  content: [{ type: "text", text: JSON.stringify({ matches: annotated, total_est_tokens }, null, 2) }],
831
1014
  };
832
1015
  });
833
- server.tool("files.bundle_search", "Run an FTS search and concatenate matched bodies into a single prompt-ready bundle (XML `<document>` blocks or markdown headers + fences) capped at `max_tokens`. Files are added in rank order (dictionary-wins first, then BM25) until the next would exceed the budget; the rest go to `skipped[]`. Read-only; no side effects, auth, or rate limits. Use instead of `files.search` + N×`files.read` when you need several related files as one context blob. Defaults: format=xml, max_tokens=50000. `project_id: null` = KB only; `tags[]` requires ALL to match; `kind` narrows to one content class.", {
834
- query: z.string().describe("Full-text search query"),
835
- project_id: z.number().nullable().optional().describe("Filter by project ID. Pass null to bundle ONLY Knowledge Base files."),
836
- tags: z.array(z.string()).optional().describe("Filter by tags (all must match)"),
837
- favorite: z.boolean().optional().describe("Filter by favorite status"),
838
- format: z.enum(["xml", "markdown"]).default("xml")
839
- .describe("Bundle format. xml = Anthropic-recommended <document> tags; markdown = ## headers + fenced blocks"),
840
- max_tokens: z.number().int().positive().default(50000)
841
- .describe("Token budget. Files added in rank order until the next would exceed; remainder go to skipped[]"),
842
- kind: z.enum(["dictionary", "note", "journal", "project"]).optional()
843
- .describe("Filter by content class. dictionary = authoritative KB, note = informational KB, journal = time-log, project = project file."),
844
- }, async ({ query, project_id, tags, favorite, format, max_tokens, kind }) => {
845
- const filters = { query };
846
- if (project_id !== undefined)
847
- filters.project_id = project_id;
848
- if (tags !== undefined)
849
- filters.tags = tags;
850
- if (favorite !== undefined)
851
- filters.favorite = favorite;
852
- if (kind !== undefined)
853
- filters.content_class = kind;
854
- let result;
855
- try {
856
- result = await bundleSearch(filters, { format, max_tokens });
857
- }
858
- catch (e) {
859
- if (e instanceof FtsQueryError) {
860
- return { isError: true, content: [{ type: "text", text: e.message }] };
861
- }
862
- throw e;
863
- }
864
- return {
865
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
866
- };
867
- });
868
- server.tool("tags.add", "Append tags to ONE file. Additive — existing tags are preserved; re-adding an existing tag is a no-op (idempotent per tag). New tag names auto-create rows in the global `tags` table. Persists to local SQLite. No external auth or rate limits. Returns `{success: true}`; throws if file_id is unknown. Use to label a single file. To tag every file matching a query in one call use `tag_search_results`; to remove tags use `remove_tags`.", {
1016
+ server.tool("tags.add", "Append tags to ONE file. Additive — existing tags are preserved; re-adding an existing tag is a no-op (idempotent per tag). New tag names auto-create rows in the global `tags` table. Persists to local SQLite. No external auth or rate limits. Returns `{success: true}`; throws if file_id is unknown. Use to label a single file. To tag every file matching a query in one call use `tags.search`; to remove tags use `tags.remove`.", {
869
1017
  file_id: z.number().describe("File ID"),
870
1018
  tags: z.array(z.string()).describe("Array of tag names to add"),
871
1019
  }, async ({ file_id, tags }) => {
@@ -874,7 +1022,7 @@ server.tool("tags.add", "Append tags to ONE file. Additive — existing tags are
874
1022
  content: [{ type: "text", text: JSON.stringify({ success: true }, null, 2) }],
875
1023
  };
876
1024
  });
877
- server.tool("tags.remove", "Detach one or more tag IDs from ONE file. Destructive on the link only — does NOT delete the file or the global tag definition (orphan tags survive in `list_tags`). Idempotent: removing an already-absent tag is a no-op. No external auth or rate limits. Returns `{success: true}`. Note: takes tag IDs (integers), not names — fetch them via `list_tags`. To remove ALL tags from many files via a query, see `tag_search_results` (additive only) — there is no bulk-untag-by-query tool.", {
1025
+ server.tool("tags.remove", "Detach one or more tag IDs from ONE file. Destructive on the link only — does NOT delete the file or the global tag definition (orphan tags survive in `tags.list`). Idempotent: removing an already-absent tag is a no-op. No external auth or rate limits. Returns `{success: true}`. Note: takes tag IDs (integers), not names — fetch them via `tags.list`. To remove ALL tags from many files via a query, see `tags.search` (additive only) — there is no bulk-untag-by-query tool.", {
878
1026
  file_id: z.number().describe("File ID"),
879
1027
  tag_ids: z.array(z.number()).describe("Array of tag IDs to remove"),
880
1028
  }, async ({ file_id, tag_ids }) => {
@@ -883,7 +1031,7 @@ server.tool("tags.remove", "Detach one or more tag IDs from ONE file. Destructiv
883
1031
  content: [{ type: "text", text: JSON.stringify({ success: true }, null, 2) }],
884
1032
  };
885
1033
  });
886
- server.tool("tags.set_favorite", "Set or clear the favorite flag on one file (idempotent — re-setting the same value is a no-op; not a toggle, you pass the desired state). Persists to local SQLite. No external auth or rate limits. Returns `{success: true}`. Use to curate quick-access pins; `list_files`/`search`/`bundle_search` accept `favorite: true` to filter to the pinned set.", {
1034
+ server.tool("tags.set_favorite", "Set or clear the favorite flag on one file (idempotent — re-setting the same value is a no-op; not a toggle, you pass the desired state). Persists to local SQLite. No external auth or rate limits. Returns `{success: true}`. Use to curate quick-access pins; `files.list` / `files.search` accept `favorite: true` to filter to the pinned set.", {
887
1035
  file_id: z.number().describe("File ID"),
888
1036
  favorite: z.boolean().describe("Favorite status"),
889
1037
  }, async ({ file_id, favorite }) => {
@@ -892,13 +1040,13 @@ server.tool("tags.set_favorite", "Set or clear the favorite flag on one file (id
892
1040
  content: [{ type: "text", text: JSON.stringify({ success: true }, null, 2) }],
893
1041
  };
894
1042
  });
895
- server.tool("tags.list", "List every tag in the global SQLite database with id, name, and applied count. Read-only; no side effects, auth, or rate limits. Returns the entire taxonomy (not paginated). Use to discover existing labels before tagging (so you reuse rather than fork) or to find tag IDs to feed into `remove_tags`. For tags on a specific file, use `describe_file`.", {}, async () => {
1043
+ server.tool("tags.list", "List every tag in the global SQLite database with id, name, and applied count. Read-only; no side effects, auth, or rate limits. Returns the entire taxonomy (not paginated). Use to discover existing labels before tagging (so you reuse rather than fork) or to find tag IDs to feed into `tags.remove`. For tags on a specific file, use `files.describe`.", {}, async () => {
896
1044
  const result = listTags();
897
1045
  return {
898
1046
  content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
899
1047
  };
900
1048
  });
901
- server.tool("projects.list", "List every registered project with id, name, absolute path, and a derived `has_hands` flag (true when the path exists on disk AND contains a `kontexta.json`). Read-only; no side effects, auth, or rate limits. Use to find the project_id to pass to scoped tools (`search`, `list_files`, `commit_backup`, `refresh_index`, etc.). To register a new project use `register_project`; to inspect its Hands tools use `list_hands`.", {}, async () => {
1049
+ server.tool("projects.list", "List every registered project with id, name, absolute path, and a derived `has_hands` flag (true when the path exists on disk AND contains a `kontexta.json`). Read-only; no side effects, auth, or rate limits. Use to find the project_id to pass to scoped tools (`files.search`, `files.list`, `admin.commit_backup`, `projects.refresh_index`, etc.). To register a new project use `projects.register`; to inspect its Hands tools use `hands.list`.", {}, async () => {
902
1050
  const result = listProjects();
903
1051
  const augmented = result.map((p) => {
904
1052
  const has_hands = !!(p.path && existsSync(p.path) && existsSync(`${p.path}/kontexta.json`));
@@ -1021,6 +1169,7 @@ ERROR CONDITIONS: Returns isError=true if path is missing or unresolvable. Scan
1021
1169
  },
1022
1170
  prompt: "Scaffold an AI agent instructions file now? Tell me which agent you use (claude-code, codex, gemini, antigravity, cursor, continue, aider, cline, or copilot) and I'll create the right file (e.g. CLAUDE.md) with the kontexta workflow rules pre-installed, so your agent picks them up on its next session.",
1023
1171
  };
1172
+ const hooksBlock = currentHooksBlock(pkgVersion);
1024
1173
  const content = [
1025
1174
  {
1026
1175
  type: "text",
@@ -1032,6 +1181,7 @@ ERROR CONDITIONS: Returns isError=true if path is missing or unresolvable. Scan
1032
1181
  hands: handsSummary,
1033
1182
  recommendation,
1034
1183
  rules_status: ruleStatuses,
1184
+ ...(hooksBlock ? { hooks: hooksBlock } : {}),
1035
1185
  ...(warnings.length ? { warnings } : {}),
1036
1186
  }, null, 2),
1037
1187
  },
@@ -1042,6 +1192,8 @@ ERROR CONDITIONS: Returns isError=true if path is missing or unresolvable. Scan
1042
1192
  text: `\nPROMPT: ${recommendation.prompt}`,
1043
1193
  });
1044
1194
  }
1195
+ if (hooksBlock?.prompt)
1196
+ content.push({ type: "text", text: `\nPROMPT: ${hooksBlock.prompt}` });
1045
1197
  return { content };
1046
1198
  }
1047
1199
  catch (e) {
@@ -1061,13 +1213,16 @@ PARAMETERS:
1061
1213
  - files: string[], optional. Paths relative to project root. For update mode, defaults to recommendation.target_files. Ignored when files is empty AND target_agent is provided (create mode).
1062
1214
  - target_agent: enum claude-code | codex | gemini | cursor | continue | aider | cline | copilot | generic. Required when files is empty AND no context file currently exists. Picks the canonical filename and the starter scaffold.
1063
1215
 
1064
- RETURNS: { written: [{ path, action: created|updated|skipped, version }], skipped: [{ path, reason }] }`, {
1216
+ - hooks: boolean, optional. With target_agent set, also enables that agent and installs its conversation-capture hooks (npx/source installs) or returns the host docker command (Docker). Ask the user before setting it.
1217
+
1218
+ RETURNS: { written: [{ path, action: created|updated|skipped, version }], skipped: [{ path, reason }], hooks_install?: { agent, mode, enabled, outcome?, docker_command?, note?, error? }, hooks?: { install_mode, alerts, prompt } }`, {
1065
1219
  project_id: z.number().describe("Project ID returned from register_project"),
1066
1220
  confirm: z.boolean().describe("MANDATORY: Set to true only after obtaining explicit user consent to modify context files."),
1067
1221
  files: z.array(z.string()).optional().describe("Project-relative paths to update; defaults to detected context files"),
1068
1222
  target_agent: z.enum(["claude-code", "codex", "gemini", "antigravity", "cursor", "continue", "aider", "cline", "copilot", "generic"]).optional()
1069
1223
  .describe("Required when files is empty AND no context file exists. Picks the canonical filename + scaffold."),
1070
- }, async ({ project_id, confirm, files, target_agent }) => {
1224
+ hooks: z.boolean().optional().describe("With target_agent, also enable that agent and install its conversation-capture hooks (npx/source) or return the host docker command. Ask the user first."),
1225
+ }, async ({ project_id, confirm, files, target_agent, hooks }) => {
1071
1226
  try {
1072
1227
  if (confirm !== true) {
1073
1228
  return {
@@ -1098,14 +1253,27 @@ RETURNS: { written: [{ path, action: created|updated|skipped, version }], skippe
1098
1253
  content: [{ type: "text", text: JSON.stringify({ error: "target_agent is required when files is empty (create mode)" }, null, 2) }],
1099
1254
  };
1100
1255
  }
1256
+ if (hooks === true && !target_agent) {
1257
+ return {
1258
+ isError: true,
1259
+ content: [{ type: "text", text: JSON.stringify({ error: "target_agent is required when hooks is true" }, null, 2) }],
1260
+ };
1261
+ }
1101
1262
  const result = syncAgentRules({
1102
1263
  projectPath: project.path,
1103
1264
  project: { name: project.name, description: project.description },
1104
1265
  files: targetFiles,
1105
1266
  targetAgent: target_agent,
1106
1267
  });
1268
+ let hooksInstall;
1269
+ if (hooks === true)
1270
+ hooksInstall = enableAndInstallHooks(target_agent, pkgVersion);
1271
+ const hooksBlock = currentHooksBlock(pkgVersion);
1107
1272
  return {
1108
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
1273
+ content: [{
1274
+ type: "text",
1275
+ text: JSON.stringify({ ...result, ...(hooksInstall ? { hooks_install: hooksInstall } : {}), ...(hooksBlock ? { hooks: hooksBlock } : {}) }, null, 2),
1276
+ }],
1109
1277
  };
1110
1278
  }
1111
1279
  catch (e) {
@@ -1329,7 +1497,7 @@ function repoDirForFile(file) {
1329
1497
  }
1330
1498
  return dataDir;
1331
1499
  }
1332
- server.tool("files.get_history", "Return the git commit history for one file (newest first), each entry with hash, message, date, and author. Reads the file's owning repo: the project's git repo for project files, the KB backup repo for KB files. Read-only; no side effects, auth, or rate limits. Returns `{file_id, path, history}`; an empty array means the file has not been committed yet. Use to understand a file's evolution before editing or restoring. Pair with `get_diff` to see exact line changes; use `restore_file` to roll back.", {
1500
+ server.tool("files.get_history", "Return the git commit history for one file (newest first), each entry with hash, message, date, and author. Reads the file's owning repo: the project's git repo for project files, the KB backup repo for KB files. Read-only; no side effects, auth, or rate limits. Returns `{file_id, path, history}`; an empty array means the file has not been committed yet. Use to understand a file's evolution before editing or restoring. Pair with `files.get_diff` to see exact line changes; use `files.restore` to roll back.", {
1333
1501
  file_id: z.number().describe("ID of the file"),
1334
1502
  }, async ({ file_id }) => {
1335
1503
  const file = readFile(file_id);
@@ -1343,7 +1511,7 @@ server.tool("files.get_history", "Return the git commit history for one file (ne
1343
1511
  ],
1344
1512
  };
1345
1513
  });
1346
- server.tool("files.get_diff", "Return the unified diff of one file between two commit hashes (typically obtained from `get_history` for the same file). Read-only; no side effects, auth, or rate limits. Order matters — `commit_a` is treated as the earlier side; reversing the args inverts the diff. Throws if either hash is unknown to the file's repo. Use after `get_history` to see WHAT changed, not just THAT it changed.", {
1514
+ server.tool("files.get_diff", "Return the unified diff of one file between two commit hashes (typically obtained from `files.get_history` for the same file). Read-only; no side effects, auth, or rate limits. Order matters — `commit_a` is treated as the earlier side; reversing the args inverts the diff. Throws if either hash is unknown to the file's repo. Use after `files.get_history` to see WHAT changed, not just THAT it changed.", {
1347
1515
  file_id: z.number().describe("ID of the file"),
1348
1516
  commit_a: z.string().describe("Earlier commit hash (from get_history)"),
1349
1517
  commit_b: z.string().describe("Later commit hash (from get_history)"),
@@ -1359,7 +1527,7 @@ server.tool("files.get_diff", "Return the unified diff of one file between two c
1359
1527
  ],
1360
1528
  };
1361
1529
  });
1362
- server.tool("files.restore", "DESTRUCTIVE. Overwrite a file's current on-disk content with the version recorded at a specific git commit, then re-index FTS. The hash MUST come from `get_history` for THIS file (foreign hashes throw). The current uncommitted content is lost unless it was already committed elsewhere. The file watcher may also pick up the change before this returns. No external auth or rate limits. Returns `{file_id, path, hash, success, message}`. Use only to undo accidental edits or recover a known-good version.", {
1530
+ server.tool("files.restore", "DESTRUCTIVE. Overwrite a file's current on-disk content with the version recorded at a specific git commit, then re-index FTS. The hash MUST come from `files.get_history` for THIS file (foreign hashes throw). The current uncommitted content is lost unless it was already committed elsewhere. The file watcher may also pick up the change before this returns. No external auth or rate limits. Returns `{file_id, path, hash, success, message}`. Use only to undo accidental edits or recover a known-good version.", {
1363
1531
  file_id: z.number().describe("ID of the file"),
1364
1532
  hash: z.string().describe("Commit hash to restore from (from get_history)"),
1365
1533
  }, async ({ file_id, hash }) => {
@@ -1388,7 +1556,7 @@ server.tool("files.restore", "DESTRUCTIVE. Overwrite a file's current on-disk co
1388
1556
  };
1389
1557
  }
1390
1558
  });
1391
- server.tool("files.read_outline", "Return a flat list of markdown headings for one file (level, text, line, byteStart, byteEnd). Read-only; no side effects, auth, or rate limits. Use as a cheap probe before `read_section` or `update_file_section` so you don't spend tokens on the full body just to learn what sections exist. Empty outline means the file has no markdown headings (it may still have content — fall back to `read_file` or `read_file_lines`).", {
1559
+ server.tool("files.read_outline", "Return a flat list of markdown headings for one file (level, text, line, byteStart, byteEnd). Read-only; no side effects, auth, or rate limits. Use as a cheap probe before `files.read({ id, section })` or `files.update({ file_id, section, content })` so you don't spend tokens on the full body just to learn what sections exist. Empty outline means the file has no markdown headings (it may still have content — fall back to `files.read` in full or `files.read({ id, lines })`).", {
1392
1560
  file_id: z.number().describe("File ID"),
1393
1561
  }, async ({ file_id }) => {
1394
1562
  try {
@@ -1416,66 +1584,6 @@ server.tool("files.read_outline", "Return a flat list of markdown headings for o
1416
1584
  };
1417
1585
  }
1418
1586
  });
1419
- server.tool("files.read_section", "Return the body of ONE heading (the heading line itself is excluded) plus level, line, size_bytes, and est_tokens. Heading match is case-insensitive but exact-string after trim — fuzzy / partial matches do NOT resolve. Returns isError if the heading is absent. Read-only; no side effects, auth, or rate limits. Pair with `read_file_outline` when you are unsure which headings exist; for non-heading line ranges use `read_file_lines`.", {
1420
- file_id: z.number().describe("File ID"),
1421
- heading: z.string().describe("Heading text to extract (case-insensitive)"),
1422
- }, async ({ file_id, heading }) => {
1423
- try {
1424
- const file = readFile(file_id);
1425
- const node = findSection(file.content, heading);
1426
- if (!node) {
1427
- return {
1428
- isError: true,
1429
- content: [{ type: "text", text: JSON.stringify({ error: `Section not found: ${heading}` }, null, 2) }],
1430
- };
1431
- }
1432
- const buf = Buffer.from(file.content, "utf8");
1433
- const body = buf.subarray(node.contentStart, node.contentEnd).toString("utf8");
1434
- return {
1435
- content: [
1436
- {
1437
- type: "text",
1438
- text: JSON.stringify({
1439
- file_id,
1440
- path: file.path,
1441
- heading: node.text,
1442
- level: node.level,
1443
- line: node.line,
1444
- content: body,
1445
- size_bytes: Buffer.byteLength(body, "utf8"),
1446
- est_tokens: estimateTokensFromBuffer(Buffer.from(body, "utf8")),
1447
- }, null, 2),
1448
- },
1449
- ],
1450
- };
1451
- }
1452
- catch (e) {
1453
- return {
1454
- isError: true,
1455
- content: [{ type: "text", text: JSON.stringify({ error: e?.message ?? String(e) }, null, 2) }],
1456
- };
1457
- }
1458
- });
1459
- server.tool("files.update_section", "Surgical write — replace the body of ONE heading without touching siblings. The heading line itself is preserved verbatim; only its body is rewritten. Persists via the same path as `update_file` (writes to disk → FTS reindex → git commit). Throws if the heading does not exist (this tool will NOT create a new section — append the section text via `update_file` first). Heading match is case-insensitive exact-string. No external auth or rate limits. Returns the updated file metadata. Use to make targeted edits without re-sending the whole body; for full-file replacement use `update_file`.", {
1460
- file_id: z.number().describe("File ID"),
1461
- heading: z.string().describe("Heading whose body to replace (case-insensitive)"),
1462
- content: z.string().describe("New body content (heading line is preserved automatically)"),
1463
- }, async ({ file_id, heading, content }) => {
1464
- try {
1465
- const file = readFile(file_id);
1466
- const updated = replaceSection(file.content, heading, content);
1467
- const result = await updateFile(file_id, updated, dataDir);
1468
- return {
1469
- content: [{ type: "text", text: JSON.stringify(annotateTokens(result), null, 2) }],
1470
- };
1471
- }
1472
- catch (e) {
1473
- return {
1474
- isError: true,
1475
- content: [{ type: "text", text: JSON.stringify({ error: e?.message ?? String(e) }, null, 2) }],
1476
- };
1477
- }
1478
- });
1479
1587
  function resolveFolderBase(projectId) {
1480
1588
  if (projectId === undefined || projectId === null) {
1481
1589
  return join(dataDir, "knowledge");
@@ -1501,7 +1609,7 @@ function validateFolderName(name) {
1501
1609
  throw new Error("name must not contain '..' segments");
1502
1610
  }
1503
1611
  }
1504
- server.tool("folders.list", "List folder paths under a project root (or the Knowledge Base when `project_id` is null/omitted). Returns `{folders: string[], base_path}` where `folders` are RELATIVE to `base_path`. Read-only; no side effects, auth, or rate limits. Throws if `project_id` references an unknown project. Use to discover where to drop a new file via `create_file`'s `folder` argument or to navigate vault structure; to actually create one use `create_folder`.", {
1612
+ server.tool("folders.list", "List folder paths under a project root (or the Knowledge Base when `project_id` is null/omitted). Returns `{folders: string[], base_path}` where `folders` are RELATIVE to `base_path`. Read-only; no side effects, auth, or rate limits. Throws if `project_id` references an unknown project. Use to discover where to drop a new file via `files.create`'s `folder` argument or to navigate vault structure; to actually create one use `folders.create`.", {
1505
1613
  project_id: z.number().nullable().optional().describe("Project ID. Pass null or omit to list KB folders."),
1506
1614
  }, async ({ project_id }) => {
1507
1615
  try {
@@ -1538,7 +1646,7 @@ server.tool("folders.create", "Create a folder under a project root or the KB. I
1538
1646
  };
1539
1647
  }
1540
1648
  });
1541
- server.tool("folders.delete", "DESTRUCTIVE — recursively delete a folder under the KB AND every file inside it (disk + FTS rows). REFUSES (returns isError) when `project_id` is supplied: deleting inside a registered project would race the file watcher and re-ingest the contents — remove project content via your editor instead. Same name validation as `create_folder`. Not recoverable from Kontexta after the call (only the git backup, if configured, retains it). No external auth or rate limits. Returns `{success: true}`.", {
1649
+ server.tool("folders.delete", "DESTRUCTIVE — recursively delete a folder under the KB AND every file inside it (disk + FTS rows). REFUSES (returns isError) when `project_id` is supplied: deleting inside a registered project would race the file watcher and re-ingest the contents — remove project content via your editor instead. Same name validation as `folders.create`. Not recoverable from Kontexta after the call (only the git backup, if configured, retains it). No external auth or rate limits. Returns `{success: true}`.", {
1542
1650
  project_id: z.number().nullable().optional().describe("Project ID. Pass null or omit to delete from the KB. Project IDs are rejected."),
1543
1651
  name: z.string().describe("Folder name (relative)"),
1544
1652
  }, async ({ project_id, name }) => {
@@ -1695,84 +1803,6 @@ server.tool("files.find_related", "Find other files sharing tags with the given
1695
1803
  ],
1696
1804
  };
1697
1805
  });
1698
- server.tool("files.create_many", "Batch variant of `files.create` — create up to 200 markdown, mermaid, or HTML files in one call. Each item follows the same rules: `project_id` required if `destination` is `project`/`kontexta`; `kind` ('dictionary' or 'note') required if `destination` is `knowledge`. SIDE EFFECTS: writes new files to disk and inserts FTS5 rows; missing folders are mkdir'd. Per-item failures are isolated to `errors[]` and the rest of the batch still commits — partial success is the norm, always inspect `error_count`. No external auth or rate limits. Returns `{created_count, error_count, created, errors}`. Use for bulk ingestion; for >200 items, page yourself. Pass format='mmd' on an item to create a Mermaid diagram file (.mmd) or 'html' for HTML reports; defaults to 'md'.", {
1699
- files: z
1700
- .array(z.object({
1701
- title: z.string().describe("File title."),
1702
- content: z.string().describe("File body content (markdown, mermaid, or HTML depending on format)."),
1703
- destination: z.enum(["knowledge", "project", "kontexta"]).describe("Storage destination: 'knowledge' for KB, 'project' for a project, 'kontexta' for app-internal."),
1704
- project_id: z.number().optional().describe("Project ID — required when destination is 'project' or 'kontexta'."),
1705
- folder: z.string().optional().describe("Relative folder path within the destination (e.g. 'notes/daily')."),
1706
- tags: z.array(z.string()).optional().describe("Tags to apply to this file."),
1707
- format: z.enum(["md", "mmd", "html"]).optional().describe("File format: 'md' (default), 'mmd' (Mermaid diagram), or 'html' (report)."),
1708
- kind: z.enum(["dictionary", "note"]).optional()
1709
- .describe("REQUIRED per-item for destination='knowledge'. See files.create for the dictionary/note rubric."),
1710
- }))
1711
- .min(1)
1712
- .max(200)
1713
- .describe("Files to create (max 200 per call)"),
1714
- }, async ({ files }) => {
1715
- const created = [];
1716
- const errors = [];
1717
- for (let i = 0; i < files.length; i++) {
1718
- const f = files[i];
1719
- try {
1720
- const resolved = resolveKindFolder({ destination: f.destination, folder: f.folder, kind: f.kind });
1721
- if ("error" in resolved) {
1722
- errors.push({ index: i, title: f.title, error: resolved.error });
1723
- continue;
1724
- }
1725
- const result = await createFile({
1726
- title: f.title,
1727
- content: f.content,
1728
- destination: f.destination,
1729
- projectId: f.project_id,
1730
- folder: resolved.folder,
1731
- tags: f.tags,
1732
- dataDir,
1733
- format: f.format,
1734
- });
1735
- const payload = annotateTokens(result);
1736
- if (resolved.warning)
1737
- payload.warning = resolved.warning;
1738
- created.push(payload);
1739
- }
1740
- catch (e) {
1741
- errors.push({ index: i, title: f.title, error: e?.message ?? String(e) });
1742
- }
1743
- }
1744
- return {
1745
- content: [
1746
- {
1747
- type: "text",
1748
- text: JSON.stringify({ created_count: created.length, error_count: errors.length, created, errors }, null, 2),
1749
- },
1750
- ],
1751
- };
1752
- });
1753
- server.tool("files.delete_many", "DESTRUCTIVE batch — delete up to 500 files by ID in one call. Same physical-deletion rules as `files.delete` (KB files unlinked from disk; project reference files only de-indexed). Per-ID failures isolated to `errors[]`; the batch keeps going — partial success is the norm. Not idempotent — unknown IDs surface as per-item errors. No external auth or rate limits. Returns `{deleted_count, error_count, deleted, errors}`. To preview the set before deleting, run `files.list` with the same filter and confirm the IDs.", {
1754
- ids: z.array(z.number()).min(1).max(500).describe("File IDs to delete (max 500 per call)"),
1755
- }, async ({ ids }) => {
1756
- const deleted = [];
1757
- const errors = [];
1758
- for (const id of ids) {
1759
- try {
1760
- await deleteFile(id, dataDir);
1761
- deleted.push(id);
1762
- }
1763
- catch (e) {
1764
- errors.push({ id, error: e?.message ?? String(e) });
1765
- }
1766
- }
1767
- return {
1768
- content: [
1769
- {
1770
- type: "text",
1771
- text: JSON.stringify({ deleted_count: deleted.length, error_count: errors.length, deleted, errors }, null, 2),
1772
- },
1773
- ],
1774
- };
1775
- });
1776
1806
  server.tool("tags.search", "Bulk-tag — run an FTS `search` and append `add_tags` to every matching file in one call. Side effect: each match gets `addTags` applied (additive, idempotent per tag); the matched files themselves are NOT modified beyond their tag links. Per-file failures isolated to `errors[]`. No external auth or rate limits. There is NO dry-run flag, so ALWAYS run `files.search` with the same query first to verify the match set before tagging. The `tags[]` filter requires existing tags to ALL match (it scopes the search; it does not control which tags get added). Returns `{matched_count, tagged_count, tags_applied, tagged_ids, errors}`.", {
1777
1807
  query: z.string().describe("Full-text search query"),
1778
1808
  add_tags: z.array(z.string()).min(1).describe("Tags to add to every matching file"),
@@ -1823,47 +1853,56 @@ server.tool("tags.search", "Bulk-tag — run an FTS `search` and append `add_tag
1823
1853
  ],
1824
1854
  };
1825
1855
  });
1826
- server.tool("files.read_by_path", "Look up a file by its absolute on-disk path and return the same shape as `files.read`. The path must EXACTLY match what Kontexta indexed — no symlink resolution, no path normalisation beyond what the OS does, no trailing-slash tolerance. Returns isError if no row matches (the file may exist on disk but not be indexed — try `projects.refresh_index`). Read-only; no side effects, auth, or rate limits. Use when an agent has a path from its working directory but no file ID; if you have the ID, prefer `files.read`.", {
1827
- path: z.string().describe("Absolute path on disk (must match the path stored in Kontexta)"),
1828
- }, async ({ path }) => {
1829
- try {
1830
- if (typeof path !== "string" || path.length === 0) {
1831
- throw new Error("path is required");
1856
+ server.tool("admin.overview", "Vault-state snapshot. `mode: 'stats'` = aggregate counts for a scope: `file_count`, `untagged_count`, `favorite_count`, `top_tags`. With `project_id` omitted (everything), also returns `by_project` breakdown. `include_token_total: true` stat()s every matching file on disk to compute a body-size estimate — measurably slower on large vaults; default false. `mode: 'whats_new'` = list files created or modified since a checkpoint (`since`, REQUIRED for this mode — ISO-8601 like `2025-01-15T00:00:00Z` or relative durations like `1h`/`7d`/`2w`; invalid formats throw); CAVEAT: hard-deleted files are NOT surfaced, only mtime-driven changes. Both modes: `project_id: null` = KB only; omit = everything. Read-only; no side effects, auth, or rate limits. Use `stats` as a cheap dashboard or to spot untagged content for cleanup (for live disk-vs-index drift use `files.diff_against_disk`); use `whats_new` at session start to catch up.", {
1857
+ mode: z.enum(["stats", "whats_new"]).describe("Which snapshot to return. 'whats_new' requires `since`."),
1858
+ project_id: z.number().nullable().optional().describe("Filter to a single project. Pass null for KB-only. Omit for everything."),
1859
+ top_tags: z.number().int().positive().max(100).optional().describe("mode='stats' only: how many top tags to return (default 10)"),
1860
+ include_token_total: z.boolean().optional().describe("mode='stats' only: if true, stat every matching file on disk to compute total est_tokens. Default false (cheap)."),
1861
+ since: z.string().optional().describe("REQUIRED for mode='whats_new'. ISO 8601 timestamp or relative duration (e.g. \"1h\", \"7d\", \"2w\")."),
1862
+ include_tags: z.boolean().optional().describe("mode='whats_new' only: attach tags[] to each file. Default true."),
1863
+ limit: z.number().optional().describe("mode='whats_new' only: max files returned. Default 200."),
1864
+ }, async ({ mode, project_id, top_tags, include_token_total, since, include_tags, limit }) => {
1865
+ if (mode === "whats_new") {
1866
+ if (!since) {
1867
+ return { isError: true, content: [{ type: "text", text: JSON.stringify({ error: "mode='whats_new' requires `since`" }, null, 2) }] };
1832
1868
  }
1833
- const row = getDatabase()
1834
- .prepare("SELECT id FROM files WHERE path = ?")
1835
- .get(path);
1836
- if (!row) {
1869
+ try {
1870
+ const opts = { since };
1871
+ if (project_id !== undefined)
1872
+ opts.project_id = project_id;
1873
+ if (include_tags !== undefined)
1874
+ opts.include_tags = include_tags;
1875
+ if (limit !== undefined)
1876
+ opts.limit = limit;
1877
+ const result = whatsNew(opts);
1878
+ const annotated = result.files.map(annotateTokens);
1879
+ const total_est_tokens = annotated.reduce((s, f) => s + (f.est_tokens ?? 0), 0);
1837
1880
  return {
1838
- isError: true,
1839
1881
  content: [
1840
1882
  {
1841
1883
  type: "text",
1842
- text: JSON.stringify({ error: `No file indexed at path: ${path}` }, null, 2),
1884
+ text: JSON.stringify({
1885
+ since: result.since,
1886
+ until: result.until,
1887
+ count: result.count,
1888
+ total_est_tokens,
1889
+ files: annotated,
1890
+ }, null, 2),
1843
1891
  },
1844
1892
  ],
1845
1893
  };
1846
1894
  }
1847
- const result = readFile(row.id);
1848
- return {
1849
- content: [{ type: "text", text: JSON.stringify(annotateTokens(result), null, 2) }],
1850
- };
1851
- }
1852
- catch (e) {
1853
- return {
1854
- isError: true,
1855
- content: [{ type: "text", text: JSON.stringify({ error: e?.message ?? String(e) }, null, 2) }],
1856
- };
1895
+ catch (e) {
1896
+ return {
1897
+ isError: true,
1898
+ content: [{ type: "text", text: JSON.stringify({ error: e.message }, null, 2) }],
1899
+ };
1900
+ }
1857
1901
  }
1858
- });
1859
- server.tool("admin.stats", "Aggregate counts for a scope: `file_count`, `untagged_count`, `favorite_count`, `top_tags`. With `project_id` omitted (everything), also returns `by_project` breakdown. `include_token_total: true` stat()s every matching file on disk to compute a body-size estimate — measurably slower on large vaults; default false. `project_id: null` = KB only; omit = all. Read-only; no side effects, auth, or rate limits. Use as a cheap dashboard or to spot untagged content for cleanup; for live disk-vs-index drift use `files.diff_against_disk`.", {
1860
- project_id: z.number().nullable().optional().describe("Filter to a single project. Pass null for KB-only. Omit for everything."),
1861
- top_tags: z.number().int().positive().max(100).optional().describe("How many top tags to return (default 10)"),
1862
- include_token_total: z.boolean().optional().describe("If true, stat every matching file on disk to compute total est_tokens. Default false (cheap)."),
1863
- }, async ({ project_id, top_tags, include_token_total }) => {
1902
+ // mode === "stats"
1864
1903
  try {
1865
1904
  const db = getDatabase();
1866
- const limit = top_tags ?? 10;
1905
+ const limitTags = top_tags ?? 10;
1867
1906
  let scopeWhere = "";
1868
1907
  const scopeParams = [];
1869
1908
  if (project_id === null) {
@@ -1891,7 +1930,7 @@ server.tool("admin.stats", "Aggregate counts for a scope: `file_count`, `untagge
1891
1930
  GROUP BY t.id
1892
1931
  ORDER BY count DESC, t.name ASC
1893
1932
  LIMIT ?`)
1894
- .all(...scopeParams, limit);
1933
+ .all(...scopeParams, limitTags);
1895
1934
  const byProject = project_id === undefined
1896
1935
  ? db
1897
1936
  .prepare(`SELECT p.id, p.name, COUNT(files.id) AS files
@@ -2153,45 +2192,6 @@ server.tool("projects.refresh_index", "Reconcile the FTS index against disk. For
2153
2192
  };
2154
2193
  }
2155
2194
  });
2156
- server.tool("admin.whats_new", "List files created or modified since a checkpoint. `since` accepts ISO-8601 (`2025-01-15T00:00:00Z`) or relative durations (`1h`, `7d`, `2w`); invalid formats throw. Read-only; no side effects, auth, or rate limits. Returns annotated rows plus aggregate `total_est_tokens` so you can decide what to read next. CAVEAT: hard-deleted files are NOT surfaced — only mtime-driven changes. Defaults: include_tags=true, limit=200. `project_id: null` = KB only; omit = everything. Use at session start to catch up.", {
2157
- since: z.string().describe("ISO 8601 timestamp or relative duration (e.g. \"1h\", \"7d\", \"2w\")."),
2158
- project_id: z.number().nullable().optional().describe("Filter to a single project. Pass null for knowledge-base-only files. Omit for all."),
2159
- include_tags: z.boolean().optional().describe("Attach tags[] to each file. Default true."),
2160
- limit: z.number().optional().describe("Max files returned. Default 200."),
2161
- }, async ({ since, project_id, include_tags, limit }) => {
2162
- try {
2163
- const opts = { since };
2164
- if (project_id !== undefined)
2165
- opts.project_id = project_id;
2166
- if (include_tags !== undefined)
2167
- opts.include_tags = include_tags;
2168
- if (limit !== undefined)
2169
- opts.limit = limit;
2170
- const result = whatsNew(opts);
2171
- const annotated = result.files.map(annotateTokens);
2172
- const total_est_tokens = annotated.reduce((s, f) => s + (f.est_tokens ?? 0), 0);
2173
- return {
2174
- content: [
2175
- {
2176
- type: "text",
2177
- text: JSON.stringify({
2178
- since: result.since,
2179
- until: result.until,
2180
- count: result.count,
2181
- total_est_tokens,
2182
- files: annotated,
2183
- }, null, 2),
2184
- },
2185
- ],
2186
- };
2187
- }
2188
- catch (e) {
2189
- return {
2190
- isError: true,
2191
- content: [{ type: "text", text: JSON.stringify({ error: e.message }, null, 2) }],
2192
- };
2193
- }
2194
- });
2195
2195
  server.tool("projects.map", "Return a compact indented outline of folders, file titles, tags, and IDs in a single dense block — substantially fewer tokens than the equivalent `files.list` JSON for the same scope. Read-only; no side effects, auth, or rate limits. Capped at `max_lines` (default 5000); the response reports `est_tokens` and emits a `warning` field if it exceeds `KONTEXTA_PROJECT_TOKEN_WARN`. `project_id: null` = KB only; omit = everything. Defaults: include_tags=true, show_titles=true. Use to orient yourself in an unfamiliar vault or project; for keyword lookup use `files.search`.", {
2196
2196
  project_id: z.number().nullable().optional().describe("Restrict to a single project. Pass null for knowledge-base-only files. Omit for everything."),
2197
2197
  include_tags: z.boolean().optional().describe("Append #tags inline. Default true. Set false to shrink the outline."),
@@ -2271,11 +2271,16 @@ server.resource("File Content", new ResourceTemplate("kontexta://files/{id}", {
2271
2271
  ],
2272
2272
  };
2273
2273
  });
2274
- server.tool("hands.list", "List every Hands command tool currently registered, with project scope, tool name, danger level, confirmation flag, and description. Hands tools come from per-project `kontexta.json` files loaded at register time. Read-only; no side effects, auth, or rate limits. Use to discover what side-effectful project commands the agent is permitted to run; for the `kontexta.json` schema see `hands.describe_schema`; reload after editing one with `hands.reload`.", {}, async () => {
2274
+ server.tool("hands.list", "List every Hands command tool currently registered, with project scope, tool name, danger level, confirmation flag, and description. Hands tools come from per-project `kontexta.json` files loaded at register time. Pass `schema: true` to instead get the complete `kontexta.json` authoring reference (JSON schema, validation rules, security guarantees, limitations, annotated example) — a static document, unrelated to any specific registered hand. Read-only; no side effects, auth, or rate limits. Use the default list mode to discover what side-effectful project commands the agent is permitted to run; use `schema: true` when helping a user write or fix a `kontexta.json`; reload after editing one with `hands.reload`.", {
2275
+ schema: z.boolean().optional().describe("If true, return the kontexta.json authoring reference document instead of the registered-hands list. Default false."),
2276
+ }, async ({ schema }) => {
2277
+ if (schema) {
2278
+ return { content: [{ type: "text", text: buildSchemaDoc() }] };
2279
+ }
2275
2280
  const items = handsRegistry.list();
2276
2281
  return { content: [{ type: "text", text: JSON.stringify({ hands: items }, null, 2) }] };
2277
2282
  });
2278
- server.tool("hands.reload", "Re-scan every registered project's `kontexta.json` and rebuild the live Hands tool registry — newly-declared tools become callable immediately, removed tools disappear from `tools/list`. SIDE EFFECT is on the running MCP session's tool inventory only (no disk writes). Idempotent. No external auth or rate limits. Takes no parameters. Returns per-project load results (counts of registered/disabled tools and any validation warnings). Use after editing a `kontexta.json` mid-session; for the schema see `hands.describe_schema`.", {}, async () => {
2283
+ server.tool("hands.reload", "Re-scan every registered project's `kontexta.json` and rebuild the live Hands tool registry — newly-declared tools become callable immediately, removed tools disappear from `tools/list`. SIDE EFFECT is on the running MCP session's tool inventory only (no disk writes). Idempotent. No external auth or rate limits. Takes no parameters. Returns per-project load results (counts of registered/disabled tools and any validation warnings). Use after editing a `kontexta.json` mid-session; for the schema see `hands.list({ schema: true })`.", {}, async () => {
2279
2284
  const projects = listProjects()
2280
2285
  .filter((p) => p.path && existsSync(p.path))
2281
2286
  .map((p) => ({ name: p.name, root: p.path }));
@@ -2295,7 +2300,6 @@ server.tool("hands.confirm", "Approve and EXECUTE a previously-issued Hands invo
2295
2300
  return { content: [{ type: "text", text: `Execution failed after approval: ${e?.message ?? e}` }] };
2296
2301
  }
2297
2302
  });
2298
- server.tool("hands.describe_schema", "Return the complete authoring reference for `kontexta.json`: JSON schema, validation rules, security guarantees, limitations, and an annotated example. Static document — does not read any project file or DB row. Read-only; no side effects, auth, or rate limits. Takes no parameters. Use when helping a user write or fix a `kontexta.json`; to see the loaded tools themselves use `hands.list`; to apply edits use `hands.reload`.", {}, async () => ({ content: [{ type: "text", text: buildSchemaDoc() }] }));
2299
2303
  server.tool("admin.get_profile", "Return the user profile stored in the Knowledge Base. The profile helps AI agents understand the user's context, role, preferences, and goals. Read-only; no side effects, auth, or rate limits. Returns existence status, full content, list of missing required sections, and a hint for new users. Use at session start to understand who you're working with.", {}, async () => {
2300
2304
  const result = handleGetProfile(dataDir);
2301
2305
  return {