wiki-viewer 1.4.2 → 1.5.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 (280) hide show
  1. package/.next/standalone/.next/BUILD_ID +1 -1
  2. package/.next/standalone/.next/app-path-routes-manifest.json +5 -0
  3. package/.next/standalone/.next/build-manifest.json +3 -3
  4. package/.next/standalone/.next/prerender-manifest.json +3 -27
  5. package/.next/standalone/.next/routes-manifest.json +34 -0
  6. package/.next/standalone/.next/server/app/_global-error/page.js +2 -2
  7. package/.next/standalone/.next/server/app/_global-error/page.js.nft.json +1 -1
  8. package/.next/standalone/.next/server/app/_global-error.html +1 -1
  9. package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
  10. package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  11. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  12. package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  13. package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  14. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  15. package/.next/standalone/.next/server/app/_not-found/page.js +4 -4
  16. package/.next/standalone/.next/server/app/_not-found/page.js.nft.json +1 -1
  17. package/.next/standalone/.next/server/app/_not-found.html +1 -1
  18. package/.next/standalone/.next/server/app/_not-found.rsc +1 -1
  19. package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  20. package/.next/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  21. package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  22. package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  23. package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  24. package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  25. package/.next/standalone/.next/server/app/api/agent/activity/route.js +5 -5
  26. package/.next/standalone/.next/server/app/api/agent/activity/route.js.nft.json +1 -1
  27. package/.next/standalone/.next/server/app/api/agent/admin/agents/[agentId]/revoke/route.js +6 -6
  28. package/.next/standalone/.next/server/app/api/agent/admin/agents/[agentId]/revoke/route.js.nft.json +1 -1
  29. package/.next/standalone/.next/server/app/api/agent/admin/agents/route.js +6 -6
  30. package/.next/standalone/.next/server/app/api/agent/admin/agents/route.js.nft.json +1 -1
  31. package/.next/standalone/.next/server/app/api/agent/admin/registrations/[regId]/approve/route.js +6 -6
  32. package/.next/standalone/.next/server/app/api/agent/admin/registrations/[regId]/approve/route.js.nft.json +1 -1
  33. package/.next/standalone/.next/server/app/api/agent/admin/registrations/[regId]/deny/route.js +4 -4
  34. package/.next/standalone/.next/server/app/api/agent/admin/registrations/[regId]/deny/route.js.nft.json +1 -1
  35. package/.next/standalone/.next/server/app/api/agent/admin/registrations/route.js +4 -4
  36. package/.next/standalone/.next/server/app/api/agent/admin/registrations/route.js.nft.json +1 -1
  37. package/.next/standalone/.next/server/app/api/agent/events/[...path]/route.js +5 -5
  38. package/.next/standalone/.next/server/app/api/agent/events/[...path]/route.js.nft.json +1 -1
  39. package/.next/standalone/.next/server/app/api/agent/files/[...path]/route.js +11 -10
  40. package/.next/standalone/.next/server/app/api/agent/files/[...path]/route.js.nft.json +1 -1
  41. package/.next/standalone/.next/server/app/api/agent/fs/file/[...path]/route/app-paths-manifest.json +3 -0
  42. package/.next/standalone/.next/server/app/api/agent/fs/file/[...path]/route/build-manifest.json +9 -0
  43. package/.next/standalone/.next/server/app/api/agent/fs/file/[...path]/route/server-reference-manifest.json +4 -0
  44. package/.next/standalone/.next/server/app/api/agent/fs/file/[...path]/route.js +17 -0
  45. package/.next/standalone/.next/server/app/api/agent/fs/file/[...path]/route.js.map +5 -0
  46. package/.next/standalone/.next/server/app/api/agent/fs/file/[...path]/route.js.nft.json +1 -0
  47. package/.next/standalone/.next/server/app/api/agent/fs/file/[...path]/route_client-reference-manifest.js +3 -0
  48. package/.next/standalone/.next/server/app/api/agent/fs/ls/[[...path]]/route/app-paths-manifest.json +3 -0
  49. package/.next/standalone/.next/server/app/api/agent/fs/ls/[[...path]]/route/build-manifest.json +9 -0
  50. package/.next/standalone/.next/server/app/api/agent/fs/ls/[[...path]]/route/server-reference-manifest.json +4 -0
  51. package/.next/standalone/.next/server/app/api/agent/fs/ls/[[...path]]/route.js +15 -0
  52. package/.next/standalone/.next/server/app/api/agent/fs/ls/[[...path]]/route.js.map +5 -0
  53. package/.next/standalone/.next/server/app/api/agent/fs/ls/[[...path]]/route.js.nft.json +1 -0
  54. package/.next/standalone/.next/server/app/api/agent/fs/ls/[[...path]]/route_client-reference-manifest.js +3 -0
  55. package/.next/standalone/.next/server/app/api/agent/fs/move/route/app-paths-manifest.json +3 -0
  56. package/.next/standalone/.next/server/app/api/agent/fs/move/route/build-manifest.json +9 -0
  57. package/.next/standalone/.next/server/app/api/agent/fs/move/route/server-reference-manifest.json +4 -0
  58. package/.next/standalone/.next/server/app/api/agent/fs/move/route.js +15 -0
  59. package/.next/standalone/.next/server/app/api/agent/fs/move/route.js.map +5 -0
  60. package/.next/standalone/.next/server/app/api/agent/fs/move/route.js.nft.json +1 -0
  61. package/.next/standalone/.next/server/app/api/agent/fs/move/route_client-reference-manifest.js +3 -0
  62. package/.next/standalone/.next/server/app/api/agent/fs/search/route/app-paths-manifest.json +3 -0
  63. package/.next/standalone/.next/server/app/api/agent/fs/search/route/build-manifest.json +9 -0
  64. package/.next/standalone/.next/server/app/api/agent/fs/search/route/server-reference-manifest.json +4 -0
  65. package/.next/standalone/.next/server/app/api/agent/fs/search/route.js +15 -0
  66. package/.next/standalone/.next/server/app/api/agent/fs/search/route.js.map +5 -0
  67. package/.next/standalone/.next/server/app/api/agent/fs/search/route.js.nft.json +1 -0
  68. package/.next/standalone/.next/server/app/api/agent/fs/search/route_client-reference-manifest.js +3 -0
  69. package/.next/standalone/.next/server/app/api/agent/internal/span/route.js +8 -8
  70. package/.next/standalone/.next/server/app/api/agent/internal/span/route.js.nft.json +1 -1
  71. package/.next/standalone/.next/server/app/api/agent/settings/route.js +8 -8
  72. package/.next/standalone/.next/server/app/api/agent/settings/route.js.nft.json +1 -1
  73. package/.next/standalone/.next/server/app/api/agent/sidecar/[...path]/route.js +7 -7
  74. package/.next/standalone/.next/server/app/api/agent/sidecar/[...path]/route.js.nft.json +1 -1
  75. package/.next/standalone/.next/server/app/api/app-proxy/[...path]/route.js +1 -1
  76. package/.next/standalone/.next/server/app/api/app-proxy/[...path]/route.js.nft.json +1 -1
  77. package/.next/standalone/.next/server/app/api/assets/[...path]/route.js.nft.json +1 -1
  78. package/.next/standalone/.next/server/app/api/auth/[...all]/route.js +3 -3
  79. package/.next/standalone/.next/server/app/api/auth/[...all]/route.js.nft.json +1 -1
  80. package/.next/standalone/.next/server/app/api/system/auth-config/route.js +5 -5
  81. package/.next/standalone/.next/server/app/api/system/auth-config/route.js.nft.json +1 -1
  82. package/.next/standalone/.next/server/app/api/system/auth-settings/route.js +4 -4
  83. package/.next/standalone/.next/server/app/api/system/auth-settings/route.js.nft.json +1 -1
  84. package/.next/standalone/.next/server/app/api/system/browse/route.js +6 -6
  85. package/.next/standalone/.next/server/app/api/system/browse/route.js.nft.json +1 -1
  86. package/.next/standalone/.next/server/app/api/system/clear-root/route.js +5 -5
  87. package/.next/standalone/.next/server/app/api/system/clear-root/route.js.nft.json +1 -1
  88. package/.next/standalone/.next/server/app/api/system/config/route.js +5 -5
  89. package/.next/standalone/.next/server/app/api/system/config/route.js.nft.json +1 -1
  90. package/.next/standalone/.next/server/app/api/system/pins/route.js +4 -4
  91. package/.next/standalone/.next/server/app/api/system/pins/route.js.nft.json +1 -1
  92. package/.next/standalone/.next/server/app/api/system/reveal/route.js +4 -4
  93. package/.next/standalone/.next/server/app/api/system/reveal/route.js.nft.json +1 -1
  94. package/.next/standalone/.next/server/app/api/system/root-status/route.js +4 -4
  95. package/.next/standalone/.next/server/app/api/system/root-status/route.js.nft.json +1 -1
  96. package/.next/standalone/.next/server/app/api/system/set-root/route.js +5 -5
  97. package/.next/standalone/.next/server/app/api/system/set-root/route.js.nft.json +1 -1
  98. package/.next/standalone/.next/server/app/api/upload/[...path]/route.js.nft.json +1 -1
  99. package/.next/standalone/.next/server/app/api/wiki/app/route.js +6 -6
  100. package/.next/standalone/.next/server/app/api/wiki/app/route.js.nft.json +1 -1
  101. package/.next/standalone/.next/server/app/api/wiki/content/route.js +6 -6
  102. package/.next/standalone/.next/server/app/api/wiki/content/route.js.nft.json +1 -1
  103. package/.next/standalone/.next/server/app/api/wiki/file/route.js.nft.json +1 -1
  104. package/.next/standalone/.next/server/app/api/wiki/folder/route.js +5 -5
  105. package/.next/standalone/.next/server/app/api/wiki/folder/route.js.nft.json +1 -1
  106. package/.next/standalone/.next/server/app/api/wiki/move/route.js +6 -6
  107. package/.next/standalone/.next/server/app/api/wiki/move/route.js.nft.json +1 -1
  108. package/.next/standalone/.next/server/app/api/wiki/new-file/route.js +5 -5
  109. package/.next/standalone/.next/server/app/api/wiki/new-file/route.js.nft.json +1 -1
  110. package/.next/standalone/.next/server/app/api/wiki/page/route.js +5 -5
  111. package/.next/standalone/.next/server/app/api/wiki/page/route.js.nft.json +1 -1
  112. package/.next/standalone/.next/server/app/api/wiki/presence/route/app-paths-manifest.json +3 -0
  113. package/.next/standalone/.next/server/app/api/wiki/presence/route/build-manifest.json +9 -0
  114. package/.next/standalone/.next/server/app/api/wiki/presence/route/server-reference-manifest.json +4 -0
  115. package/.next/standalone/.next/server/app/api/wiki/presence/route.js +14 -0
  116. package/.next/standalone/.next/server/app/api/wiki/presence/route.js.map +5 -0
  117. package/.next/standalone/.next/server/app/api/wiki/presence/route.js.nft.json +1 -0
  118. package/.next/standalone/.next/server/app/api/wiki/presence/route_client-reference-manifest.js +3 -0
  119. package/.next/standalone/.next/server/app/api/wiki/route.js +5 -5
  120. package/.next/standalone/.next/server/app/api/wiki/route.js.nft.json +1 -1
  121. package/.next/standalone/.next/server/app/api/wiki/slugs/route.js +5 -5
  122. package/.next/standalone/.next/server/app/api/wiki/slugs/route.js.nft.json +1 -1
  123. package/.next/standalone/.next/server/app/api/wiki/upload/route.js +5 -5
  124. package/.next/standalone/.next/server/app/api/wiki/upload/route.js.nft.json +1 -1
  125. package/.next/standalone/.next/server/app/api/wiki/watch/route.js +6 -6
  126. package/.next/standalone/.next/server/app/api/wiki/watch/route.js.nft.json +1 -1
  127. package/.next/standalone/.next/server/app/index.html +1 -1
  128. package/.next/standalone/.next/server/app/index.rsc +2 -2
  129. package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  130. package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +2 -2
  131. package/.next/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  132. package/.next/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  133. package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  134. package/.next/standalone/.next/server/app/page.js +4 -4
  135. package/.next/standalone/.next/server/app/page.js.nft.json +1 -1
  136. package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  137. package/.next/standalone/.next/server/app/signin/page.js +9 -4
  138. package/.next/standalone/.next/server/app/signin/page.js.nft.json +1 -1
  139. package/.next/standalone/.next/server/app/signin/page_client-reference-manifest.js +1 -1
  140. package/.next/standalone/.next/server/app-paths-manifest.json +5 -0
  141. package/.next/standalone/.next/server/chunks/0p91_next_dist_esm_build_templates_app-route_0d2jbo5.js +3 -0
  142. package/.next/standalone/.next/server/chunks/0p91_next_dist_esm_build_templates_app-route_0ytral2.js +3 -0
  143. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0269d2e._.js +1 -1
  144. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__03h3~3e._.js → [root-of-the-server]__04udrya._.js} +2 -2
  145. package/.next/standalone/.next/server/chunks/[root-of-the-server]__05f6x0i._.js +3 -0
  146. package/.next/standalone/.next/server/chunks/[root-of-the-server]__06-dtd0._.js +3 -0
  147. package/.next/standalone/.next/server/chunks/[root-of-the-server]__06sek6_._.js +1 -1
  148. package/.next/standalone/.next/server/chunks/[root-of-the-server]__09s9qkd._.js +1 -1
  149. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0d75a5q._.js +1 -1
  150. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0d_da6q._.js +3 -0
  151. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0e7si9p._.js +1 -1
  152. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0hhhvm7._.js +1 -1
  153. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__04g0j8i._.js → [root-of-the-server]__0kdn1le._.js} +2 -2
  154. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0kk26wc._.js +3 -0
  155. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0kur4ro._.js +15 -0
  156. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0p12-6~._.js +1 -1
  157. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0qc2~6l._.js +15 -0
  158. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0s~i040._.js +3 -0
  159. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0w47wil._.js +1 -1
  160. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0xq124z._.js +3 -0
  161. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0l..bxz._.js → [root-of-the-server]__0xz-_0v._.js} +2 -2
  162. package/.next/standalone/.next/server/chunks/[root-of-the-server]__10w2q~o._.js +1 -1
  163. package/.next/standalone/.next/server/chunks/_079xuln._.js +3 -0
  164. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_agent_fs_file_[___path]_route_actions_0gb11t~.js +3 -0
  165. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_agent_fs_ls_[[___path]]_route_actions_0wfg4nl.js +3 -0
  166. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_agent_fs_move_route_actions_0z34mqq.js +3 -0
  167. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_agent_fs_search_route_actions_0ut_ug..js +3 -0
  168. package/.next/standalone/.next/server/chunks/_next-internal_server_app_api_wiki_presence_route_actions_0x9d7f4.js +3 -0
  169. package/.next/standalone/.next/server/chunks/{[root-of-the-server]__0d89o98._.js → src_lib_auth_server_ts_00f4e0h._.js} +2 -2
  170. package/.next/standalone/.next/server/chunks/ssr/0biy_@better-auth_core_dist_121m_lh._.js +5 -0
  171. package/.next/standalone/.next/server/chunks/ssr/0dhv_better-auth_dist_adapters_kysely-adapter_index_mjs_08ymlcb._.js +3 -0
  172. package/.next/standalone/.next/server/chunks/ssr/0dti_kysely_dist_esm_0-t3o9q._.js +3 -0
  173. package/.next/standalone/.next/server/chunks/ssr/0dti_kysely_dist_esm_01._58q._.js +3 -0
  174. package/.next/standalone/.next/server/chunks/ssr/0p91_next_0f40gy0._.js +6 -0
  175. package/.next/standalone/.next/server/chunks/ssr/{0p91_next_dist_0~2d1tl._.js → 0p91_next_dist_10ud_sa._.js} +2 -2
  176. package/.next/standalone/.next/server/chunks/ssr/0sag_@better-auth_memory-adapter_dist_index_mjs_07-_ka6._.js +3 -0
  177. package/.next/standalone/.next/server/chunks/ssr/0ugq_@better-auth_kysely-adapter_dist_bun-sqlite-dialect-DzNwOpKv_mjs_0lruvb8._.js +3 -0
  178. package/.next/standalone/.next/server/chunks/ssr/0ugq_@better-auth_kysely-adapter_dist_d1-sqlite-dialect-C2B7YsIT_mjs_03n6~tc._.js +3 -0
  179. package/.next/standalone/.next/server/chunks/ssr/0ugq_@better-auth_kysely-adapter_dist_index_mjs_0gi5w.w._.js +4 -0
  180. package/.next/standalone/.next/server/chunks/ssr/0ugq_@better-auth_kysely-adapter_dist_node-sqlite-dialect_mjs_0l4.y~0._.js +3 -0
  181. package/.next/standalone/.next/server/chunks/ssr/12y~_mermaid_dist_chunks_mermaid_core_diagram-OG6HWLK6_mjs_0t5sus6._.js +1 -1
  182. package/.next/standalone/.next/server/chunks/ssr/12y~_mermaid_dist_chunks_mermaid_core_sankeyDiagram-5OEKKPKP_mjs_11ifrnu._.js +1 -1
  183. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__026s8~z._.js +3 -0
  184. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__06mzg2t._.js +3 -0
  185. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0btcd4o._.js +12 -0
  186. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0c~og-9._.js +3 -0
  187. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__134_q7l._.js +1 -1
  188. package/.next/standalone/.next/server/chunks/ssr/_0pqaawz._.js +3 -3
  189. package/.next/standalone/.next/server/chunks/ssr/node_modules__pnpm_051tcva._.js +3 -0
  190. package/.next/standalone/.next/server/chunks/ssr/node_modules__pnpm_0o~d81.._.js +1 -1
  191. package/.next/standalone/.next/server/chunks/ssr/node_modules__pnpm_0y9k6h~._.js +1 -1
  192. package/.next/standalone/.next/server/chunks/ssr/node_modules__pnpm_0znncy9._.js +1 -1
  193. package/.next/standalone/.next/server/chunks/ssr/node_modules__pnpm_12-ni1n._.js +1 -1
  194. package/.next/standalone/.next/server/chunks/ssr/src_app_signin_00yk0vm._.js +452 -0
  195. package/.next/standalone/.next/server/chunks/ssr/src_app_signin_signin-form_tsx_0eznlbd._.js +3 -0
  196. package/.next/standalone/.next/server/functions-config-manifest.json +5 -0
  197. package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
  198. package/.next/standalone/.next/server/middleware-manifest.json +5 -5
  199. package/.next/standalone/.next/server/pages/404.html +1 -1
  200. package/.next/standalone/.next/server/pages/500.html +1 -1
  201. package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
  202. package/.next/standalone/.next/server/server-reference-manifest.json +1 -1
  203. package/.next/standalone/.next/static/chunks/09-jtayuhrq~b.js +1 -0
  204. package/.next/standalone/.next/static/chunks/0uv7ozzpiyp2_.js +1 -0
  205. package/.next/standalone/.next/static/chunks/135c~rq_ux73w.js +1 -0
  206. package/.next/standalone/.next/static/chunks/{11s9zwr7edrs7.js → 14luv~jq7e6-n.js} +12 -12
  207. package/.next/standalone/README.md +79 -16
  208. package/.next/standalone/agents/bootstrap-prompt.md +12 -1
  209. package/.next/standalone/agents/wiki-viewer-skill/SKILL.md +199 -6
  210. package/.next/standalone/docs/agent-fs-plan.md +65 -7
  211. package/.next/standalone/docs/file-vs-collab-authority.md +124 -0
  212. package/.next/standalone/package.json +1 -1
  213. package/.next/standalone/packages/wiki-viewer-mcp/README.md +194 -0
  214. package/.next/standalone/packages/wiki-viewer-mcp/dist/http-client.js +220 -0
  215. package/.next/standalone/packages/wiki-viewer-mcp/dist/index.js +472 -0
  216. package/.next/standalone/packages/wiki-viewer-mcp/dist/register.js +94 -0
  217. package/.next/standalone/packages/wiki-viewer-mcp/dist/state-cache.js +26 -0
  218. package/.next/standalone/packages/wiki-viewer-mcp/package-lock.json +1716 -0
  219. package/.next/standalone/packages/wiki-viewer-mcp/package.json +41 -0
  220. package/.next/standalone/packages/wiki-viewer-mcp/src/http-client.ts +344 -0
  221. package/.next/standalone/packages/wiki-viewer-mcp/src/index.ts +575 -0
  222. package/.next/standalone/packages/wiki-viewer-mcp/src/register.ts +144 -0
  223. package/.next/standalone/packages/wiki-viewer-mcp/src/state-cache.ts +45 -0
  224. package/.next/standalone/packages/wiki-viewer-mcp/tsconfig.json +19 -0
  225. package/.next/standalone/pnpm-lock.yaml +9 -9
  226. package/.next/standalone/src/app/api/agent/files/[...path]/route.ts +11 -1
  227. package/.next/standalone/src/app/api/agent/fs/file/[...path]/route.ts +344 -0
  228. package/.next/standalone/src/app/api/agent/fs/ls/[[...path]]/route.ts +147 -0
  229. package/.next/standalone/src/app/api/agent/fs/move/route.ts +125 -0
  230. package/.next/standalone/src/app/api/agent/fs/search/route.ts +236 -0
  231. package/.next/standalone/src/app/api/agent/register/route.ts +3 -3
  232. package/.next/standalone/src/app/api/agents/install/route.ts +44 -2
  233. package/.next/standalone/src/app/api/wiki/move/route.ts +10 -1
  234. package/.next/standalone/src/app/api/wiki/presence/route.ts +55 -0
  235. package/.next/standalone/src/app/signin/page.tsx +10 -225
  236. package/.next/standalone/src/app/signin/signin-form.tsx +238 -0
  237. package/.next/standalone/src/components/ai-panel/ai-panel.tsx +49 -0
  238. package/.next/standalone/src/components/editor/editor.tsx +38 -0
  239. package/.next/standalone/src/lib/proof/audit.ts +79 -0
  240. package/.next/standalone/src/lib/proof/auth.ts +2 -2
  241. package/.next/standalone/src/lib/proof/collab-state.ts +79 -0
  242. package/.next/standalone/src/lib/proof/lease.ts +104 -0
  243. package/.next/standalone/src/lib/proof/ops-applier.ts +74 -25
  244. package/.next/standalone/src/lib/proof/raw-fs.ts +198 -0
  245. package/.next/standalone/src/lib/proof/registry.ts +1 -1
  246. package/.next/standalone/src/lib/proof/sidecar.ts +38 -1
  247. package/.next/standalone/src/lib/proof/types.ts +13 -1
  248. package/.next/standalone/src/tests/proof/agent-fs.test.ts +824 -0
  249. package/.next/standalone/src/tests/proof/agents-install.test.ts +53 -0
  250. package/.next/standalone/src/tests/proof/collab-state.test.ts +499 -0
  251. package/.next/standalone/src/tests/proof/reconcile-sidecar.test.ts +195 -0
  252. package/.next/standalone/src/tests/proof/sidecar-lifecycle.test.ts +177 -0
  253. package/.next/standalone/tsconfig.tsbuildinfo +1 -1
  254. package/README.md +79 -16
  255. package/package.json +1 -1
  256. package/.next/standalone/.next/server/app/signin.html +0 -1
  257. package/.next/standalone/.next/server/app/signin.meta +0 -15
  258. package/.next/standalone/.next/server/app/signin.rsc +0 -23
  259. package/.next/standalone/.next/server/app/signin.segments/_full.segment.rsc +0 -23
  260. package/.next/standalone/.next/server/app/signin.segments/_head.segment.rsc +0 -6
  261. package/.next/standalone/.next/server/app/signin.segments/_index.segment.rsc +0 -7
  262. package/.next/standalone/.next/server/app/signin.segments/_tree.segment.rsc +0 -3
  263. package/.next/standalone/.next/server/app/signin.segments/signin/__PAGE__.segment.rsc +0 -9
  264. package/.next/standalone/.next/server/app/signin.segments/signin.segment.rsc +0 -5
  265. package/.next/standalone/.next/server/chunks/[root-of-the-server]__09~~-nd._.js +0 -3
  266. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0w87kiz._.js +0 -3
  267. package/.next/standalone/.next/server/chunks/[root-of-the-server]__12ssbhv._.js +0 -3
  268. package/.next/standalone/.next/server/chunks/node_modules__pnpm_0g0fhfk._.js +0 -3
  269. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__088hqzy._.js +0 -3
  270. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0c147fo._.js +0 -3
  271. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0z.1v1z._.js +0 -3
  272. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__12zp2dm._.js +0 -3
  273. package/.next/standalone/.next/server/chunks/ssr/node_modules__pnpm_0exqvyf._.js +0 -3
  274. package/.next/standalone/.next/server/chunks/ssr/src_app_signin_page_tsx_1143y49._.js +0 -3
  275. package/.next/standalone/.next/static/chunks/0-_39e4awbk8y.js +0 -1
  276. package/.next/standalone/.next/static/chunks/02bxx~2cg~s6~.js +0 -1
  277. package/.next/standalone/.next/static/chunks/0mj_f8ncf2tks.js +0 -1
  278. /package/.next/standalone/.next/static/{OwXjVuoXDC_gda_BKji1J → 19j4-_brJLoulXAMekpM2}/_buildManifest.js +0 -0
  279. /package/.next/standalone/.next/static/{OwXjVuoXDC_gda_BKji1J → 19j4-_brJLoulXAMekpM2}/_clientMiddlewareManifest.js +0 -0
  280. /package/.next/standalone/.next/static/{OwXjVuoXDC_gda_BKji1J → 19j4-_brJLoulXAMekpM2}/_ssgManifest.js +0 -0
@@ -0,0 +1,472 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * wiki-viewer-mcp — MCP filesystem adapter for wiki-viewer agent API.
4
+ *
5
+ * Maps standard MCP filesystem tools onto the wiki-viewer HTTP agent API
6
+ * described in docs/agent-fs-plan.md §2 + §3.5 + §6.
7
+ *
8
+ * Configuration (env vars):
9
+ * WIKI_VIEWER_URL Base URL of wiki-viewer instance (required)
10
+ * WIKI_VIEWER_TOKEN Bearer token from TOFU registration (required)
11
+ * WIKI_VIEWER_AGENT_ID X-Agent-Id header value (required)
12
+ *
13
+ * Mode-awareness:
14
+ * Before any raw write to a .md file, the shim checks the cached
15
+ * X-Collab-State from the last read. If "active", it blocks the write
16
+ * and instructs the agent to use Tier-2 block-ops instead.
17
+ * The server also enforces this (409 COLLAB_ACTIVE), which the shim
18
+ * surfaces cleanly.
19
+ */
20
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
21
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
22
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
23
+ import * as z from "zod";
24
+ import { parseArgs } from "node:util";
25
+ import { WikiViewerClient, IfMatchError, CollabActiveError, WikiViewerError } from "./http-client.js";
26
+ import * as stateCache from "./state-cache.js";
27
+ import { register, RegistrationDeniedError, RegistrationExpiredError, RegistrationTimeoutError, } from "./register.js";
28
+ // ─── Config ───────────────────────────────────────────────────────────────────
29
+ function requireEnv(name) {
30
+ const v = process.env[name];
31
+ if (!v)
32
+ throw new Error(`Missing required env var: ${name}`);
33
+ return v;
34
+ }
35
+ export function createClient(overrides) {
36
+ return new WikiViewerClient({
37
+ baseUrl: overrides?.baseUrl ?? requireEnv("WIKI_VIEWER_URL"),
38
+ token: overrides?.token ?? requireEnv("WIKI_VIEWER_TOKEN"),
39
+ agentId: overrides?.agentId ?? requireEnv("WIKI_VIEWER_AGENT_ID"),
40
+ fetch: overrides?.fetch,
41
+ });
42
+ }
43
+ // ─── Tool schemas ─────────────────────────────────────────────────────────────
44
+ const ReadFileInput = z.object({
45
+ path: z.string().describe("File path relative to wiki root"),
46
+ range: z.string().optional().describe("HTTP Range header value, e.g. 'bytes=0-1023'"),
47
+ });
48
+ const WriteFileInput = z.object({
49
+ path: z.string().describe("File path relative to wiki root"),
50
+ content: z.string().describe("File content (text)"),
51
+ mkdirs: z.boolean().optional().describe("Create parent directories if missing"),
52
+ force: z.boolean().optional().describe("Skip If-Match guard (audited)"),
53
+ ifCollabMatch: z.number().optional().describe("If-Collab-Match revision (for tracked .md)"),
54
+ });
55
+ const EditFileInput = z.object({
56
+ path: z.string().describe("File path relative to wiki root"),
57
+ find: z.string().describe("Exact string to find (first occurrence)"),
58
+ replace: z.string().describe("Replacement string"),
59
+ });
60
+ const ListDirectoryInput = z.object({
61
+ path: z.string().describe("Directory path relative to wiki root"),
62
+ recursive: z.boolean().optional().describe("List recursively"),
63
+ depth: z.number().optional().describe("Max depth for recursive listing"),
64
+ limit: z.number().optional().describe("Max entries to return"),
65
+ });
66
+ const SearchInput = z.object({
67
+ kind: z.enum(["grep", "glob"]).describe("grep = text search, glob = path pattern"),
68
+ query: z.string().describe("Search query or glob pattern"),
69
+ path: z.string().optional().describe("Root path to search within"),
70
+ glob: z.string().optional().describe("File glob filter for grep"),
71
+ limit: z.number().optional().describe("Max matches to return"),
72
+ });
73
+ const MoveFileInput = z.object({
74
+ from: z.string().describe("Source path"),
75
+ to: z.string().describe("Destination path"),
76
+ });
77
+ const DeleteFileInput = z.object({
78
+ path: z.string().describe("File path to delete"),
79
+ recursive: z.boolean().optional().describe("Delete directory recursively"),
80
+ force: z.boolean().optional().describe("Skip If-Match guard (audited)"),
81
+ });
82
+ // ─── Tool definitions ─────────────────────────────────────────────────────────
83
+ export const TOOLS = [
84
+ {
85
+ name: "read_file",
86
+ description: "Read a file from the wiki-viewer instance. Returns content and metadata. " +
87
+ "Captures sha256 (ETag) and X-Collab-State for subsequent writes. " +
88
+ "Always read before writing to get the current sha.",
89
+ inputSchema: zodToJsonSchema(ReadFileInput),
90
+ },
91
+ {
92
+ name: "write_file",
93
+ description: "Write (create or overwrite) a file. " +
94
+ "If you have previously read the file, the last known sha is sent as If-Match automatically — " +
95
+ "you get a 412 error if the file changed since your read. " +
96
+ "WARNING: for .md files with X-Collab-State 'active', raw writes are blocked — " +
97
+ "use wiki-viewer block-ops (Tier 2) instead so the human can review your changes.",
98
+ inputSchema: zodToJsonSchema(WriteFileInput),
99
+ },
100
+ {
101
+ name: "edit_file",
102
+ description: "Edit a file by exact string replacement (first occurrence). " +
103
+ "Implemented client-side as: read → str-replace → PUT with If-Match. " +
104
+ "Returns an error if the find string is not found or the file is collab-active. " +
105
+ "For .md files, prefer block-ops if X-Collab-State is 'active'.",
106
+ inputSchema: zodToJsonSchema(EditFileInput),
107
+ },
108
+ {
109
+ name: "list_directory",
110
+ description: "List directory contents. Scope-filtered; .proof/ is hidden.",
111
+ inputSchema: zodToJsonSchema(ListDirectoryInput),
112
+ },
113
+ {
114
+ name: "search",
115
+ description: "Search files. kind='grep' searches file contents; kind='glob' matches paths. " +
116
+ "Server-side — avoids round-trip explosion from ls+read patterns.",
117
+ inputSchema: zodToJsonSchema(SearchInput),
118
+ },
119
+ {
120
+ name: "move_file",
121
+ description: "Move or rename a file. Sidecar (.proof/*.json) is moved automatically for .md files.",
122
+ inputSchema: zodToJsonSchema(MoveFileInput),
123
+ },
124
+ {
125
+ name: "delete_file",
126
+ description: "Delete a file. Requires 'delete' scope. You must have read the file first " +
127
+ "(its sha is sent as If-Match). .md sidecars are removed automatically.",
128
+ inputSchema: zodToJsonSchema(DeleteFileInput),
129
+ },
130
+ ];
131
+ // ─── Handler helpers ──────────────────────────────────────────────────────────
132
+ function isMd(path) {
133
+ return path.endsWith(".md") || path.endsWith(".markdown");
134
+ }
135
+ function collabActiveMessage(path, snapshotUrl) {
136
+ const tier2 = snapshotUrl
137
+ ? `\nTier-2 block-ops snapshot: ${snapshotUrl}`
138
+ : "";
139
+ return (`⚠️ COLLAB ACTIVE: "${path}" is being actively collaborated on by a human.\n` +
140
+ `Raw writes are blocked to protect pending review artifacts.\n` +
141
+ `→ Use wiki-viewer Tier-2 block-ops (POST /api/agent/files/<path>.md with block.replace / suggestion.*) so your edit becomes a reviewable suggestion.${tier2}\n` +
142
+ `→ Alternatively, re-read the file and pass ifCollabMatch with the current X-Collab-Revision if you have confirmed with the human that a direct raw write is intended.`);
143
+ }
144
+ function ifMatchMismatchMessage(path) {
145
+ return (`412 If-Match mismatch for "${path}" — the file changed since you last read it.\n` +
146
+ `Re-read the file with read_file to get the current content and sha, then retry.`);
147
+ }
148
+ function ok(text) {
149
+ return { content: [{ type: "text", text }] };
150
+ }
151
+ function err(text) {
152
+ return { content: [{ type: "text", text: `ERROR: ${text}` }] };
153
+ }
154
+ /**
155
+ * Check cached collab state before a write.
156
+ * Returns a blocking error message if write should not proceed, or null if ok.
157
+ */
158
+ function checkCollabBlock(path) {
159
+ if (!isMd(path))
160
+ return null;
161
+ const cached = stateCache.get(path);
162
+ if (!cached)
163
+ return null; // no prior read — let server enforce
164
+ if (cached.collabState === "active") {
165
+ return collabActiveMessage(path, cached.collabSnapshot);
166
+ }
167
+ return null;
168
+ }
169
+ // ─── Server factory ───────────────────────────────────────────────────────────
170
+ export function createServer(client) {
171
+ const server = new Server({ name: "wiki-viewer-mcp", version: "0.1.0" }, { capabilities: { tools: {} } });
172
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
173
+ tools: TOOLS,
174
+ }));
175
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
176
+ const { name, arguments: args } = request.params;
177
+ try {
178
+ switch (name) {
179
+ // ── read_file ───────────────────────────────────────────────────────
180
+ case "read_file": {
181
+ const { path, range } = ReadFileInput.parse(args);
182
+ const result = await client.readFile(path, range);
183
+ const collabNote = result.collabState !== "not-markdown"
184
+ ? `\nX-Collab-State: ${result.collabState}` +
185
+ (result.collabRevision !== null ? `\nX-Collab-Revision: ${result.collabRevision}` : "") +
186
+ (result.collabSnapshot ? `\nX-Collab-Snapshot: ${result.collabSnapshot}` : "") +
187
+ (result.collabState === "active"
188
+ ? "\n⚠️ File is COLLAB ACTIVE — use block-ops for edits so human can review."
189
+ : result.collabState === "tracked"
190
+ ? "\nFile is tracked — prefer block-ops for prose/semantic edits."
191
+ : "")
192
+ : "";
193
+ if (result.text !== null) {
194
+ return ok(`File: ${path}\nSize: ${result.size} bytes | ETag: ${result.sha256}${collabNote}\n\n${result.text}`);
195
+ }
196
+ else {
197
+ return ok(`File: ${path}\nSize: ${result.size} bytes | ETag: ${result.sha256}\nContent-Type: ${result.contentType} (binary — use range reads for partial content)${collabNote}`);
198
+ }
199
+ }
200
+ // ── write_file ──────────────────────────────────────────────────────
201
+ case "write_file": {
202
+ const { path, content, mkdirs, force, ifCollabMatch } = WriteFileInput.parse(args);
203
+ // Client-side collab guard
204
+ const block = checkCollabBlock(path);
205
+ if (block)
206
+ return err(block);
207
+ const cached = stateCache.get(path);
208
+ const ifMatch = cached?.sha256;
209
+ const result = await client.writeFile(path, content, {
210
+ ifMatch,
211
+ mkdirs,
212
+ force,
213
+ ifCollabMatch,
214
+ });
215
+ return ok(`Written: ${path}\nSha256: ${result.sha256}\nSize: ${result.size} bytes\n${result.created ? "Created (new file)" : "Overwritten"}`);
216
+ }
217
+ // ── edit_file ───────────────────────────────────────────────────────
218
+ case "edit_file": {
219
+ const { path, find, replace } = EditFileInput.parse(args);
220
+ // Client-side collab guard
221
+ const block = checkCollabBlock(path);
222
+ if (block)
223
+ return err(block);
224
+ // Read → transform → PUT with If-Match
225
+ const readResult = await client.readFile(path);
226
+ if (readResult.text === null) {
227
+ return err(`edit_file: "${path}" appears to be binary — cannot do text replacement.`);
228
+ }
229
+ // Check collab state from fresh read
230
+ if (readResult.collabState === "active") {
231
+ return err(collabActiveMessage(path, readResult.collabSnapshot));
232
+ }
233
+ if (!readResult.text.includes(find)) {
234
+ return err(`edit_file: string not found in "${path}".\n` +
235
+ `Search for: ${JSON.stringify(find)}\n` +
236
+ `Tip: re-read the file to see current content.`);
237
+ }
238
+ const newContent = readResult.text.replace(find, replace);
239
+ const writeResult = await client.writeFile(path, newContent, {
240
+ ifMatch: readResult.sha256,
241
+ });
242
+ return ok(`Edited: ${path}\nReplaced ${JSON.stringify(find)} → ${JSON.stringify(replace)}\nNew sha256: ${writeResult.sha256}`);
243
+ }
244
+ // ── list_directory ──────────────────────────────────────────────────
245
+ case "list_directory": {
246
+ const { path, recursive, depth, limit } = ListDirectoryInput.parse(args);
247
+ const entries = await client.listDirectory(path, { recursive, depth, limit });
248
+ const lines = entries.map((e) => `${e.type === "directory" ? "DIR " : "FILE"} ${e.path}` +
249
+ (e.size !== null ? ` (${e.size}b)` : "") +
250
+ (e.mtime ? ` [${e.mtime}]` : ""));
251
+ return ok(lines.length > 0 ? lines.join("\n") : "(empty directory)");
252
+ }
253
+ // ── search ──────────────────────────────────────────────────────────
254
+ case "search": {
255
+ const body = SearchInput.parse(args);
256
+ const result = await client.search(body);
257
+ if (result.matches.length === 0) {
258
+ return ok("No matches found.");
259
+ }
260
+ const lines = result.matches.map((m) => {
261
+ if (result.kind === "grep" && m.line !== undefined) {
262
+ return `${m.path}:${m.line}: ${m.text ?? ""}`;
263
+ }
264
+ return m.path;
265
+ });
266
+ return ok(`${result.matches.length} match(es):\n${lines.join("\n")}`);
267
+ }
268
+ // ── move_file ───────────────────────────────────────────────────────
269
+ case "move_file": {
270
+ const { from, to } = MoveFileInput.parse(args);
271
+ const cached = stateCache.get(from);
272
+ await client.moveFile(from, to, cached?.sha256);
273
+ return ok(`Moved: ${from} → ${to}`);
274
+ }
275
+ // ── delete_file ─────────────────────────────────────────────────────
276
+ case "delete_file": {
277
+ const { path, recursive, force } = DeleteFileInput.parse(args);
278
+ const cached = stateCache.get(path);
279
+ if (!cached?.sha256) {
280
+ return err(`delete_file: no cached sha for "${path}" — read the file first with read_file so the current sha can be sent as If-Match.`);
281
+ }
282
+ await client.deleteFile(path, cached.sha256, { recursive, force });
283
+ return ok(`Deleted: ${path}`);
284
+ }
285
+ default:
286
+ return err(`Unknown tool: ${name}`);
287
+ }
288
+ }
289
+ catch (e) {
290
+ if (e instanceof IfMatchError) {
291
+ return err(ifMatchMismatchMessage(e.message.match(/"([^"]+)"/)?.at(1) ?? "file"));
292
+ }
293
+ if (e instanceof CollabActiveError) {
294
+ return err(collabActiveMessage(e.message, e.snapshotUrl));
295
+ }
296
+ if (e instanceof WikiViewerError) {
297
+ return err(`wiki-viewer error ${e.status} (${e.code}): ${e.message}`);
298
+ }
299
+ if (e instanceof z.ZodError) {
300
+ return err(`Invalid arguments: ${e.message}`);
301
+ }
302
+ throw e; // unexpected — let MCP transport handle
303
+ }
304
+ });
305
+ return server;
306
+ }
307
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
308
+ function zodToJsonSchema(schema) {
309
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
310
+ const shape = schema.shape;
311
+ const properties = {};
312
+ const required = [];
313
+ for (const [key, val] of Object.entries(shape)) {
314
+ const v = val;
315
+ const isOptional = v._def.type === "optional";
316
+ const inner = isOptional ? (v.unwrap ? v.unwrap() : v._def.innerType ?? v) : v;
317
+ properties[key] = buildJsonSchema(inner);
318
+ if (!isOptional)
319
+ required.push(key);
320
+ }
321
+ return { type: "object", properties, required };
322
+ }
323
+ function buildJsonSchema(val) {
324
+ const desc = val.description ?? val._def.description;
325
+ const withDesc = (s) => { if (desc)
326
+ s["description"] = desc; return s; };
327
+ switch (val._def.type) {
328
+ case "string": return withDesc({ type: "string" });
329
+ case "number": return withDesc({ type: "number" });
330
+ case "boolean": return withDesc({ type: "boolean" });
331
+ case "enum": {
332
+ const opts = val.options ?? Object.keys(val._def.entries ?? {});
333
+ return withDesc({ type: "string", enum: opts });
334
+ }
335
+ case "optional": return buildJsonSchema(val.unwrap ? val.unwrap() : val._def.innerType ?? val);
336
+ default: return withDesc({ type: "string" });
337
+ }
338
+ }
339
+ // ─── Entrypoints ─────────────────────────────────────────────────────────────
340
+ async function main() {
341
+ const client = createClient();
342
+ const server = createServer(client);
343
+ const transport = new StdioServerTransport();
344
+ await server.connect(transport);
345
+ // Server runs until stdin closes
346
+ }
347
+ /**
348
+ * CLI entry: routes to `register` subcommand or MCP stdio server.
349
+ * Only called when the file is the actual entry point (not imported in tests).
350
+ */
351
+ async function runCli() {
352
+ // Detect subcommand: first positional arg
353
+ const positional = process.argv.slice(2).filter((a) => !a.startsWith("-"));
354
+ const subcommand = positional[0];
355
+ if (subcommand === "register") {
356
+ await runRegister();
357
+ }
358
+ else {
359
+ await main();
360
+ }
361
+ }
362
+ async function runRegister() {
363
+ const { values } = parseArgs({
364
+ args: process.argv.slice(2),
365
+ options: {
366
+ url: { type: "string" },
367
+ id: { type: "string" },
368
+ name: { type: "string" },
369
+ "scope-paths": { type: "string", default: "**/*" },
370
+ ops: { type: "string", default: "read,mutate" },
371
+ timeout: { type: "string", default: "300" },
372
+ },
373
+ allowPositionals: true,
374
+ });
375
+ if (!values.url) {
376
+ console.error("Error: --url is required (e.g. https://notes.example.com)");
377
+ process.exit(1);
378
+ }
379
+ if (!values.id) {
380
+ console.error("Error: --id is required (e.g. ai:myagent)");
381
+ process.exit(1);
382
+ }
383
+ if (!values.name) {
384
+ console.error("Error: --name is required (e.g. \"My Agent\")");
385
+ process.exit(1);
386
+ }
387
+ if (!values.id.match(/^ai:[a-z][a-z0-9-]{0,30}$/)) {
388
+ console.error("Error: --id must match ^ai:[a-z][a-z0-9-]{0,30}$ (e.g. ai:myagent)");
389
+ process.exit(1);
390
+ }
391
+ const scopePaths = (values["scope-paths"] ?? "**/*").split(",").map((p) => p.trim());
392
+ const rawOps = (values.ops ?? "read,mutate").split(",").map((o) => o.trim());
393
+ const validOps = ["read", "mutate", "delete"];
394
+ const ops = rawOps.filter((o) => validOps.includes(o));
395
+ if (ops.length === 0) {
396
+ console.error("Error: --ops must include at least one of: read, mutate, delete");
397
+ process.exit(1);
398
+ }
399
+ const scope = { paths: scopePaths, ops };
400
+ const timeoutMs = parseInt(values.timeout ?? "300", 10) * 1000;
401
+ console.log(`Registering agent ${values.id} with ${values.url} …`);
402
+ console.log(`Scope: paths=${JSON.stringify(scopePaths)}, ops=${JSON.stringify(ops)}`);
403
+ console.log();
404
+ try {
405
+ const result = await register({
406
+ baseUrl: values.url,
407
+ id: values.id,
408
+ displayName: values.name,
409
+ scope,
410
+ timeoutMs,
411
+ onPending: (_id, attempt) => {
412
+ if (attempt === 1) {
413
+ console.log(`⏳ Waiting for approval. Open the wiki-viewer AI Panel and approve agent "${values.id}".`);
414
+ }
415
+ else if (attempt % 10 === 0) {
416
+ console.log(` Still waiting… (${attempt * 3}s elapsed)`);
417
+ }
418
+ },
419
+ });
420
+ console.log();
421
+ console.log("✅ Approved!");
422
+ console.log();
423
+ console.log(`Agent ID : ${result.agentId}`);
424
+ console.log(`Token : ${result.token}`);
425
+ console.log();
426
+ console.log("Paste this into your mcp.json:");
427
+ console.log();
428
+ console.log(JSON.stringify({
429
+ servers: {
430
+ "wiki-viewer": {
431
+ command: "npx",
432
+ args: ["wiki-viewer-mcp"],
433
+ env: {
434
+ WIKI_VIEWER_URL: values.url,
435
+ WIKI_VIEWER_TOKEN: result.token,
436
+ WIKI_VIEWER_AGENT_ID: result.agentId,
437
+ },
438
+ },
439
+ },
440
+ }, null, 2));
441
+ process.exit(0);
442
+ }
443
+ catch (e) {
444
+ if (e instanceof RegistrationDeniedError ||
445
+ e instanceof RegistrationExpiredError ||
446
+ e instanceof RegistrationTimeoutError) {
447
+ console.error(`\n❌ ${e.message}`);
448
+ }
449
+ else {
450
+ console.error("\n❌ Unexpected error:", e);
451
+ }
452
+ process.exit(1);
453
+ }
454
+ }
455
+ // Only auto-start when this file is the entry point, not when imported in tests.
456
+ if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\/dist\//, "/src/").replace(/\.js$/, ".ts"))) {
457
+ runCli().catch((e) => {
458
+ console.error("wiki-viewer-mcp fatal:", e);
459
+ process.exit(1);
460
+ });
461
+ }
462
+ else if (
463
+ // Also run when invoked as the compiled binary
464
+ process.argv[1] &&
465
+ (process.argv[1].endsWith("wiki-viewer-mcp") || process.argv[1].endsWith("index.js")) &&
466
+ !process.argv[1].includes("__tests__")) {
467
+ runCli().catch((e) => {
468
+ console.error("wiki-viewer-mcp fatal:", e);
469
+ process.exit(1);
470
+ });
471
+ }
472
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,94 @@
1
+ /**
2
+ * TOFU registration flow for wiki-viewer.
3
+ *
4
+ * Pure function `register()` is testable with a mock fetch.
5
+ * The CLI wrapper lives in index.ts.
6
+ *
7
+ * Flow:
8
+ * POST /api/agent/register → {registrationId, pollUrl, status:"pending"}
9
+ * human approves in AI Panel
10
+ * GET <pollUrl> → 202 pending | 200 approved | 410 denied | 404 expired
11
+ * returns {token, agentId}
12
+ */
13
+ export async function register(opts) {
14
+ const _fetch = opts.fetch ?? globalThis.fetch;
15
+ const pollIntervalMs = opts.pollIntervalMs ?? 3_000;
16
+ const timeoutMs = opts.timeoutMs ?? 300_000;
17
+ const base = opts.baseUrl.replace(/\/$/, "");
18
+ // ── Step 1: POST registration ──────────────────────────────────────────────
19
+ const postRes = await _fetch(`${base}/api/agent/register`, {
20
+ method: "POST",
21
+ headers: { "Content-Type": "application/json" },
22
+ body: JSON.stringify({
23
+ id: opts.id,
24
+ displayName: opts.displayName,
25
+ scope: opts.scope,
26
+ }),
27
+ });
28
+ if (!postRes.ok) {
29
+ const body = await postRes.text().catch(() => "");
30
+ throw new Error(`Registration request failed (${postRes.status}): ${body}`);
31
+ }
32
+ const { registrationId, pollUrl } = await postRes.json();
33
+ // Resolve pollUrl — may be absolute or relative
34
+ const resolvedPollUrl = pollUrl.startsWith("http")
35
+ ? pollUrl
36
+ : `${base}${pollUrl.startsWith("/") ? "" : "/"}${pollUrl}`;
37
+ // ── Step 2: Poll until approved / denied / timeout ─────────────────────────
38
+ const deadline = Date.now() + timeoutMs;
39
+ let attempt = 0;
40
+ while (Date.now() < deadline) {
41
+ await sleep(pollIntervalMs);
42
+ attempt++;
43
+ const pollRes = await _fetch(resolvedPollUrl);
44
+ if (pollRes.status === 200) {
45
+ const body = await pollRes.json();
46
+ if (body.status === "approved" && body.agentId && body.token) {
47
+ return { token: body.token, agentId: body.agentId };
48
+ }
49
+ if (body.status === "denied") {
50
+ throw new RegistrationDeniedError("Registration denied by the operator.");
51
+ }
52
+ }
53
+ else if (pollRes.status === 202) {
54
+ // Still pending — fire callback and loop
55
+ opts.onPending?.(registrationId, attempt);
56
+ }
57
+ else if (pollRes.status === 410) {
58
+ const body = await pollRes.json().catch(() => ({}));
59
+ throw new RegistrationDeniedError(`Registration ${body.status ?? "denied/consumed"} — it can no longer be approved.`);
60
+ }
61
+ else if (pollRes.status === 404) {
62
+ throw new RegistrationExpiredError("Registration expired (404). Try registering again.");
63
+ }
64
+ else {
65
+ throw new Error(`Unexpected poll status ${pollRes.status}.`);
66
+ }
67
+ }
68
+ throw new RegistrationTimeoutError(`Timed out after ${Math.round(timeoutMs / 1000)}s. ` +
69
+ `The request may still be pending in the wiki-viewer AI Panel (id: ${registrationId}).`);
70
+ }
71
+ // ── Typed errors ──────────────────────────────────────────────────────────────
72
+ export class RegistrationDeniedError extends Error {
73
+ constructor(message) {
74
+ super(message);
75
+ this.name = "RegistrationDeniedError";
76
+ }
77
+ }
78
+ export class RegistrationExpiredError extends Error {
79
+ constructor(message) {
80
+ super(message);
81
+ this.name = "RegistrationExpiredError";
82
+ }
83
+ }
84
+ export class RegistrationTimeoutError extends Error {
85
+ constructor(message) {
86
+ super(message);
87
+ this.name = "RegistrationTimeoutError";
88
+ }
89
+ }
90
+ // ── Helpers ───────────────────────────────────────────────────────────────────
91
+ function sleep(ms) {
92
+ return new Promise((resolve) => setTimeout(resolve, ms));
93
+ }
94
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Per-path cache for last-known file metadata from GET responses.
3
+ * Drives If-Match and collab-state checks on subsequent writes.
4
+ */
5
+ const cache = new Map();
6
+ export function set(path, state) {
7
+ cache.set(normalisePath(path), state);
8
+ }
9
+ export function get(path) {
10
+ return cache.get(normalisePath(path));
11
+ }
12
+ export function del(path) {
13
+ cache.delete(normalisePath(path));
14
+ }
15
+ export function rename(from, to) {
16
+ const s = cache.get(normalisePath(from));
17
+ if (s) {
18
+ cache.delete(normalisePath(from));
19
+ cache.set(normalisePath(to), s);
20
+ }
21
+ }
22
+ /** Normalise leading slash away so 'foo/bar' and '/foo/bar' are the same key */
23
+ function normalisePath(p) {
24
+ return p.replace(/^\/+/, "");
25
+ }
26
+ //# sourceMappingURL=state-cache.js.map