studiograph 1.3.48-next.2 → 1.3.48-next.201

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 (1157) hide show
  1. package/README.md +26 -16
  2. package/dist/agent/agent-pool.d.ts +117 -0
  3. package/dist/agent/agent-pool.js +287 -0
  4. package/dist/agent/agent-pool.js.map +1 -0
  5. package/dist/agent/followups.d.ts +34 -0
  6. package/dist/agent/followups.js +52 -0
  7. package/dist/agent/followups.js.map +1 -0
  8. package/dist/agent/orchestrator.d.ts +113 -22
  9. package/dist/agent/orchestrator.js +574 -181
  10. package/dist/agent/orchestrator.js.map +1 -1
  11. package/dist/agent/prompts/entity-types-section.d.ts +34 -0
  12. package/dist/agent/prompts/entity-types-section.js +76 -0
  13. package/dist/agent/prompts/entity-types-section.js.map +1 -0
  14. package/dist/agent/prompts/system.md +147 -69
  15. package/dist/agent/skill-loader.d.ts +30 -17
  16. package/dist/agent/skill-loader.js +63 -30
  17. package/dist/agent/skill-loader.js.map +1 -1
  18. package/dist/agent/skills/entity-schema.md +77 -433
  19. package/dist/agent/skills/interview/entity-templates.md +193 -0
  20. package/dist/agent/skills/interview/question-domains.md +391 -0
  21. package/dist/agent/skills/interview/skill.md +204 -0
  22. package/dist/agent/skills/schema-rules.md +54 -0
  23. package/dist/agent/tools/capture-tools.d.ts +31 -0
  24. package/dist/agent/tools/capture-tools.js +40 -0
  25. package/dist/agent/tools/capture-tools.js.map +1 -0
  26. package/dist/agent/tools/folder-tools.d.ts +47 -0
  27. package/dist/agent/tools/folder-tools.js +249 -0
  28. package/dist/agent/tools/folder-tools.js.map +1 -0
  29. package/dist/agent/tools/fs-tools.d.ts +7 -6
  30. package/dist/agent/tools/fs-tools.js +5 -4
  31. package/dist/agent/tools/fs-tools.js.map +1 -1
  32. package/dist/agent/tools/graph-tools.d.ts +21 -58
  33. package/dist/agent/tools/graph-tools.js +664 -333
  34. package/dist/agent/tools/graph-tools.js.map +1 -1
  35. package/dist/agent/tools/history-tools.d.ts +95 -0
  36. package/dist/agent/tools/history-tools.js +461 -0
  37. package/dist/agent/tools/history-tools.js.map +1 -0
  38. package/dist/agent/tools/load-skill.d.ts +6 -5
  39. package/dist/agent/tools/load-skill.js +3 -3
  40. package/dist/agent/tools/load-skill.js.map +1 -1
  41. package/dist/agent/tools/ops-tools.d.ts +5 -4
  42. package/dist/agent/tools/ops-tools.js +130 -236
  43. package/dist/agent/tools/ops-tools.js.map +1 -1
  44. package/dist/agent/tools/permission-tools.d.ts +87 -17
  45. package/dist/agent/tools/permission-tools.js +233 -38
  46. package/dist/agent/tools/permission-tools.js.map +1 -1
  47. package/dist/agent/tools/tool-loader.js +5 -4
  48. package/dist/agent/tools/tool-loader.js.map +1 -1
  49. package/dist/agent/tools/web-tools.js +58 -9
  50. package/dist/agent/tools/web-tools.js.map +1 -1
  51. package/dist/cli/commands/about.d.ts +1 -0
  52. package/dist/cli/commands/about.js +55 -3
  53. package/dist/cli/commands/about.js.map +1 -1
  54. package/dist/cli/commands/admin/audit-workspace.d.ts +23 -0
  55. package/dist/cli/commands/admin/audit-workspace.js +133 -0
  56. package/dist/cli/commands/admin/audit-workspace.js.map +1 -0
  57. package/dist/cli/commands/admin/audit.d.ts +21 -0
  58. package/dist/cli/commands/admin/audit.js +174 -0
  59. package/dist/cli/commands/admin/audit.js.map +1 -0
  60. package/dist/cli/commands/admin/backup.d.ts +54 -0
  61. package/dist/cli/commands/admin/backup.js +207 -0
  62. package/dist/cli/commands/admin/backup.js.map +1 -0
  63. package/dist/cli/commands/admin/folder.d.ts +11 -0
  64. package/dist/cli/commands/admin/folder.js +186 -0
  65. package/dist/cli/commands/admin/folder.js.map +1 -0
  66. package/dist/cli/commands/admin/index.d.ts +16 -0
  67. package/dist/cli/commands/admin/index.js +46 -0
  68. package/dist/cli/commands/admin/index.js.map +1 -0
  69. package/dist/cli/commands/admin/migrate-assets.d.ts +53 -0
  70. package/dist/cli/commands/admin/migrate-assets.js +184 -0
  71. package/dist/cli/commands/admin/migrate-assets.js.map +1 -0
  72. package/dist/cli/commands/admin/migrate.d.ts +56 -0
  73. package/dist/cli/commands/admin/migrate.js +263 -0
  74. package/dist/cli/commands/admin/migrate.js.map +1 -0
  75. package/dist/cli/commands/admin/restore.d.ts +24 -0
  76. package/dist/cli/commands/admin/restore.js +228 -0
  77. package/dist/cli/commands/admin/restore.js.map +1 -0
  78. package/dist/cli/commands/admin/secrets.d.ts +23 -0
  79. package/dist/cli/commands/admin/secrets.js +256 -0
  80. package/dist/cli/commands/admin/secrets.js.map +1 -0
  81. package/dist/cli/commands/admin/settings.d.ts +28 -0
  82. package/dist/cli/commands/admin/settings.js +284 -0
  83. package/dist/cli/commands/admin/settings.js.map +1 -0
  84. package/dist/cli/commands/admin/token.d.ts +42 -0
  85. package/dist/cli/commands/admin/token.js +126 -0
  86. package/dist/cli/commands/admin/token.js.map +1 -0
  87. package/dist/cli/commands/admin/transfer-ownership.d.ts +15 -0
  88. package/dist/cli/commands/admin/transfer-ownership.js +106 -0
  89. package/dist/cli/commands/admin/transfer-ownership.js.map +1 -0
  90. package/dist/cli/commands/admin/user.d.ts +11 -0
  91. package/dist/cli/commands/admin/user.js +187 -0
  92. package/dist/cli/commands/admin/user.js.map +1 -0
  93. package/dist/cli/commands/clone.d.ts +25 -3
  94. package/dist/cli/commands/clone.js +142 -36
  95. package/dist/cli/commands/clone.js.map +1 -1
  96. package/dist/cli/commands/commit.d.ts +1 -1
  97. package/dist/cli/commands/commit.js +24 -11
  98. package/dist/cli/commands/commit.js.map +1 -1
  99. package/dist/cli/commands/config.d.ts +23 -107
  100. package/dist/cli/commands/config.js +52 -260
  101. package/dist/cli/commands/config.js.map +1 -1
  102. package/dist/cli/commands/connector.d.ts +10 -13
  103. package/dist/cli/commands/connector.js +16 -58
  104. package/dist/cli/commands/connector.js.map +1 -1
  105. package/dist/cli/commands/deploy.js +215 -68
  106. package/dist/cli/commands/deploy.js.map +1 -1
  107. package/dist/cli/commands/index.js +2 -2
  108. package/dist/cli/commands/index.js.map +1 -1
  109. package/dist/cli/commands/init.js +10 -30
  110. package/dist/cli/commands/init.js.map +1 -1
  111. package/dist/cli/commands/mcp.js +12 -4
  112. package/dist/cli/commands/mcp.js.map +1 -1
  113. package/dist/cli/commands/orphans.js +14 -30
  114. package/dist/cli/commands/orphans.js.map +1 -1
  115. package/dist/cli/commands/r2.d.ts +3 -0
  116. package/dist/cli/commands/r2.js +223 -204
  117. package/dist/cli/commands/r2.js.map +1 -1
  118. package/dist/cli/commands/redeploy.js +65 -12
  119. package/dist/cli/commands/redeploy.js.map +1 -1
  120. package/dist/cli/commands/reset.d.ts +22 -6
  121. package/dist/cli/commands/reset.js +142 -63
  122. package/dist/cli/commands/reset.js.map +1 -1
  123. package/dist/cli/commands/serve.js +218 -24
  124. package/dist/cli/commands/serve.js.map +1 -1
  125. package/dist/cli/commands/sync.d.ts +1 -1
  126. package/dist/cli/commands/sync.js +372 -202
  127. package/dist/cli/commands/sync.js.map +1 -1
  128. package/dist/cli/crypto-bundle.d.ts +39 -0
  129. package/dist/cli/crypto-bundle.js +94 -0
  130. package/dist/cli/crypto-bundle.js.map +1 -0
  131. package/dist/cli/index.js +24 -35
  132. package/dist/cli/index.js.map +1 -1
  133. package/dist/cli/railway-pin.d.ts +68 -0
  134. package/dist/cli/railway-pin.js +96 -0
  135. package/dist/cli/railway-pin.js.map +1 -0
  136. package/dist/cli/railway-provisioning.d.ts +53 -0
  137. package/dist/cli/railway-provisioning.js +85 -0
  138. package/dist/cli/railway-provisioning.js.map +1 -0
  139. package/dist/cli/setup-wizard.d.ts +33 -52
  140. package/dist/cli/setup-wizard.js +43 -68
  141. package/dist/cli/setup-wizard.js.map +1 -1
  142. package/dist/core/accent-palette.d.ts +22 -0
  143. package/dist/core/accent-palette.js +47 -0
  144. package/dist/core/accent-palette.js.map +1 -0
  145. package/dist/core/cell-anchor.d.ts +29 -0
  146. package/dist/core/cell-anchor.js +53 -0
  147. package/dist/core/cell-anchor.js.map +1 -0
  148. package/dist/core/comment-anchor.d.ts +41 -0
  149. package/dist/core/comment-anchor.js +147 -0
  150. package/dist/core/comment-anchor.js.map +1 -0
  151. package/dist/core/commit-messages.d.ts +57 -0
  152. package/dist/core/commit-messages.js +85 -0
  153. package/dist/core/commit-messages.js.map +1 -0
  154. package/dist/core/embeds.d.ts +77 -0
  155. package/dist/core/embeds.js +147 -0
  156. package/dist/core/embeds.js.map +1 -0
  157. package/dist/core/entity-body-templates.d.ts +21 -0
  158. package/dist/core/entity-body-templates.js +53 -0
  159. package/dist/core/entity-body-templates.js.map +1 -0
  160. package/dist/core/entity-types-catalog.d.ts +65 -0
  161. package/dist/core/entity-types-catalog.js +140 -0
  162. package/dist/core/entity-types-catalog.js.map +1 -0
  163. package/dist/core/folder-paths.d.ts +41 -0
  164. package/dist/core/folder-paths.js +95 -0
  165. package/dist/core/folder-paths.js.map +1 -0
  166. package/dist/core/folder-sidecar.d.ts +36 -0
  167. package/dist/core/folder-sidecar.js +91 -0
  168. package/dist/core/folder-sidecar.js.map +1 -0
  169. package/dist/core/format-registry.d.ts +170 -0
  170. package/dist/core/format-registry.js +404 -0
  171. package/dist/core/format-registry.js.map +1 -0
  172. package/dist/core/graph.d.ts +731 -14
  173. package/dist/core/graph.js +2202 -315
  174. package/dist/core/graph.js.map +1 -1
  175. package/dist/core/history-diff.d.ts +35 -0
  176. package/dist/core/history-diff.js +114 -0
  177. package/dist/core/history-diff.js.map +1 -0
  178. package/dist/core/refs.d.ts +41 -0
  179. package/dist/core/refs.js +80 -0
  180. package/dist/core/refs.js.map +1 -0
  181. package/dist/core/schema-registry.d.ts +82 -0
  182. package/dist/core/schema-registry.js +238 -0
  183. package/dist/core/schema-registry.js.map +1 -1
  184. package/dist/core/schemas/connector.d.ts +67 -0
  185. package/dist/core/schemas/connector.js +100 -0
  186. package/dist/core/schemas/connector.js.map +1 -0
  187. package/dist/core/schemas/workspace.d.ts +122 -0
  188. package/dist/core/schemas/workspace.js +211 -0
  189. package/dist/core/schemas/workspace.js.map +1 -0
  190. package/dist/core/secrets/SecretStore.d.ts +77 -0
  191. package/dist/core/secrets/SecretStore.js +13 -0
  192. package/dist/core/secrets/SecretStore.js.map +1 -0
  193. package/dist/core/secrets/SettingsResolver.d.ts +54 -0
  194. package/dist/core/secrets/SettingsResolver.js +80 -0
  195. package/dist/core/secrets/SettingsResolver.js.map +1 -0
  196. package/dist/core/secrets/SettingsStore.d.ts +30 -0
  197. package/dist/core/secrets/SettingsStore.js +9 -0
  198. package/dist/core/secrets/SettingsStore.js.map +1 -0
  199. package/dist/core/secrets/SqliteEncryptedStore.d.ts +90 -0
  200. package/dist/core/secrets/SqliteEncryptedStore.js +598 -0
  201. package/dist/core/secrets/SqliteEncryptedStore.js.map +1 -0
  202. package/dist/core/secrets/audit.d.ts +36 -0
  203. package/dist/core/secrets/audit.js +60 -0
  204. package/dist/core/secrets/audit.js.map +1 -0
  205. package/dist/core/secrets/auth-db-migration.d.ts +129 -0
  206. package/dist/core/secrets/auth-db-migration.js +653 -0
  207. package/dist/core/secrets/auth-db-migration.js.map +1 -0
  208. package/dist/core/secrets/bundle.d.ts +141 -0
  209. package/dist/core/secrets/bundle.js +435 -0
  210. package/dist/core/secrets/bundle.js.map +1 -0
  211. package/dist/core/secrets/dual-write.d.ts +81 -0
  212. package/dist/core/secrets/dual-write.js +247 -0
  213. package/dist/core/secrets/dual-write.js.map +1 -0
  214. package/dist/core/secrets/encryption.d.ts +44 -0
  215. package/dist/core/secrets/encryption.js +97 -0
  216. package/dist/core/secrets/encryption.js.map +1 -0
  217. package/dist/core/secrets/index.d.ts +49 -0
  218. package/dist/core/secrets/index.js +74 -0
  219. package/dist/core/secrets/index.js.map +1 -0
  220. package/dist/core/secrets/master-key.d.ts +38 -0
  221. package/dist/core/secrets/master-key.js +122 -0
  222. package/dist/core/secrets/master-key.js.map +1 -0
  223. package/dist/core/secrets/probes/anthropic.d.ts +98 -0
  224. package/dist/core/secrets/probes/anthropic.js +300 -0
  225. package/dist/core/secrets/probes/anthropic.js.map +1 -0
  226. package/dist/core/secrets/probes/brave.d.ts +9 -0
  227. package/dist/core/secrets/probes/brave.js +15 -0
  228. package/dist/core/secrets/probes/brave.js.map +1 -0
  229. package/dist/core/secrets/probes/r2.d.ts +15 -0
  230. package/dist/core/secrets/probes/r2.js +14 -0
  231. package/dist/core/secrets/probes/r2.js.map +1 -0
  232. package/dist/core/secrets/probes/tavily.d.ts +18 -0
  233. package/dist/core/secrets/probes/tavily.js +58 -0
  234. package/dist/core/secrets/probes/tavily.js.map +1 -0
  235. package/dist/core/secrets/probes/voyage.d.ts +13 -0
  236. package/dist/core/secrets/probes/voyage.js +52 -0
  237. package/dist/core/secrets/probes/voyage.js.map +1 -0
  238. package/dist/core/secrets/r2-structural-migration.d.ts +39 -0
  239. package/dist/core/secrets/r2-structural-migration.js +109 -0
  240. package/dist/core/secrets/r2-structural-migration.js.map +1 -0
  241. package/dist/core/secrets/read-flip.d.ts +59 -0
  242. package/dist/core/secrets/read-flip.js +87 -0
  243. package/dist/core/secrets/read-flip.js.map +1 -0
  244. package/dist/core/secrets/registry.d.ts +188 -0
  245. package/dist/core/secrets/registry.js +616 -0
  246. package/dist/core/secrets/registry.js.map +1 -0
  247. package/dist/core/types.d.ts +80 -475
  248. package/dist/core/types.js +27 -3
  249. package/dist/core/types.js.map +1 -1
  250. package/dist/core/user-config.d.ts +75 -7
  251. package/dist/core/user-config.js +155 -7
  252. package/dist/core/user-config.js.map +1 -1
  253. package/dist/core/validation.d.ts +731 -1790
  254. package/dist/core/validation.js +442 -228
  255. package/dist/core/validation.js.map +1 -1
  256. package/dist/core/workspace-manager.d.ts +89 -12
  257. package/dist/core/workspace-manager.js +225 -73
  258. package/dist/core/workspace-manager.js.map +1 -1
  259. package/dist/core/workspace.d.ts +19 -5
  260. package/dist/core/workspace.js +69 -35
  261. package/dist/core/workspace.js.map +1 -1
  262. package/dist/mcp/comment-virtual-entity.d.ts +36 -0
  263. package/dist/mcp/comment-virtual-entity.js +71 -0
  264. package/dist/mcp/comment-virtual-entity.js.map +1 -0
  265. package/dist/mcp/connector-manager.d.ts +94 -13
  266. package/dist/mcp/connector-manager.js +283 -62
  267. package/dist/mcp/connector-manager.js.map +1 -1
  268. package/dist/mcp/oauth-provider.d.ts +27 -33
  269. package/dist/mcp/oauth-provider.js +65 -134
  270. package/dist/mcp/oauth-provider.js.map +1 -1
  271. package/dist/mcp/oauth-registry.d.ts +62 -0
  272. package/dist/mcp/oauth-registry.js +85 -0
  273. package/dist/mcp/oauth-registry.js.map +1 -0
  274. package/dist/mcp/server.d.ts +11 -3
  275. package/dist/mcp/server.js +30 -5
  276. package/dist/mcp/server.js.map +1 -1
  277. package/dist/mcp/state-signer.d.ts +62 -0
  278. package/dist/mcp/state-signer.js +205 -0
  279. package/dist/mcp/state-signer.js.map +1 -0
  280. package/dist/mcp/tools.d.ts +35 -2
  281. package/dist/mcp/tools.js +1361 -112
  282. package/dist/mcp/tools.js.map +1 -1
  283. package/dist/server/__tests__/helpers/graph-api.d.ts +16 -0
  284. package/dist/server/__tests__/helpers/graph-api.js +16 -0
  285. package/dist/server/__tests__/helpers/graph-api.js.map +1 -0
  286. package/dist/server/asset-index-queue.d.ts +96 -0
  287. package/dist/server/asset-index-queue.js +191 -0
  288. package/dist/server/asset-index-queue.js.map +1 -0
  289. package/dist/server/body-write-coordinator.d.ts +151 -0
  290. package/dist/server/body-write-coordinator.js +161 -0
  291. package/dist/server/body-write-coordinator.js.map +1 -0
  292. package/dist/server/cloud-billing-flow.d.ts +32 -0
  293. package/dist/server/cloud-billing-flow.js +75 -0
  294. package/dist/server/cloud-billing-flow.js.map +1 -0
  295. package/dist/server/commit-audit.d.ts +26 -0
  296. package/dist/server/commit-audit.js +30 -0
  297. package/dist/server/commit-audit.js.map +1 -0
  298. package/dist/server/index.d.ts +22 -3
  299. package/dist/server/index.js +622 -198
  300. package/dist/server/index.js.map +1 -1
  301. package/dist/server/middleware/sanitize.d.ts +46 -0
  302. package/dist/server/middleware/sanitize.js +171 -0
  303. package/dist/server/middleware/sanitize.js.map +1 -0
  304. package/dist/server/routes/asset-api.d.ts +31 -0
  305. package/dist/server/routes/asset-api.js +593 -0
  306. package/dist/server/routes/asset-api.js.map +1 -0
  307. package/dist/server/routes/audit-api.d.ts +24 -0
  308. package/dist/server/routes/audit-api.js +117 -0
  309. package/dist/server/routes/audit-api.js.map +1 -0
  310. package/dist/server/routes/auth-api.d.ts +3 -2
  311. package/dist/server/routes/auth-api.js +573 -39
  312. package/dist/server/routes/auth-api.js.map +1 -1
  313. package/dist/server/routes/capture-api.d.ts +18 -0
  314. package/dist/server/routes/capture-api.js +257 -0
  315. package/dist/server/routes/capture-api.js.map +1 -0
  316. package/dist/server/routes/chat-sessions-api.d.ts +9 -0
  317. package/dist/server/routes/chat-sessions-api.js +121 -0
  318. package/dist/server/routes/chat-sessions-api.js.map +1 -0
  319. package/dist/server/routes/chat.d.ts +12 -1
  320. package/dist/server/routes/chat.js +318 -88
  321. package/dist/server/routes/chat.js.map +1 -1
  322. package/dist/server/routes/comments-api.d.ts +15 -0
  323. package/dist/server/routes/comments-api.js +444 -0
  324. package/dist/server/routes/comments-api.js.map +1 -0
  325. package/dist/server/routes/config-api.d.ts +21 -0
  326. package/dist/server/routes/config-api.js +256 -0
  327. package/dist/server/routes/config-api.js.map +1 -0
  328. package/dist/server/routes/connectors-api.d.ts +17 -0
  329. package/dist/server/routes/connectors-api.js +410 -0
  330. package/dist/server/routes/connectors-api.js.map +1 -0
  331. package/dist/server/routes/event-ingest-api.d.ts +15 -0
  332. package/dist/server/routes/event-ingest-api.js +125 -0
  333. package/dist/server/routes/event-ingest-api.js.map +1 -0
  334. package/dist/server/routes/git-http.d.ts +3 -3
  335. package/dist/server/routes/git-http.js +86 -38
  336. package/dist/server/routes/git-http.js.map +1 -1
  337. package/dist/server/routes/graph-api-access.d.ts +57 -0
  338. package/dist/server/routes/graph-api-access.js +112 -0
  339. package/dist/server/routes/graph-api-access.js.map +1 -0
  340. package/dist/server/routes/graph-api.d.ts +1 -1
  341. package/dist/server/routes/graph-api.js +1529 -263
  342. package/dist/server/routes/graph-api.js.map +1 -1
  343. package/dist/server/routes/health.d.ts +18 -0
  344. package/dist/server/routes/health.js +74 -0
  345. package/dist/server/routes/health.js.map +1 -0
  346. package/dist/server/routes/import-batch.d.ts +24 -0
  347. package/dist/server/routes/import-batch.js +33 -0
  348. package/dist/server/routes/import-batch.js.map +1 -0
  349. package/dist/server/routes/insights-api.d.ts +9 -2
  350. package/dist/server/routes/insights-api.js +384 -38
  351. package/dist/server/routes/insights-api.js.map +1 -1
  352. package/dist/server/routes/mcp.d.ts +7 -3
  353. package/dist/server/routes/mcp.js +22 -6
  354. package/dist/server/routes/mcp.js.map +1 -1
  355. package/dist/server/routes/oauth-api.d.ts +67 -0
  356. package/dist/server/routes/oauth-api.js +421 -0
  357. package/dist/server/routes/oauth-api.js.map +1 -0
  358. package/dist/server/routes/permissions-api.d.ts +9 -2
  359. package/dist/server/routes/permissions-api.js +87 -30
  360. package/dist/server/routes/permissions-api.js.map +1 -1
  361. package/dist/server/routes/r2-api.d.ts +25 -0
  362. package/dist/server/routes/r2-api.js +276 -0
  363. package/dist/server/routes/r2-api.js.map +1 -0
  364. package/dist/server/routes/secrets-api.d.ts +36 -0
  365. package/dist/server/routes/secrets-api.js +308 -0
  366. package/dist/server/routes/secrets-api.js.map +1 -0
  367. package/dist/server/routes/settings-api.d.ts +29 -0
  368. package/dist/server/routes/settings-api.js +180 -0
  369. package/dist/server/routes/settings-api.js.map +1 -0
  370. package/dist/server/routes/share-api.d.ts +32 -0
  371. package/dist/server/routes/share-api.js +234 -0
  372. package/dist/server/routes/share-api.js.map +1 -0
  373. package/dist/server/routes/url-api.d.ts +7 -0
  374. package/dist/server/routes/url-api.js +74 -0
  375. package/dist/server/routes/url-api.js.map +1 -0
  376. package/dist/server/routes/views-api.js +75 -7
  377. package/dist/server/routes/views-api.js.map +1 -1
  378. package/dist/server/routes/workspace-api.d.ts +2 -1
  379. package/dist/server/routes/workspace-api.js +129 -35
  380. package/dist/server/routes/workspace-api.js.map +1 -1
  381. package/dist/server/routes/ws.d.ts +2 -1
  382. package/dist/server/routes/ws.js +68 -16
  383. package/dist/server/routes/ws.js.map +1 -1
  384. package/dist/server/session-manager.d.ts +48 -5
  385. package/dist/server/session-manager.js +182 -15
  386. package/dist/server/session-manager.js.map +1 -1
  387. package/dist/server/ws-hub.d.ts +138 -14
  388. package/dist/server/ws-hub.js +0 -0
  389. package/dist/server/ws-hub.js.map +1 -1
  390. package/dist/server/yjs-manager.d.ts +285 -7
  391. package/dist/server/yjs-manager.js +907 -36
  392. package/dist/server/yjs-manager.js.map +1 -1
  393. package/dist/server/yjs-persistence.d.ts +165 -0
  394. package/dist/server/yjs-persistence.js +557 -0
  395. package/dist/server/yjs-persistence.js.map +1 -0
  396. package/dist/server/yjs-text-diff.d.ts +32 -0
  397. package/dist/server/yjs-text-diff.js +61 -0
  398. package/dist/server/yjs-text-diff.js.map +1 -0
  399. package/dist/services/access-control.d.ts +73 -0
  400. package/dist/services/access-control.js +165 -0
  401. package/dist/services/access-control.js.map +1 -0
  402. package/dist/services/asset-caption-service.d.ts +102 -0
  403. package/dist/services/asset-caption-service.js +184 -0
  404. package/dist/services/asset-caption-service.js.map +1 -0
  405. package/dist/services/asset-delete-authz.d.ts +31 -0
  406. package/dist/services/asset-delete-authz.js +61 -0
  407. package/dist/services/asset-delete-authz.js.map +1 -0
  408. package/dist/services/asset-finalize-service.d.ts +58 -0
  409. package/dist/services/asset-finalize-service.js +207 -0
  410. package/dist/services/asset-finalize-service.js.map +1 -0
  411. package/dist/services/asset-import-service.d.ts +111 -0
  412. package/dist/services/asset-import-service.js +394 -0
  413. package/dist/services/asset-import-service.js.map +1 -0
  414. package/dist/services/asset-index-sweep.d.ts +92 -0
  415. package/dist/services/asset-index-sweep.js +258 -0
  416. package/dist/services/asset-index-sweep.js.map +1 -0
  417. package/dist/services/asset-lifecycle-check.d.ts +22 -0
  418. package/dist/services/asset-lifecycle-check.js +80 -0
  419. package/dist/services/asset-lifecycle-check.js.map +1 -0
  420. package/dist/services/asset-listing.d.ts +72 -0
  421. package/dist/services/asset-listing.js +321 -0
  422. package/dist/services/asset-listing.js.map +1 -0
  423. package/dist/services/asset-presign-service.d.ts +68 -0
  424. package/dist/services/asset-presign-service.js +124 -0
  425. package/dist/services/asset-presign-service.js.map +1 -0
  426. package/dist/services/asset-sidecar-service.d.ts +30 -0
  427. package/dist/services/asset-sidecar-service.js +96 -0
  428. package/dist/services/asset-sidecar-service.js.map +1 -0
  429. package/dist/services/asset-upload-errors.d.ts +41 -0
  430. package/dist/services/asset-upload-errors.js +45 -0
  431. package/dist/services/asset-upload-errors.js.map +1 -0
  432. package/dist/services/asset-upload-service.d.ts +74 -0
  433. package/dist/services/asset-upload-service.js +244 -0
  434. package/dist/services/asset-upload-service.js.map +1 -0
  435. package/dist/services/asset-upload-token.d.ts +58 -0
  436. package/dist/services/asset-upload-token.js +75 -0
  437. package/dist/services/asset-upload-token.js.map +1 -0
  438. package/dist/services/assets/asset-index-service.d.ts +127 -0
  439. package/dist/services/assets/asset-index-service.js +227 -0
  440. package/dist/services/assets/asset-index-service.js.map +1 -0
  441. package/dist/services/assets/base.d.ts +118 -1
  442. package/dist/services/assets/base.js +77 -1
  443. package/dist/services/assets/base.js.map +1 -1
  444. package/dist/services/assets/index.d.ts +103 -1
  445. package/dist/services/assets/index.js +192 -0
  446. package/dist/services/assets/index.js.map +1 -1
  447. package/dist/services/assets/local.d.ts +16 -1
  448. package/dist/services/assets/local.js +110 -1
  449. package/dist/services/assets/local.js.map +1 -1
  450. package/dist/services/assets/r2-sync.d.ts +88 -0
  451. package/dist/services/assets/r2-sync.js +412 -0
  452. package/dist/services/assets/r2-sync.js.map +1 -0
  453. package/dist/services/assets/r2.d.ts +87 -1
  454. package/dist/services/assets/r2.js +203 -1
  455. package/dist/services/assets/r2.js.map +1 -1
  456. package/dist/services/auth-service.d.ts +350 -36
  457. package/dist/services/auth-service.js +1179 -140
  458. package/dist/services/auth-service.js.map +1 -1
  459. package/dist/services/bookmark-import-service.d.ts +49 -0
  460. package/dist/services/bookmark-import-service.js +250 -0
  461. package/dist/services/bookmark-import-service.js.map +1 -0
  462. package/dist/services/chat-session-service.d.ts +96 -0
  463. package/dist/services/chat-session-service.js +316 -0
  464. package/dist/services/chat-session-service.js.map +1 -0
  465. package/dist/services/cloud-inference-billing.d.ts +64 -0
  466. package/dist/services/cloud-inference-billing.js +313 -0
  467. package/dist/services/cloud-inference-billing.js.map +1 -0
  468. package/dist/services/comment-service.d.ts +97 -0
  469. package/dist/services/comment-service.js +341 -0
  470. package/dist/services/comment-service.js.map +1 -0
  471. package/dist/services/convert-service.d.ts +64 -0
  472. package/dist/services/convert-service.js +68 -0
  473. package/dist/services/convert-service.js.map +1 -0
  474. package/dist/services/csv-service.d.ts +22 -17
  475. package/dist/services/csv-service.js +55 -92
  476. package/dist/services/csv-service.js.map +1 -1
  477. package/dist/services/entity-mutations.d.ts +210 -0
  478. package/dist/services/entity-mutations.js +377 -0
  479. package/dist/services/entity-mutations.js.map +1 -0
  480. package/dist/services/event-processor.d.ts +104 -0
  481. package/dist/services/event-processor.js +441 -0
  482. package/dist/services/event-processor.js.map +1 -0
  483. package/dist/services/extract/docx.d.ts +1 -0
  484. package/dist/services/extract/docx.js +233 -0
  485. package/dist/services/extract/docx.js.map +1 -0
  486. package/dist/services/extract/index.d.ts +9 -0
  487. package/dist/services/extract/index.js +10 -0
  488. package/dist/services/extract/index.js.map +1 -0
  489. package/dist/services/extract/pdf.d.ts +13 -0
  490. package/dist/services/extract/pdf.js +69 -0
  491. package/dist/services/extract/pdf.js.map +1 -0
  492. package/dist/services/folder-creation.d.ts +33 -0
  493. package/dist/services/folder-creation.js +103 -0
  494. package/dist/services/folder-creation.js.map +1 -0
  495. package/dist/services/git.d.ts +54 -0
  496. package/dist/services/git.js +188 -54
  497. package/dist/services/git.js.map +1 -1
  498. package/dist/services/graph-maintenance.d.ts +42 -0
  499. package/dist/services/graph-maintenance.js +143 -0
  500. package/dist/services/graph-maintenance.js.map +1 -0
  501. package/dist/services/import-service.d.ts +58 -3
  502. package/dist/services/import-service.js +316 -100
  503. package/dist/services/import-service.js.map +1 -1
  504. package/dist/services/lint-service.js +10 -17
  505. package/dist/services/lint-service.js.map +1 -1
  506. package/dist/services/markdown.d.ts +12 -1
  507. package/dist/services/markdown.js +77 -9
  508. package/dist/services/markdown.js.map +1 -1
  509. package/dist/services/memory-service.d.ts +22 -14
  510. package/dist/services/memory-service.js +53 -35
  511. package/dist/services/memory-service.js.map +1 -1
  512. package/dist/services/mention-detector.d.ts +23 -0
  513. package/dist/services/mention-detector.js +47 -0
  514. package/dist/services/mention-detector.js.map +1 -0
  515. package/dist/services/model-capabilities.d.ts +41 -0
  516. package/dist/services/model-capabilities.js +107 -0
  517. package/dist/services/model-capabilities.js.map +1 -0
  518. package/dist/services/notification-broadcast.d.ts +32 -0
  519. package/dist/services/notification-broadcast.js +38 -0
  520. package/dist/services/notification-broadcast.js.map +1 -0
  521. package/dist/services/notification-service.d.ts +41 -0
  522. package/dist/services/notification-service.js +100 -0
  523. package/dist/services/notification-service.js.map +1 -0
  524. package/dist/services/oauth-server-store.d.ts +147 -0
  525. package/dist/services/oauth-server-store.js +319 -0
  526. package/dist/services/oauth-server-store.js.map +1 -0
  527. package/dist/services/orphan-service.js +2 -2
  528. package/dist/services/orphan-service.js.map +1 -1
  529. package/dist/services/personal-folder.d.ts +40 -0
  530. package/dist/services/personal-folder.js +101 -0
  531. package/dist/services/personal-folder.js.map +1 -0
  532. package/dist/services/share-link-service.d.ts +57 -0
  533. package/dist/services/share-link-service.js +142 -0
  534. package/dist/services/share-link-service.js.map +1 -0
  535. package/dist/services/user-person-bridge.d.ts +136 -0
  536. package/dist/services/user-person-bridge.js +340 -0
  537. package/dist/services/user-person-bridge.js.map +1 -0
  538. package/dist/services/vector-service.d.ts +260 -6
  539. package/dist/services/vector-service.js +574 -31
  540. package/dist/services/vector-service.js.map +1 -1
  541. package/dist/services/workspace-access.d.ts +108 -0
  542. package/dist/services/workspace-access.js +149 -0
  543. package/dist/services/workspace-access.js.map +1 -0
  544. package/dist/services/workspace-assets-folder.d.ts +46 -0
  545. package/dist/services/workspace-assets-folder.js +75 -0
  546. package/dist/services/workspace-assets-folder.js.map +1 -0
  547. package/dist/utils/git.d.ts +17 -2
  548. package/dist/utils/git.js +23 -7
  549. package/dist/utils/git.js.map +1 -1
  550. package/dist/utils/log.d.ts +42 -0
  551. package/dist/utils/log.js +137 -0
  552. package/dist/utils/log.js.map +1 -0
  553. package/dist/utils/preflight.js +2 -2
  554. package/dist/utils/preflight.js.map +1 -1
  555. package/dist/utils/version-checker.d.ts +12 -19
  556. package/dist/utils/version-checker.js +14 -104
  557. package/dist/utils/version-checker.js.map +1 -1
  558. package/dist/web/_app/immutable/assets/0.BZHoBJEc.css +2 -0
  559. package/dist/web/_app/immutable/assets/12.DlIf1mKh.css +1 -0
  560. package/dist/web/_app/immutable/assets/13.7d-Q37wc.css +1 -0
  561. package/dist/web/_app/immutable/assets/14.BwBFdc1D.css +1 -0
  562. package/dist/web/_app/immutable/assets/15.CmLrbzZp.css +1 -0
  563. package/dist/web/_app/immutable/assets/16.B0GwXar3.css +1 -0
  564. package/dist/web/_app/immutable/assets/2.C9Vt4JHy.css +1 -0
  565. package/dist/web/_app/immutable/assets/3.BFvgCYSk.css +1 -0
  566. package/dist/web/_app/immutable/assets/4.OmdYF47-.css +1 -0
  567. package/dist/web/_app/immutable/assets/5.C6MySjPq.css +1 -0
  568. package/dist/web/_app/immutable/assets/BulkActionsBar.Bx7nxMjH.css +1 -0
  569. package/dist/web/_app/immutable/assets/CalendarView.lBCvS3X5.css +1 -0
  570. package/dist/web/_app/immutable/assets/CodeMirrorEditor.D6hf2pNJ.css +1 -0
  571. package/dist/web/_app/immutable/assets/CopyField.DVGZtw4U.css +1 -0
  572. package/dist/web/_app/immutable/assets/FolderMembersPanel.DX1oBeF_.css +1 -0
  573. package/dist/web/_app/immutable/assets/FolderMutationDialogs.D2B7KrRn.css +1 -0
  574. package/dist/web/_app/immutable/assets/FolderPicker.B5KdvRYl.css +1 -0
  575. package/dist/web/_app/immutable/assets/GalleryView.CF48FWYQ.css +1 -0
  576. package/dist/web/_app/immutable/assets/GraphView.BJtGL9py.css +1 -0
  577. package/dist/web/_app/immutable/assets/KanbanView.BOaI5KFL.css +1 -0
  578. package/dist/web/_app/immutable/assets/Link.vV0ne105.css +1 -0
  579. package/dist/web/_app/immutable/assets/Markdown.BqgpZCv5.css +1 -0
  580. package/dist/web/_app/immutable/assets/Rail.f8lsriOT.css +1 -0
  581. package/dist/web/_app/immutable/assets/SettingsDialog.DwMus2u2.css +1 -0
  582. package/dist/web/_app/immutable/assets/Spinner.UBfl0pab.css +1 -0
  583. package/dist/web/_app/immutable/assets/StopFilledAlt.fNlDN65D.css +1 -0
  584. package/dist/web/_app/immutable/assets/TimelineView.DriOGAKB.css +1 -0
  585. package/dist/web/_app/immutable/assets/WorkspaceView.u5VdwRR6.css +1 -0
  586. package/dist/web/_app/immutable/assets/button.BlLm4Dg1.css +1 -0
  587. package/dist/web/_app/immutable/assets/checkbox.DK0MgYgb.css +1 -0
  588. package/dist/web/_app/immutable/assets/dist.DDCWxn3B.css +1 -0
  589. package/dist/web/_app/immutable/assets/ibm-plex-mono-latin-400-normal.CvHOgSBP.woff +0 -0
  590. package/dist/web/_app/immutable/assets/ibm-plex-mono-latin-400-normal.DMJ8VG8y.woff2 +0 -0
  591. package/dist/web/_app/immutable/assets/ibm-plex-mono-latin-500-normal.CB9ihrfo.woff +0 -0
  592. package/dist/web/_app/immutable/assets/ibm-plex-mono-latin-500-normal.DSY6xOcd.woff2 +0 -0
  593. package/dist/web/_app/immutable/assets/ibm-plex-sans-latin-400-italic.CZTNEAuW.woff2 +0 -0
  594. package/dist/web/_app/immutable/assets/ibm-plex-sans-latin-400-italic.CsGl1sm0.woff +0 -0
  595. package/dist/web/_app/immutable/assets/ibm-plex-sans-latin-400-normal.CDDApCn2.woff2 +0 -0
  596. package/dist/web/_app/immutable/assets/ibm-plex-sans-latin-400-normal.CYLoc0-x.woff +0 -0
  597. package/dist/web/_app/immutable/assets/ibm-plex-sans-latin-500-italic.BNK2_mGO.woff2 +0 -0
  598. package/dist/web/_app/immutable/assets/ibm-plex-sans-latin-500-italic.DpEwFAQM.woff +0 -0
  599. package/dist/web/_app/immutable/assets/ibm-plex-sans-latin-500-normal.6ng42L7E.woff2 +0 -0
  600. package/dist/web/_app/immutable/assets/ibm-plex-sans-latin-500-normal.BgVn5rGT.woff +0 -0
  601. package/dist/web/_app/immutable/assets/ibm-plex-sans-latin-600-normal.Cu4Hd6ag.woff +0 -0
  602. package/dist/web/_app/immutable/assets/ibm-plex-sans-latin-600-normal.CuJfVYMP.woff2 +0 -0
  603. package/dist/web/_app/immutable/assets/inline-list.cqga56xT.css +1 -0
  604. package/dist/web/_app/immutable/assets/list-columns.DiLB0G5L.css +1 -0
  605. package/dist/web/_app/immutable/assets/select.BFL238eD.css +1 -0
  606. package/dist/web/_app/immutable/assets/sheet.4rY4hpfJ.css +1 -0
  607. package/dist/web/_app/immutable/chunks/2oYV6q4R.js +2 -0
  608. package/dist/web/_app/immutable/chunks/4XSri7g0.js +1 -0
  609. package/dist/web/_app/immutable/chunks/4iaT0dG72.js +1 -0
  610. package/dist/web/_app/immutable/chunks/5_TKU9QS2.js +1 -0
  611. package/dist/web/_app/immutable/chunks/8Yh26Z9_2.js +1 -0
  612. package/dist/web/_app/immutable/chunks/Atl8xKOm.js +2 -0
  613. package/dist/web/_app/immutable/chunks/B-Z_xZy_.js +4 -0
  614. package/dist/web/_app/immutable/chunks/B0pk0Lyx.js +1 -0
  615. package/dist/web/_app/immutable/chunks/B1RnjnNt.js +1 -0
  616. package/dist/web/_app/immutable/chunks/B2n86UNJ.js +1 -0
  617. package/dist/web/_app/immutable/chunks/B318GEUB2.js +1 -0
  618. package/dist/web/_app/immutable/chunks/B6Lt-qaJ.js +1 -0
  619. package/dist/web/_app/immutable/chunks/B8yrQWxT2.js +1 -0
  620. package/dist/web/_app/immutable/chunks/BADt8daH.js +2 -0
  621. package/dist/web/_app/immutable/chunks/BBGt-XQo.js +3 -0
  622. package/dist/web/_app/immutable/chunks/BDIUHcEz.js +1 -0
  623. package/dist/web/_app/immutable/chunks/BDSuq3KH.js +1 -0
  624. package/dist/web/_app/immutable/chunks/BGiLU5VN.js +1 -0
  625. package/dist/web/_app/immutable/chunks/BJgOZTHR.js +1 -0
  626. package/dist/web/_app/immutable/chunks/BOSiTh-42.js +1 -0
  627. package/dist/web/_app/immutable/chunks/BPxcCdjn.js +1 -0
  628. package/dist/web/_app/immutable/chunks/BVPNAzAK.js +1 -0
  629. package/dist/web/_app/immutable/chunks/BcOvJgjM.js +1 -0
  630. package/dist/web/_app/immutable/chunks/BdYQewoD.js +1 -0
  631. package/dist/web/_app/immutable/chunks/BfCWIy8t.js +8 -0
  632. package/dist/web/_app/immutable/chunks/BgRT-K6w.js +5 -0
  633. package/dist/web/_app/immutable/chunks/BibveGGd.js +1 -0
  634. package/dist/web/_app/immutable/chunks/BmM5VZ4W.js +1 -0
  635. package/dist/web/_app/immutable/chunks/BnIYzuS1.js +66 -0
  636. package/dist/web/_app/immutable/chunks/BoDmwOTJ.js +1 -0
  637. package/dist/web/_app/immutable/chunks/BoglwbZW.js +1 -0
  638. package/dist/web/_app/immutable/chunks/Bqm_YrIg2.js +23 -0
  639. package/dist/web/_app/immutable/chunks/BtMRrdc4.js +2 -0
  640. package/dist/web/_app/immutable/chunks/C-AnzvKr.js +7 -0
  641. package/dist/web/_app/immutable/chunks/C1Y3tUpz.js +1 -0
  642. package/dist/web/_app/immutable/chunks/C6VZhhwF.js +1 -0
  643. package/dist/web/_app/immutable/chunks/C8IMrD4G2.js +3 -0
  644. package/dist/web/_app/immutable/chunks/CAXXrbj52.js +1 -0
  645. package/dist/web/_app/immutable/chunks/CB-0u-Pc2.js +1 -0
  646. package/dist/web/_app/immutable/chunks/CEniyZ1Z2.js +6 -0
  647. package/dist/web/_app/immutable/chunks/CJhElIkU2.js +1 -0
  648. package/dist/web/_app/immutable/chunks/CK8tIaYT.js +1 -0
  649. package/dist/web/_app/immutable/chunks/CM8uYli8.js +1 -0
  650. package/dist/web/_app/immutable/chunks/CTzjJm_m2.js +1 -0
  651. package/dist/web/_app/immutable/chunks/CUXqa1nn2.js +1 -0
  652. package/dist/web/_app/immutable/chunks/CY0iY_WO.js +1 -0
  653. package/dist/web/_app/immutable/chunks/CbCfNNV_2.js +2692 -0
  654. package/dist/web/_app/immutable/chunks/CbuGIyDu2.js +22 -0
  655. package/dist/web/_app/immutable/chunks/CcRGXA-t.js +1 -0
  656. package/dist/web/_app/immutable/chunks/CcXmQaYs2.js +1 -0
  657. package/dist/web/_app/immutable/chunks/CcaQuaSt2.js +1 -0
  658. package/dist/web/_app/immutable/chunks/CoHaBDpN2.js +2 -0
  659. package/dist/web/_app/immutable/chunks/Cvbd3myc2.js +14 -0
  660. package/dist/web/_app/immutable/chunks/D20C1thX2.js +1 -0
  661. package/dist/web/_app/immutable/chunks/D3JoMtWC.js +7 -0
  662. package/dist/web/_app/immutable/chunks/D3ch71s_.js +1 -0
  663. package/dist/web/_app/immutable/chunks/D4xXlMEU.js +2 -0
  664. package/dist/web/_app/immutable/chunks/D5GipQqN2.js +1 -0
  665. package/dist/web/_app/immutable/chunks/D9TyJuu_.js +1 -0
  666. package/dist/web/_app/immutable/chunks/DBFijAmG.js +1 -0
  667. package/dist/web/_app/immutable/chunks/DHLjkH7T.js +1 -0
  668. package/dist/web/_app/immutable/chunks/DIfdPIt_2.js +1 -0
  669. package/dist/web/_app/immutable/chunks/DO_sw49q2.js +1 -0
  670. package/dist/web/_app/immutable/chunks/DP69PpIj.js +1 -0
  671. package/dist/web/_app/immutable/chunks/DQ3HSZMs.js +2 -0
  672. package/dist/web/_app/immutable/chunks/DQMWa2t7.js +1 -0
  673. package/dist/web/_app/immutable/chunks/DT0wzK622.js +1 -0
  674. package/dist/web/_app/immutable/chunks/DTnEJArL.js +1 -0
  675. package/dist/web/_app/immutable/chunks/DToS-G202.js +1 -0
  676. package/dist/web/_app/immutable/chunks/DZcU6mGe2.js +1 -0
  677. package/dist/web/_app/immutable/chunks/DbslMybD.js +1 -0
  678. package/dist/web/_app/immutable/chunks/DcGThsSF.js +1 -0
  679. package/dist/web/_app/immutable/chunks/DcPrzUMJ.js +1 -0
  680. package/dist/web/_app/immutable/chunks/De0g5qop2.js +1 -0
  681. package/dist/web/_app/immutable/chunks/DimS8dbZ2.js +1 -0
  682. package/dist/web/_app/immutable/chunks/DjuqhOjF.js +1 -0
  683. package/dist/web/_app/immutable/chunks/Dk6sAhpo.js +3 -0
  684. package/dist/web/_app/immutable/chunks/Dl6cnwyk.js +1 -0
  685. package/dist/web/_app/immutable/chunks/DnIQzIOz.js +1 -0
  686. package/dist/web/_app/immutable/chunks/DnXYAo60.js +1 -0
  687. package/dist/web/_app/immutable/chunks/DnrImJan.js +1 -0
  688. package/dist/web/_app/immutable/chunks/Dpuq25vu2.js +1 -0
  689. package/dist/web/_app/immutable/chunks/DrMZDWru.js +1 -0
  690. package/dist/web/_app/immutable/chunks/DsVOtl0N.js +1 -0
  691. package/dist/web/_app/immutable/chunks/DuTXsWdP.js +2 -0
  692. package/dist/web/_app/immutable/chunks/Dw-frCfE.js +1 -0
  693. package/dist/web/_app/immutable/chunks/Dz34u8Ie2.js +185 -0
  694. package/dist/web/_app/immutable/chunks/DzcFeQZU2.js +2 -0
  695. package/dist/web/_app/immutable/chunks/DzrRTvug.js +1 -0
  696. package/dist/web/_app/immutable/chunks/G5oUVQa92.js +1 -0
  697. package/dist/web/_app/immutable/chunks/HyhOhoeq2.js +2 -0
  698. package/dist/web/_app/immutable/chunks/J5nb9xxj.js +1 -0
  699. package/dist/web/_app/immutable/chunks/JCjEwqH9.js +1 -0
  700. package/dist/web/_app/immutable/chunks/JN_nsXUm2.js +1 -0
  701. package/dist/web/_app/immutable/chunks/JS2_GaB1.js +1 -0
  702. package/dist/web/_app/immutable/chunks/MtI6dyxu.js +1 -0
  703. package/dist/web/_app/immutable/chunks/N6vnY5Si2.js +1 -0
  704. package/dist/web/_app/immutable/chunks/PcEbaKam.js +2 -0
  705. package/dist/web/_app/immutable/chunks/VTYhCLh9.js +2 -0
  706. package/dist/web/_app/immutable/chunks/Wowi_89k.js +5 -0
  707. package/dist/web/_app/immutable/chunks/Y_asqJqs2.js +83 -0
  708. package/dist/web/_app/immutable/chunks/Yhg5Q4MT.js +1 -0
  709. package/dist/web/_app/immutable/chunks/f_eYccPf2.js +1 -0
  710. package/dist/web/_app/immutable/chunks/hm_8RsuL.js +1 -0
  711. package/dist/web/_app/immutable/chunks/iPCkjliu.js +3 -0
  712. package/dist/web/_app/immutable/chunks/j2AvgZGz.js +1 -0
  713. package/dist/web/_app/immutable/chunks/kNaey6uv.js +1 -0
  714. package/dist/web/_app/immutable/chunks/l1761xxj.js +1 -0
  715. package/dist/web/_app/immutable/chunks/liGRFQqV2.js +184 -0
  716. package/dist/web/_app/immutable/chunks/lq1kR86d.js +1 -0
  717. package/dist/web/_app/immutable/chunks/mIykYR4F2.js +1 -0
  718. package/dist/web/_app/immutable/chunks/rbhlO_t8.js +1 -0
  719. package/dist/web/_app/immutable/chunks/tJpAwaTl.js +1 -0
  720. package/dist/web/_app/immutable/chunks/tcegdii0.js +2 -0
  721. package/dist/web/_app/immutable/chunks/u8G2EUvz2.js +224 -0
  722. package/dist/web/_app/immutable/chunks/vgsM0KTm2.js +1 -0
  723. package/dist/web/_app/immutable/chunks/xcGI4fuV.js +1 -0
  724. package/dist/web/_app/immutable/chunks/xihTtKlq.js +1 -0
  725. package/dist/web/_app/immutable/chunks/yEYlhV9G2.js +1 -0
  726. package/dist/web/_app/immutable/entry/app.DSf_XGp8.js +2 -0
  727. package/dist/web/_app/immutable/entry/start.B7ScfxPc.js +1 -0
  728. package/dist/web/_app/immutable/nodes/0.BMSOOETY.js +2 -0
  729. package/dist/web/_app/immutable/nodes/1.B0lBUpHt.js +1 -0
  730. package/dist/web/_app/immutable/nodes/10.DmDbUH1j.js +1 -0
  731. package/dist/web/_app/immutable/nodes/11.gwY7gZdR.js +1 -0
  732. package/dist/web/_app/immutable/nodes/12.BpGHSr2y.js +1 -0
  733. package/dist/web/_app/immutable/nodes/13.Bf178QF_.js +1 -0
  734. package/dist/web/_app/immutable/nodes/14.D_x8-nk9.js +1 -0
  735. package/dist/web/_app/immutable/nodes/15.DY4XeagL.js +1 -0
  736. package/dist/web/_app/immutable/nodes/16.DPqftx8x.js +77 -0
  737. package/dist/web/_app/immutable/nodes/2.OM2LGRpi.js +109 -0
  738. package/dist/web/_app/immutable/nodes/3.e8ZoPCmC.js +6 -0
  739. package/dist/web/_app/immutable/nodes/4.BdYR1hNQ.js +11 -0
  740. package/dist/web/_app/immutable/nodes/5.B8sOFna9.js +5 -0
  741. package/dist/web/_app/immutable/nodes/6.L1BbYsmo.js +1 -0
  742. package/dist/web/_app/immutable/nodes/7.B7zoemJD.js +1 -0
  743. package/dist/web/_app/immutable/nodes/8.B1VtnfMK.js +1 -0
  744. package/dist/web/_app/immutable/nodes/9.BE3VCQzk.js +1 -0
  745. package/dist/web/_app/version.json +1 -1
  746. package/dist/web/favicon-16.png +0 -0
  747. package/dist/web/favicon-180.png +0 -0
  748. package/dist/web/favicon-32.png +0 -0
  749. package/dist/web/favicon-48.png +0 -0
  750. package/dist/web/favicon-512.png +0 -0
  751. package/dist/web/favicon.ico +0 -0
  752. package/dist/web/favicon.svg +8 -0
  753. package/dist/web/index.html +58 -19
  754. package/dist/web/studiograph-logomark.svg +29 -0
  755. package/package.json +38 -14
  756. package/dist/agent/skills/enrich-entities.md +0 -136
  757. package/dist/agent/skills/obsidian-source-setup.md +0 -246
  758. package/dist/agent/skills/skill-loader.d.ts +0 -48
  759. package/dist/agent/skills/skill-loader.js +0 -166
  760. package/dist/agent/skills/skill-loader.js.map +0 -1
  761. package/dist/agent/skills/sync-configuration.md +0 -119
  762. package/dist/agent/skills/sync-setup.md +0 -82
  763. package/dist/agent/tools/sync-tools.d.ts +0 -35
  764. package/dist/agent/tools/sync-tools.js +0 -992
  765. package/dist/agent/tools/sync-tools.js.map +0 -1
  766. package/dist/auth/github.d.ts +0 -56
  767. package/dist/auth/github.js +0 -169
  768. package/dist/auth/github.js.map +0 -1
  769. package/dist/cli/commands/access.d.ts +0 -11
  770. package/dist/cli/commands/access.js +0 -156
  771. package/dist/cli/commands/access.js.map +0 -1
  772. package/dist/cli/commands/app.d.ts +0 -7
  773. package/dist/cli/commands/app.js +0 -268
  774. package/dist/cli/commands/app.js.map +0 -1
  775. package/dist/cli/commands/auth.d.ts +0 -10
  776. package/dist/cli/commands/auth.js +0 -79
  777. package/dist/cli/commands/auth.js.map +0 -1
  778. package/dist/cli/commands/clear.d.ts +0 -5
  779. package/dist/cli/commands/clear.js +0 -36
  780. package/dist/cli/commands/clear.js.map +0 -1
  781. package/dist/cli/commands/collection.d.ts +0 -10
  782. package/dist/cli/commands/collection.js +0 -187
  783. package/dist/cli/commands/collection.js.map +0 -1
  784. package/dist/cli/commands/enrich.d.ts +0 -11
  785. package/dist/cli/commands/enrich.js +0 -135
  786. package/dist/cli/commands/enrich.js.map +0 -1
  787. package/dist/cli/commands/graphrag.d.ts +0 -12
  788. package/dist/cli/commands/graphrag.js +0 -122
  789. package/dist/cli/commands/graphrag.js.map +0 -1
  790. package/dist/cli/commands/join.d.ts +0 -9
  791. package/dist/cli/commands/join.js +0 -255
  792. package/dist/cli/commands/join.js.map +0 -1
  793. package/dist/cli/commands/members.d.ts +0 -11
  794. package/dist/cli/commands/members.js +0 -230
  795. package/dist/cli/commands/members.js.map +0 -1
  796. package/dist/cli/commands/org.d.ts +0 -10
  797. package/dist/cli/commands/org.js +0 -132
  798. package/dist/cli/commands/org.js.map +0 -1
  799. package/dist/cli/commands/provision.d.ts +0 -8
  800. package/dist/cli/commands/provision.js +0 -116
  801. package/dist/cli/commands/provision.js.map +0 -1
  802. package/dist/cli/commands/resolve.d.ts +0 -8
  803. package/dist/cli/commands/resolve.js +0 -85
  804. package/dist/cli/commands/resolve.js.map +0 -1
  805. package/dist/cli/commands/review.d.ts +0 -19
  806. package/dist/cli/commands/review.js +0 -128
  807. package/dist/cli/commands/review.js.map +0 -1
  808. package/dist/cli/commands/source.d.ts +0 -16
  809. package/dist/cli/commands/source.js +0 -159
  810. package/dist/cli/commands/source.js.map +0 -1
  811. package/dist/cli/commands/start.d.ts +0 -7
  812. package/dist/cli/commands/start.js +0 -589
  813. package/dist/cli/commands/start.js.map +0 -1
  814. package/dist/cli/commands/sync-collection.d.ts +0 -14
  815. package/dist/cli/commands/sync-collection.js +0 -355
  816. package/dist/cli/commands/sync-collection.js.map +0 -1
  817. package/dist/cli/commands/sync-entities.d.ts +0 -13
  818. package/dist/cli/commands/sync-entities.js +0 -242
  819. package/dist/cli/commands/sync-entities.js.map +0 -1
  820. package/dist/cli/commands/team.d.ts +0 -12
  821. package/dist/cli/commands/team.js +0 -185
  822. package/dist/cli/commands/team.js.map +0 -1
  823. package/dist/cli/commands/update.d.ts +0 -8
  824. package/dist/cli/commands/update.js +0 -155
  825. package/dist/cli/commands/update.js.map +0 -1
  826. package/dist/cli/commands/user.d.ts +0 -7
  827. package/dist/cli/commands/user.js +0 -153
  828. package/dist/cli/commands/user.js.map +0 -1
  829. package/dist/cli/scaffolding.d.ts +0 -12
  830. package/dist/cli/scaffolding.js +0 -397
  831. package/dist/cli/scaffolding.js.map +0 -1
  832. package/dist/cli/sync-review-interactive.d.ts +0 -31
  833. package/dist/cli/sync-review-interactive.js +0 -393
  834. package/dist/cli/sync-review-interactive.js.map +0 -1
  835. package/dist/core/migration-runner.d.ts +0 -42
  836. package/dist/core/migration-runner.js +0 -232
  837. package/dist/core/migration-runner.js.map +0 -1
  838. package/dist/core/migration-types.d.ts +0 -101
  839. package/dist/core/migration-types.js +0 -21
  840. package/dist/core/migration-types.js.map +0 -1
  841. package/dist/core/migrations/20260219-formalize-memory-location.d.ts +0 -2
  842. package/dist/core/migrations/20260219-formalize-memory-location.js +0 -35
  843. package/dist/core/migrations/20260219-formalize-memory-location.js.map +0 -1
  844. package/dist/core/migrations/20260220-add-workspace-metadata.d.ts +0 -12
  845. package/dist/core/migrations/20260220-add-workspace-metadata.js +0 -65
  846. package/dist/core/migrations/20260220-add-workspace-metadata.js.map +0 -1
  847. package/dist/core/migrations/20260220-add-workspace-readme.d.ts +0 -11
  848. package/dist/core/migrations/20260220-add-workspace-readme.js +0 -82
  849. package/dist/core/migrations/20260220-add-workspace-readme.js.map +0 -1
  850. package/dist/core/migrations/20260220-migrate-yaml-to-json.d.ts +0 -9
  851. package/dist/core/migrations/20260220-migrate-yaml-to-json.js +0 -64
  852. package/dist/core/migrations/20260220-migrate-yaml-to-json.js.map +0 -1
  853. package/dist/core/migrations/index.d.ts +0 -11
  854. package/dist/core/migrations/index.js +0 -23
  855. package/dist/core/migrations/index.js.map +0 -1
  856. package/dist/integrations/asana.d.ts +0 -26
  857. package/dist/integrations/asana.js +0 -78
  858. package/dist/integrations/asana.js.map +0 -1
  859. package/dist/integrations/figma-local.d.ts +0 -16
  860. package/dist/integrations/figma-local.js +0 -10
  861. package/dist/integrations/figma-local.js.map +0 -1
  862. package/dist/integrations/figma.d.ts +0 -17
  863. package/dist/integrations/figma.js +0 -17
  864. package/dist/integrations/figma.js.map +0 -1
  865. package/dist/integrations/granola.d.ts +0 -24
  866. package/dist/integrations/granola.js +0 -60
  867. package/dist/integrations/granola.js.map +0 -1
  868. package/dist/integrations/linear.d.ts +0 -14
  869. package/dist/integrations/linear.js +0 -80
  870. package/dist/integrations/linear.js.map +0 -1
  871. package/dist/integrations/paper-local.d.ts +0 -14
  872. package/dist/integrations/paper-local.js +0 -10
  873. package/dist/integrations/paper-local.js.map +0 -1
  874. package/dist/integrations/paper.d.ts +0 -2
  875. package/dist/integrations/paper.js +0 -10
  876. package/dist/integrations/paper.js.map +0 -1
  877. package/dist/integrations/pipedrive.d.ts +0 -26
  878. package/dist/integrations/pipedrive.js +0 -97
  879. package/dist/integrations/pipedrive.js.map +0 -1
  880. package/dist/integrations/registry.d.ts +0 -15
  881. package/dist/integrations/registry.js +0 -27
  882. package/dist/integrations/registry.js.map +0 -1
  883. package/dist/integrations/types.d.ts +0 -38
  884. package/dist/integrations/types.js +0 -9
  885. package/dist/integrations/types.js.map +0 -1
  886. package/dist/lib/lib/utils.d.ts +0 -2
  887. package/dist/lib/lib/utils.js +0 -6
  888. package/dist/lib/lib/utils.js.map +0 -1
  889. package/dist/mcp/connectors/asana.d.ts +0 -2
  890. package/dist/mcp/connectors/asana.js +0 -20
  891. package/dist/mcp/connectors/asana.js.map +0 -1
  892. package/dist/mcp/connectors/definitions.d.ts +0 -45
  893. package/dist/mcp/connectors/definitions.js +0 -32
  894. package/dist/mcp/connectors/definitions.js.map +0 -1
  895. package/dist/mcp/connectors/figma.d.ts +0 -5
  896. package/dist/mcp/connectors/figma.js +0 -21
  897. package/dist/mcp/connectors/figma.js.map +0 -1
  898. package/dist/mcp/connectors/gdrive.d.ts +0 -2
  899. package/dist/mcp/connectors/gdrive.js +0 -20
  900. package/dist/mcp/connectors/gdrive.js.map +0 -1
  901. package/dist/mcp/connectors/granola.d.ts +0 -2
  902. package/dist/mcp/connectors/granola.js +0 -12
  903. package/dist/mcp/connectors/granola.js.map +0 -1
  904. package/dist/mcp/connectors/linear.d.ts +0 -2
  905. package/dist/mcp/connectors/linear.js +0 -19
  906. package/dist/mcp/connectors/linear.js.map +0 -1
  907. package/dist/mcp/connectors/obsidian.d.ts +0 -2
  908. package/dist/mcp/connectors/obsidian.js +0 -19
  909. package/dist/mcp/connectors/obsidian.js.map +0 -1
  910. package/dist/mcp/connectors/pipedrive.d.ts +0 -2
  911. package/dist/mcp/connectors/pipedrive.js +0 -20
  912. package/dist/mcp/connectors/pipedrive.js.map +0 -1
  913. package/dist/mcp/connectors/slack.d.ts +0 -2
  914. package/dist/mcp/connectors/slack.js +0 -21
  915. package/dist/mcp/connectors/slack.js.map +0 -1
  916. package/dist/mcp/server-oauth-provider.d.ts +0 -56
  917. package/dist/mcp/server-oauth-provider.js +0 -142
  918. package/dist/mcp/server-oauth-provider.js.map +0 -1
  919. package/dist/server/chrome/chrome.css +0 -691
  920. package/dist/server/chrome/chrome.js +0 -374
  921. package/dist/server/collab-authority.d.ts +0 -70
  922. package/dist/server/collab-authority.js +0 -218
  923. package/dist/server/collab-authority.js.map +0 -1
  924. package/dist/server/collab.d.ts +0 -29
  925. package/dist/server/collab.js +0 -195
  926. package/dist/server/collab.js.map +0 -1
  927. package/dist/server/commit-scheduler.d.ts +0 -39
  928. package/dist/server/commit-scheduler.js +0 -113
  929. package/dist/server/commit-scheduler.js.map +0 -1
  930. package/dist/server/plugin-loader.d.ts +0 -53
  931. package/dist/server/plugin-loader.js +0 -155
  932. package/dist/server/plugin-loader.js.map +0 -1
  933. package/dist/server/routes/collab.d.ts +0 -6
  934. package/dist/server/routes/collab.js +0 -10
  935. package/dist/server/routes/collab.js.map +0 -1
  936. package/dist/server/routes/git-api.d.ts +0 -9
  937. package/dist/server/routes/git-api.js +0 -82
  938. package/dist/server/routes/git-api.js.map +0 -1
  939. package/dist/server/routes/meeting-ingest-api.d.ts +0 -15
  940. package/dist/server/routes/meeting-ingest-api.js +0 -323
  941. package/dist/server/routes/meeting-ingest-api.js.map +0 -1
  942. package/dist/server/routes/sync-api.d.ts +0 -26
  943. package/dist/server/routes/sync-api.js +0 -814
  944. package/dist/server/routes/sync-api.js.map +0 -1
  945. package/dist/server/routes/webhook.d.ts +0 -14
  946. package/dist/server/routes/webhook.js +0 -102
  947. package/dist/server/routes/webhook.js.map +0 -1
  948. package/dist/services/github-provisioner.d.ts +0 -36
  949. package/dist/services/github-provisioner.js +0 -126
  950. package/dist/services/github-provisioner.js.map +0 -1
  951. package/dist/services/github-service.d.ts +0 -99
  952. package/dist/services/github-service.js +0 -310
  953. package/dist/services/github-service.js.map +0 -1
  954. package/dist/services/insights.d.ts +0 -38
  955. package/dist/services/insights.js +0 -246
  956. package/dist/services/insights.js.map +0 -1
  957. package/dist/services/sync/collection-sync.d.ts +0 -60
  958. package/dist/services/sync/collection-sync.js +0 -509
  959. package/dist/services/sync/collection-sync.js.map +0 -1
  960. package/dist/services/sync/commit.d.ts +0 -60
  961. package/dist/services/sync/commit.js +0 -354
  962. package/dist/services/sync/commit.js.map +0 -1
  963. package/dist/services/sync/context-index.d.ts +0 -69
  964. package/dist/services/sync/context-index.js +0 -280
  965. package/dist/services/sync/context-index.js.map +0 -1
  966. package/dist/services/sync/data-fetcher.d.ts +0 -31
  967. package/dist/services/sync/data-fetcher.js +0 -12
  968. package/dist/services/sync/data-fetcher.js.map +0 -1
  969. package/dist/services/sync/derive.d.ts +0 -34
  970. package/dist/services/sync/derive.js +0 -164
  971. package/dist/services/sync/derive.js.map +0 -1
  972. package/dist/services/sync/enrichment-state.d.ts +0 -31
  973. package/dist/services/sync/enrichment-state.js +0 -63
  974. package/dist/services/sync/enrichment-state.js.map +0 -1
  975. package/dist/services/sync/enrichment.d.ts +0 -25
  976. package/dist/services/sync/enrichment.js +0 -121
  977. package/dist/services/sync/enrichment.js.map +0 -1
  978. package/dist/services/sync/entity-refresh.d.ts +0 -30
  979. package/dist/services/sync/entity-refresh.js +0 -275
  980. package/dist/services/sync/entity-refresh.js.map +0 -1
  981. package/dist/services/sync/frontmatter-extractor.d.ts +0 -40
  982. package/dist/services/sync/frontmatter-extractor.js +0 -279
  983. package/dist/services/sync/frontmatter-extractor.js.map +0 -1
  984. package/dist/services/sync/graph-match-state.d.ts +0 -33
  985. package/dist/services/sync/graph-match-state.js +0 -61
  986. package/dist/services/sync/graph-match-state.js.map +0 -1
  987. package/dist/services/sync/graph-match.d.ts +0 -53
  988. package/dist/services/sync/graph-match.js +0 -316
  989. package/dist/services/sync/graph-match.js.map +0 -1
  990. package/dist/services/sync/graphrag-client.d.ts +0 -43
  991. package/dist/services/sync/graphrag-client.js +0 -94
  992. package/dist/services/sync/graphrag-client.js.map +0 -1
  993. package/dist/services/sync/graphrag-config.d.ts +0 -16
  994. package/dist/services/sync/graphrag-config.js +0 -39
  995. package/dist/services/sync/graphrag-config.js.map +0 -1
  996. package/dist/services/sync/graphrag-context.d.ts +0 -14
  997. package/dist/services/sync/graphrag-context.js +0 -109
  998. package/dist/services/sync/graphrag-context.js.map +0 -1
  999. package/dist/services/sync/graphrag-indexer.d.ts +0 -30
  1000. package/dist/services/sync/graphrag-indexer.js +0 -358
  1001. package/dist/services/sync/graphrag-indexer.js.map +0 -1
  1002. package/dist/services/sync/llm.d.ts +0 -32
  1003. package/dist/services/sync/llm.js +0 -115
  1004. package/dist/services/sync/llm.js.map +0 -1
  1005. package/dist/services/sync/mcp-client.d.ts +0 -71
  1006. package/dist/services/sync/mcp-client.js +0 -299
  1007. package/dist/services/sync/mcp-client.js.map +0 -1
  1008. package/dist/services/sync/model-factory.d.ts +0 -13
  1009. package/dist/services/sync/model-factory.js +0 -38
  1010. package/dist/services/sync/model-factory.js.map +0 -1
  1011. package/dist/services/sync/name-quality.d.ts +0 -31
  1012. package/dist/services/sync/name-quality.js +0 -60
  1013. package/dist/services/sync/name-quality.js.map +0 -1
  1014. package/dist/services/sync/output-schemas.d.ts +0 -92
  1015. package/dist/services/sync/output-schemas.js +0 -43
  1016. package/dist/services/sync/output-schemas.js.map +0 -1
  1017. package/dist/services/sync/prompts.d.ts +0 -19
  1018. package/dist/services/sync/prompts.js +0 -128
  1019. package/dist/services/sync/prompts.js.map +0 -1
  1020. package/dist/services/sync/reconciler.d.ts +0 -48
  1021. package/dist/services/sync/reconciler.js +0 -294
  1022. package/dist/services/sync/reconciler.js.map +0 -1
  1023. package/dist/services/sync/rest-client.d.ts +0 -40
  1024. package/dist/services/sync/rest-client.js +0 -100
  1025. package/dist/services/sync/rest-client.js.map +0 -1
  1026. package/dist/services/sync/source-config.d.ts +0 -67
  1027. package/dist/services/sync/source-config.js +0 -304
  1028. package/dist/services/sync/source-config.js.map +0 -1
  1029. package/dist/services/sync/source-definitions/asana.d.ts +0 -14
  1030. package/dist/services/sync/source-definitions/asana.js +0 -42
  1031. package/dist/services/sync/source-definitions/asana.js.map +0 -1
  1032. package/dist/services/sync/source-definitions/definitions.d.ts +0 -8
  1033. package/dist/services/sync/source-definitions/definitions.js +0 -8
  1034. package/dist/services/sync/source-definitions/definitions.js.map +0 -1
  1035. package/dist/services/sync/source-definitions/gdrive.d.ts +0 -16
  1036. package/dist/services/sync/source-definitions/gdrive.js +0 -68
  1037. package/dist/services/sync/source-definitions/gdrive.js.map +0 -1
  1038. package/dist/services/sync/source-definitions/granola.d.ts +0 -2
  1039. package/dist/services/sync/source-definitions/granola.js +0 -21
  1040. package/dist/services/sync/source-definitions/granola.js.map +0 -1
  1041. package/dist/services/sync/source-definitions/linear.d.ts +0 -2
  1042. package/dist/services/sync/source-definitions/linear.js +0 -62
  1043. package/dist/services/sync/source-definitions/linear.js.map +0 -1
  1044. package/dist/services/sync/source-definitions/obsidian.d.ts +0 -2
  1045. package/dist/services/sync/source-definitions/obsidian.js +0 -55
  1046. package/dist/services/sync/source-definitions/obsidian.js.map +0 -1
  1047. package/dist/services/sync/source-definitions/pipedrive.d.ts +0 -2
  1048. package/dist/services/sync/source-definitions/pipedrive.js +0 -43
  1049. package/dist/services/sync/source-definitions/pipedrive.js.map +0 -1
  1050. package/dist/services/sync/staging.d.ts +0 -53
  1051. package/dist/services/sync/staging.js +0 -130
  1052. package/dist/services/sync/staging.js.map +0 -1
  1053. package/dist/services/sync/structured-extractor.d.ts +0 -57
  1054. package/dist/services/sync/structured-extractor.js +0 -584
  1055. package/dist/services/sync/structured-extractor.js.map +0 -1
  1056. package/dist/services/sync/sync-runner.d.ts +0 -32
  1057. package/dist/services/sync/sync-runner.js +0 -195
  1058. package/dist/services/sync/sync-runner.js.map +0 -1
  1059. package/dist/services/sync/sync-state.d.ts +0 -43
  1060. package/dist/services/sync/sync-state.js +0 -154
  1061. package/dist/services/sync/sync-state.js.map +0 -1
  1062. package/dist/services/sync/types.d.ts +0 -381
  1063. package/dist/services/sync/types.js +0 -8
  1064. package/dist/services/sync/types.js.map +0 -1
  1065. package/dist/services/sync/unstructured-extractor.d.ts +0 -27
  1066. package/dist/services/sync/unstructured-extractor.js +0 -185
  1067. package/dist/services/sync/unstructured-extractor.js.map +0 -1
  1068. package/dist/utils/merge-resolver.d.ts +0 -59
  1069. package/dist/utils/merge-resolver.js +0 -303
  1070. package/dist/utils/merge-resolver.js.map +0 -1
  1071. package/dist/utils/workspace-config.d.ts +0 -8
  1072. package/dist/utils/workspace-config.js +0 -22
  1073. package/dist/utils/workspace-config.js.map +0 -1
  1074. package/dist/web/_app/immutable/assets/0.DdizXOKi.css +0 -1
  1075. package/dist/web/_app/immutable/assets/10.BUrHkYry.css +0 -1
  1076. package/dist/web/_app/immutable/assets/2.n7-yW_Fs.css +0 -1
  1077. package/dist/web/_app/immutable/assets/3.BtaZagnv.css +0 -1
  1078. package/dist/web/_app/immutable/assets/4.DT7X0x5S.css +0 -1
  1079. package/dist/web/_app/immutable/assets/5.DFeGxLYf.css +0 -1
  1080. package/dist/web/_app/immutable/assets/6.CquhUpOu.css +0 -1
  1081. package/dist/web/_app/immutable/assets/7.CjbDRbuG.css +0 -1
  1082. package/dist/web/_app/immutable/assets/8.S1QdUGNM.css +0 -1
  1083. package/dist/web/_app/immutable/assets/9.CT4xL4K3.css +0 -1
  1084. package/dist/web/_app/immutable/assets/Copy.FS8bdfxr.css +0 -1
  1085. package/dist/web/_app/immutable/assets/Toaster.rN8r_Hzv.css +0 -1
  1086. package/dist/web/_app/immutable/assets/ViewToolbar.D-QW2oKe.css +0 -1
  1087. package/dist/web/_app/immutable/assets/index.D6tMDJWk.css +0 -1
  1088. package/dist/web/_app/immutable/chunks/-iaeBIWN.js +0 -1
  1089. package/dist/web/_app/immutable/chunks/37NdyH6G.js +0 -32
  1090. package/dist/web/_app/immutable/chunks/4Hhzb6pv.js +0 -1
  1091. package/dist/web/_app/immutable/chunks/72bZS3G9.js +0 -1
  1092. package/dist/web/_app/immutable/chunks/7S2LGqoP.js +0 -2
  1093. package/dist/web/_app/immutable/chunks/B340SUKR.js +0 -1
  1094. package/dist/web/_app/immutable/chunks/B3Z4_Sps.js +0 -1
  1095. package/dist/web/_app/immutable/chunks/BB_5th5W.js +0 -3383
  1096. package/dist/web/_app/immutable/chunks/BPWYOQXG.js +0 -1
  1097. package/dist/web/_app/immutable/chunks/BR77jbfR.js +0 -1
  1098. package/dist/web/_app/immutable/chunks/BS2rFAVq.js +0 -1
  1099. package/dist/web/_app/immutable/chunks/BSsDC_p4.js +0 -1
  1100. package/dist/web/_app/immutable/chunks/BTX2Jr8_.js +0 -1
  1101. package/dist/web/_app/immutable/chunks/Bq_KShUL.js +0 -4
  1102. package/dist/web/_app/immutable/chunks/Bsacq2UX.js +0 -1
  1103. package/dist/web/_app/immutable/chunks/ByunV8un.js +0 -1
  1104. package/dist/web/_app/immutable/chunks/BzPu-Eht.js +0 -1
  1105. package/dist/web/_app/immutable/chunks/C7VoTosa.js +0 -2
  1106. package/dist/web/_app/immutable/chunks/CDV5Q7RN.js +0 -1
  1107. package/dist/web/_app/immutable/chunks/CGc1sIb_.js +0 -1
  1108. package/dist/web/_app/immutable/chunks/CJ8__CWt.js +0 -1
  1109. package/dist/web/_app/immutable/chunks/CJUKmosC.js +0 -5
  1110. package/dist/web/_app/immutable/chunks/CSVbGg_b.js +0 -5
  1111. package/dist/web/_app/immutable/chunks/CT6oIU-C.js +0 -1
  1112. package/dist/web/_app/immutable/chunks/CTRxNfZk.js +0 -1
  1113. package/dist/web/_app/immutable/chunks/CWQRQXxy.js +0 -1
  1114. package/dist/web/_app/immutable/chunks/CX87mIM8.js +0 -1
  1115. package/dist/web/_app/immutable/chunks/CXH6iFbA.js +0 -1
  1116. package/dist/web/_app/immutable/chunks/CX_61fY8.js +0 -5
  1117. package/dist/web/_app/immutable/chunks/CYrVHOHA.js +0 -1
  1118. package/dist/web/_app/immutable/chunks/CdeYcEuU.js +0 -1
  1119. package/dist/web/_app/immutable/chunks/CmCtpZ1Y.js +0 -1
  1120. package/dist/web/_app/immutable/chunks/Cpsr8-Xy.js +0 -1
  1121. package/dist/web/_app/immutable/chunks/CqkleIqs.js +0 -1
  1122. package/dist/web/_app/immutable/chunks/CrdV0ttd.js +0 -1
  1123. package/dist/web/_app/immutable/chunks/CscoF-YL.js +0 -18
  1124. package/dist/web/_app/immutable/chunks/Cx4YdFMk.js +0 -1
  1125. package/dist/web/_app/immutable/chunks/D7ZqAKi9.js +0 -3
  1126. package/dist/web/_app/immutable/chunks/DGbA7IXh.js +0 -2
  1127. package/dist/web/_app/immutable/chunks/DTZE-yoq.js +0 -2
  1128. package/dist/web/_app/immutable/chunks/DbbB6Up5.js +0 -1
  1129. package/dist/web/_app/immutable/chunks/DnL9f0lc.js +0 -7
  1130. package/dist/web/_app/immutable/chunks/DtM5cEDu.js +0 -1
  1131. package/dist/web/_app/immutable/chunks/Eqahi7_S.js +0 -2
  1132. package/dist/web/_app/immutable/chunks/O9Eb9k00.js +0 -1
  1133. package/dist/web/_app/immutable/chunks/PPVm8Dsz.js +0 -1
  1134. package/dist/web/_app/immutable/chunks/QF8MAmnc.js +0 -1
  1135. package/dist/web/_app/immutable/chunks/UjzxCpxn.js +0 -1
  1136. package/dist/web/_app/immutable/chunks/WSUKABI_.js +0 -1
  1137. package/dist/web/_app/immutable/chunks/Y90OgS-9.js +0 -1
  1138. package/dist/web/_app/immutable/chunks/cLyZlkXv.js +0 -1
  1139. package/dist/web/_app/immutable/chunks/iDtAARVW.js +0 -2
  1140. package/dist/web/_app/immutable/chunks/oC_W7W7p.js +0 -1
  1141. package/dist/web/_app/immutable/chunks/rJdWIgh-.js +0 -1
  1142. package/dist/web/_app/immutable/chunks/tvOsokaa.js +0 -1
  1143. package/dist/web/_app/immutable/chunks/uLEXaPwE.js +0 -1
  1144. package/dist/web/_app/immutable/chunks/vSaooFHB.js +0 -1
  1145. package/dist/web/_app/immutable/entry/app.BeUKh4sD.js +0 -2
  1146. package/dist/web/_app/immutable/entry/start.CZJnFuQn.js +0 -1
  1147. package/dist/web/_app/immutable/nodes/0.DyF_RsLg.js +0 -2
  1148. package/dist/web/_app/immutable/nodes/1.7iDQmMPh.js +0 -1
  1149. package/dist/web/_app/immutable/nodes/10.Btl8d8HT.js +0 -1
  1150. package/dist/web/_app/immutable/nodes/2.LDRE62jN.js +0 -168
  1151. package/dist/web/_app/immutable/nodes/3.BaW1XB1x.js +0 -1
  1152. package/dist/web/_app/immutable/nodes/4.D0Q8kpkI.js +0 -12
  1153. package/dist/web/_app/immutable/nodes/5.n7j2UG9h.js +0 -4
  1154. package/dist/web/_app/immutable/nodes/6.DQYxR0iy.js +0 -2
  1155. package/dist/web/_app/immutable/nodes/7.BsURvFAp.js +0 -2
  1156. package/dist/web/_app/immutable/nodes/8.CsiErG0p.js +0 -1
  1157. package/dist/web/_app/immutable/nodes/9.CnN6OZgC.js +0 -1
package/dist/mcp/tools.js CHANGED
@@ -5,11 +5,36 @@
5
5
  * methods — no new business logic. Results are returned as JSON text so the
6
6
  * MCP client (Claude Desktop) can process structured data.
7
7
  *
8
+ * Every tool enforces per-user access control via `services/access-control.ts`.
9
+ * Callers (the HTTP /mcp route, the stdio MCP server) must resolve a user
10
+ * identity before registering tools — `registerTools` requires a user in its
11
+ * `McpAccessContext` argument so there is no anonymous MCP path.
12
+ *
8
13
  * Note: `inputSchema` is cast to `any` at each call site because the MCP SDK's
9
14
  * ZodRawShapeCompat type does not accept ZodObject in TypeScript's strict mode.
10
15
  * Runtime schema validation is handled correctly by the SDK regardless.
11
16
  */
12
17
  import { z } from 'zod';
18
+ import { ENTITY_SCHEMAS } from '../core/validation.js';
19
+ import { getAccessibleRepos, hasRepoAccess, canWriteRepo, getAccessibleEntityIds, filterWikilinks, } from '../services/access-control.js';
20
+ import { createSharedFolder, FolderCreationError } from '../services/folder-creation.js';
21
+ import { validateFolderPath } from '../core/folder-paths.js';
22
+ import { existsSync } from 'fs';
23
+ import { join } from 'path';
24
+ import { isCuratedEntityType } from '../core/entity-types-catalog.js';
25
+ import { getAgentAllowedEntityTypes } from '../agent/prompts/entity-types-section.js';
26
+ import * as commentVirtualEntity from './comment-virtual-entity.js';
27
+ import { buildActor, prepareCreatePayload, prepareUpdatePayload, diagnosedUpdate, DroppedAssetError, assertEntityRefs, } from '../services/entity-mutations.js';
28
+ import { BridgeError, validateUserHandleInPayload, assertCanChangeUserHandle } from '../services/user-person-bridge.js';
29
+ import { extractAssetEmbeds, stripFrontmatter, assetEmbed } from '../core/embeds.js';
30
+ import { listRepoAssets } from '../services/asset-listing.js';
31
+ import { presignAssetUpload } from '../services/asset-presign-service.js';
32
+ import { finalizeAssetUpload } from '../services/asset-finalize-service.js';
33
+ import { importAssetAsEntity } from '../services/asset-import-service.js';
34
+ import { AssetUploadError } from '../services/asset-upload-errors.js';
35
+ import { presignMimeAllowlist, inlineUploadMimeAllowlist, resolveFormat, isInlineUploadAllowed } from '../core/format-registry.js';
36
+ import { resolveWorkspaceAssetsRepo } from '../services/workspace-assets-folder.js';
37
+ import { Workspace } from '../core/workspace.js';
13
38
  // ── helpers ───────────────────────────────────────────────────────────────────
14
39
  function ok(data) {
15
40
  return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
@@ -18,30 +43,198 @@ function fail(err) {
18
43
  const msg = err instanceof Error ? err.message : String(err);
19
44
  return { content: [{ type: 'text', text: msg }], isError: true };
20
45
  }
46
+ /** Deny-without-leaking helper — same wording as a missing repo/entity. */
47
+ function notFound(repo) {
48
+ return fail(new Error(`Folder "${repo}" not found`));
49
+ }
50
+ /**
51
+ * Map an AssetUploadError (or any Error with a stable `code` discriminator)
52
+ * onto the MCP `fail()` envelope, embedding the code so the client can
53
+ * branch programmatically. Wraps `fail()` rather than replacing it so any
54
+ * non-typed error falls through to the existing "unknown" path.
55
+ *
56
+ * The code makes its way into the text payload as a JSON object — MCP
57
+ * clients that parse the text get a structured shape; pure-text consumers
58
+ * still get a readable line.
59
+ */
60
+ function errorToMcpResult(err) {
61
+ if (err instanceof AssetUploadError) {
62
+ return {
63
+ content: [{
64
+ type: 'text',
65
+ text: JSON.stringify({ error: err.message, code: err.code }, null, 2),
66
+ }],
67
+ isError: true,
68
+ };
69
+ }
70
+ return fail(err);
71
+ }
21
72
  // Strip frontmatter fields that duplicate the top-level id/type keys
22
73
  function shape(id, entityType, data, extra) {
23
74
  const { id: _id, entity_type: _et, ...rest } = data;
24
75
  return { id, type: entityType, ...rest, ...extra };
25
76
  }
77
+ /**
78
+ * Default subfolders for entity types when the caller omits `folder_path`.
79
+ * Existing entries with no folder live at the repo root; new entries of these
80
+ * types route into a typed subfolder so the repo stays organised by default.
81
+ * An explicit `folder_path: ""` (or any explicit value) overrides this map.
82
+ */
83
+ const DEFAULT_FOLDER_BY_TYPE = {
84
+ person: 'People',
85
+ organization: 'Organizations',
86
+ };
87
+ /** Convert an absolute entity path to a repo-relative POSIX path. */
88
+ function relPathOf(absPath, repoRoot) {
89
+ return absPath.startsWith(repoRoot + '/') ? absPath.slice(repoRoot.length + 1) : absPath;
90
+ }
91
+ /**
92
+ * Presign MIME enum for `create_asset_upload`, derived from the format registry
93
+ * (P4-V1) so the tool's accepted set can't drift from the presign service's gate.
94
+ * z.enum needs a non-empty tuple; the registry always yields ≥1 image MIME, but
95
+ * fall back to png/jpeg defensively so a registry edit can never produce an
96
+ * empty enum that throws at module load.
97
+ */
98
+ const PRESIGN_MIME_TUPLE = (() => {
99
+ const mimes = presignMimeAllowlist();
100
+ return mimes.length > 0 ? mimes : ['image/png', 'image/jpeg'];
101
+ })();
102
+ /** Inline-upload (upload_asset_inline) caps + accepted-MIME display list,
103
+ * computed once at module load from the registry (not per /mcp request). */
104
+ const INLINE_MAX_BYTES = 6 * 1024 * 1024; // ~4.5MB pre-base64; keeps the model payload sane.
105
+ const INLINE_UPLOAD_MIME_LIST = inlineUploadMimeAllowlist().sort();
26
106
  // ── tool registration ─────────────────────────────────────────────────────────
27
- export function registerTools(server, wm, authService) {
107
+ export function registerTools(server, wm, authService, ctx) {
108
+ const { user, wsHub, apiTokenName, commentService } = ctx;
109
+ // External-agent identity: "<owner>'s <token name>", or "<owner>'s agent"
110
+ // as a fallback when the token has no name (older tokens or contexts that
111
+ // didn't thread the token through). `userId` lets the client paint the chip
112
+ // with the same accent as the owning user's avatar.
113
+ const agentLabel = apiTokenName
114
+ ? `${user.displayName}'s ${apiTokenName}`
115
+ : `${user.displayName}'s agent`;
116
+ const agentIdentity = {
117
+ kind: 'external',
118
+ label: agentLabel,
119
+ userId: String(user.id),
120
+ };
121
+ // Match the broadcast shape used by src/server/routes/graph-api.ts so the
122
+ // realtime listener in web/src/lib/stores/realtime.svelte.ts treats MCP
123
+ // mutations identically to web-UI mutations. The `agent` tag lets clients
124
+ // distinguish agent-driven mutations from human-driven ones.
125
+ function emitEntityChange(action, repo, entityType, entityId) {
126
+ wsHub?.broadcast({
127
+ type: 'entity_change',
128
+ action,
129
+ repo,
130
+ entityType,
131
+ entityId,
132
+ actor: user.displayName,
133
+ source: 'api',
134
+ agent: agentIdentity,
135
+ timestamp: new Date().toISOString(),
136
+ });
137
+ }
138
+ /**
139
+ * Wrap a mutation tool call so the sidebar can show a live "X's agent is
140
+ * acting" chip in the affected folder. `enter` fires before the work,
141
+ * `leave` after — wsHub TTL-cleans on crash. `verb` shapes the chip copy.
142
+ */
143
+ async function withAgentActivity(repo, verb, fn) {
144
+ wsHub?.handleAgentActivity('enter', repo, agentIdentity, verb);
145
+ try {
146
+ return await fn();
147
+ }
148
+ finally {
149
+ wsHub?.handleAgentActivity('leave', repo, agentIdentity, verb);
150
+ }
151
+ }
152
+ // Entity types the MCP surface may create. Matches the agent's allowlist so
153
+ // a workspace looks identical across the main app and MCP clients: the full
154
+ // canonical catalog plus workspace custom types. See
155
+ // src/core/entity-types-catalog.ts.
156
+ const builtinTypeKeys = new Set(Object.keys(ENTITY_SCHEMAS));
157
+ const customWorkspaceTypes = wm.getSchemaRegistry().getAllTypes()
158
+ .filter(t => !builtinTypeKeys.has(t));
159
+ const mcpAllowedCreateTypes = getAgentAllowedEntityTypes(customWorkspaceTypes);
160
+ const mcpAllowedSet = new Set(mcpAllowedCreateTypes);
28
161
  // ── list_repos ────────────────────────────────────────────────────────────
29
- server.registerTool('list_repos', { description: 'List all collections in the Studiograph workspace' }, async () => ok(wm.getAllRepoConfigs()));
162
+ server.registerTool('list_repos', { description: 'List folders in the Studiograph workspace that you have access to' }, async () => ok(getAccessibleRepos(user, wm, authService)));
163
+ // ── create_repo ───────────────────────────────────────────────────────────
164
+ //
165
+ // Creates a new shared folder in the workspace and grants the
166
+ // caller folder-admin access. Shares its implementation with the web route
167
+ // POST /api/repos via services/folder-creation.ts so both surfaces behave
168
+ // identically. After creation, use create_entity with the new folder name
169
+ // to add entries. Folder names are immutable slugs; the display name is
170
+ // editable later via the web UI.
171
+ const createRepoSchema = z.object({
172
+ name: z.string().describe('Folder slug — lowercase kebab-case (letters, digits, hyphens; must start with a letter or digit). ' +
173
+ 'This becomes the folder id and directory name; it cannot be changed without a rename.'),
174
+ display_name: z.string().optional().describe('Human-readable name shown in the UI (e.g. "Client Projects"). Defaults to the slug.'),
175
+ description: z.string().optional().describe('Short description of what this folder is for.'),
176
+ });
177
+ server.registerTool('create_repo', {
178
+ description: 'Create a new shared folder in the workspace. Use this when an agent or ' +
179
+ 'user needs a fresh container for a new project, client area, or topic and no existing ' +
180
+ 'folder fits. The caller is automatically granted folder-admin access. ' +
181
+ 'Follow up with create_entity (passing the new folder name as `repo`) to seed entries. ' +
182
+ 'Folder names must be kebab-case and unique; the private per-user "entries-<id>" ' +
183
+ 'namespace is reserved and will be rejected.',
184
+ inputSchema: createRepoSchema,
185
+ }, async (args) => {
186
+ const { name, display_name, description } = createRepoSchema.parse(args);
187
+ try {
188
+ const repo = await createSharedFolder(wm, authService, { name, display_name, description }, user, wsHub);
189
+ return ok({ success: true, ...repo });
190
+ }
191
+ catch (err) {
192
+ if (err instanceof FolderCreationError) {
193
+ return fail(new Error(err.message));
194
+ }
195
+ return fail(err);
196
+ }
197
+ });
30
198
  // ── list_entities ─────────────────────────────────────────────────────────
31
199
  const listEntitiesSchema = z.object({
32
- repo: z.string().optional().describe('Collection name — omit to list across all collections'),
33
- entity_type: z.string().optional().describe('Entity type filter (project, client, person, meeting…)'),
200
+ repo: z.string().optional().describe('Folder name — omit to list across all folders'),
201
+ entity_type: z.string().optional().describe('Entity type filter (project, client, person, event…)'),
34
202
  limit: z.number().int().positive().optional().describe('Maximum number of results'),
35
203
  });
36
- server.registerTool('list_entities', { description: 'List entities in a collection (or all collections). Optionally filter by entity type.', inputSchema: listEntitiesSchema }, async (args) => {
204
+ server.registerTool('list_entities', { description: 'List entities in a folder (or all folders). Optionally filter by entity type.', inputSchema: listEntitiesSchema }, async (args) => {
37
205
  const { repo, entity_type, limit } = listEntitiesSchema.parse(args);
38
206
  try {
207
+ // Comments live in SQLite, not the filesystem graph — dispatch through
208
+ // the virtual-entity adapter when the caller asks for them explicitly.
209
+ if (entity_type === 'comment' && commentService) {
210
+ if (repo && !hasRepoAccess(user, repo, wm, authService))
211
+ return notFound(repo);
212
+ const accessibleNames = new Set(getAccessibleRepos(user, wm, authService).map(r => r.name));
213
+ const envelopes = commentVirtualEntity.listComments(commentService, { repo, limit });
214
+ const filtered = envelopes.filter(e => accessibleNames.has(e.data.repo));
215
+ return ok(filtered.map(e => shape(e.id, e.entityType, e.data, { repo: e.data.repo })));
216
+ }
39
217
  if (repo) {
218
+ if (!hasRepoAccess(user, repo, wm, authService))
219
+ return notFound(repo);
40
220
  const entities = wm.getGraph(repo).list(entity_type, limit);
41
221
  return ok(entities.map(e => shape(e.id, e.entityType, e.data)));
42
222
  }
43
- const entities = wm.list(entity_type, limit);
44
- return ok(entities.map(e => shape(e.id, e.entityType, e.data, { repo: e.repoName })));
223
+ // No repo specified → iterate only over the user's accessible folders.
224
+ const accessible = getAccessibleRepos(user, wm, authService);
225
+ const results = [];
226
+ for (const r of accessible) {
227
+ try {
228
+ const list = wm.getGraph(r.name).list(entity_type);
229
+ for (const e of list) {
230
+ results.push(shape(e.id, e.entityType, e.data, { repo: r.name }));
231
+ if (limit && results.length >= limit)
232
+ return ok(results);
233
+ }
234
+ }
235
+ catch { /* skip unmounted repos */ }
236
+ }
237
+ return ok(results);
45
238
  }
46
239
  catch (err) {
47
240
  return fail(err);
@@ -49,15 +242,34 @@ export function registerTools(server, wm, authService) {
49
242
  });
50
243
  // ── get_entity ────────────────────────────────────────────────────────────
51
244
  const getEntitySchema = z.object({
52
- repo: z.string().describe('Collection name'),
245
+ repo: z.string().describe('Folder name'),
53
246
  entity_type: z.string().describe('Entity type (project, client, person…)'),
54
247
  entity_id: z.string().describe('Entity ID (kebab-case slug)'),
55
248
  });
56
249
  server.registerTool('get_entity', { description: 'Get a specific entity — includes full markdown content and frontmatter', inputSchema: getEntitySchema }, async (args) => {
57
250
  const { repo, entity_type, entity_id } = getEntitySchema.parse(args);
251
+ if (!hasRepoAccess(user, repo, wm, authService))
252
+ return notFound(repo);
58
253
  try {
59
- const entity = wm.getGraph(repo).get(entity_type, entity_id);
60
- return ok({ id: entity.id, type: entity.entityType, data: entity.data, content: entity.document.content });
254
+ if (entity_type === 'comment' && commentService) {
255
+ const envelope = commentVirtualEntity.getComment(commentService, entity_id);
256
+ if (!envelope)
257
+ return fail(new Error(`Comment "${entity_id}" not found`));
258
+ if (envelope.data.repo !== repo)
259
+ return notFound(repo);
260
+ return ok({ id: envelope.id, type: envelope.entityType, data: envelope.data, content: envelope.document.content });
261
+ }
262
+ const graph = wm.getGraph(repo);
263
+ const entity = graph.get(entity_type, entity_id);
264
+ // Prefer the live editor body when a seeded Y.Doc is open: graph.get
265
+ // reads disk, which lags the editor by the autosave debounce, so a
266
+ // user's freshly-placed image/asset embed may not be on disk yet.
267
+ // Returning disk content here is what let agents edit-then-overwrite
268
+ // and silently drop those embeds. null => no live doc, disk is
269
+ // authoritative.
270
+ const liveBody = graph.getLiveBody(entity_type, entity_id);
271
+ const content = liveBody ?? entity.document.content;
272
+ return ok({ id: entity.id, type: entity.entityType, data: entity.data, content });
61
273
  }
62
274
  catch (err) {
63
275
  return fail(err);
@@ -67,13 +279,19 @@ export function registerTools(server, wm, authService) {
67
279
  const searchSchema = z.object({
68
280
  query: z.string().optional().describe('Text search query'),
69
281
  entity_type: z.string().optional().describe('Filter by entity type'),
70
- repos: z.array(z.string()).optional().describe('Limit to specific collection names'),
282
+ repos: z.array(z.string()).optional().describe('Limit to specific folder names'),
71
283
  limit: z.number().int().positive().optional().describe('Maximum number of results'),
72
284
  });
73
- server.registerTool('search_entities', { description: 'Full-text search for entities across all collections', inputSchema: searchSchema }, async (args) => {
285
+ server.registerTool('search_entities', { description: 'Full-text search for entities across folders you can access', inputSchema: searchSchema }, async (args) => {
74
286
  const { query, entity_type, repos, limit } = searchSchema.parse(args);
75
287
  try {
76
- const results = await wm.search({ query, entityType: entity_type, repoNames: repos, limit });
288
+ const accessibleNames = new Set(getAccessibleRepos(user, wm, authService).map(r => r.name));
289
+ const scoped = repos
290
+ ? repos.filter(r => accessibleNames.has(r))
291
+ : [...accessibleNames];
292
+ if (scoped.length === 0)
293
+ return ok([]);
294
+ const results = await wm.search({ query, entityType: entity_type, repoNames: scoped, limit });
77
295
  return ok(results.map(e => shape(e.id, e.entityType, e.data, { repo: e.repoName })));
78
296
  }
79
297
  catch (err) {
@@ -81,62 +299,808 @@ export function registerTools(server, wm, authService) {
81
299
  }
82
300
  });
83
301
  // ── create_entity ─────────────────────────────────────────────────────────
302
+ // Constrain `entity_type` to the allowlist so MCP clients (e.g. Claude Desktop)
303
+ // see the same type surface as the main agent. Existing canonical-type entities
304
+ // remain readable/updatable via other tools.
305
+ const createEntityTypeSchema = mcpAllowedCreateTypes.length > 0
306
+ ? z.enum(mcpAllowedCreateTypes)
307
+ : z.string();
84
308
  const createSchema = z.object({
85
- repo: z.string().describe('Collection name'),
86
- entity_type: z.string().describe('Entity type'),
309
+ repo: z.string().describe('Folder name'),
310
+ entity_type: createEntityTypeSchema.describe(`Entity type. Allowed: ${mcpAllowedCreateTypes.join(', ')}.`),
87
311
  entity_id: z.string().describe('Entity ID (kebab-case slug)'),
88
- data: z.record(z.unknown()).describe('Frontmatter fields as a JSON object'),
312
+ data: z.record(z.string(), z.unknown()).describe('Type-specific frontmatter fields (e.g. for person: name, email, organization, role). ' +
313
+ 'Base fields (entity_id, entity_type, created_at, updated_at, created_by, updated_by) ' +
314
+ 'are stamped automatically — do not include them.'),
89
315
  content: z.string().optional().describe('Markdown body content'),
316
+ folder_path: z.string().optional().describe('Repo-relative subfolder to place the entry in (e.g. "People", "clients/acme"). ' +
317
+ 'Omit to use the per-type default (person → People, organization → Organizations); ' +
318
+ 'pass an empty string to force the repo root. Parent folders are auto-created.'),
90
319
  });
91
- server.registerTool('create_entity', { description: 'Create a new entity in a collection. Commits to git automatically.', inputSchema: createSchema }, async (args) => {
92
- const { repo, entity_type, entity_id, data, content } = createSchema.parse(args);
320
+ server.registerTool('create_entity', {
321
+ description: 'Create a new entity in a folder. Commits to git automatically. ' +
322
+ 'Base frontmatter (entity_id, created_at, updated_at, created_by, updated_by) is ' +
323
+ 'stamped automatically — `data` should only carry type-specific fields. ' +
324
+ 'For person entries, `status` accepts synonyms (active/prospective/inactive/past/etc.) ' +
325
+ 'and normalizes to `current` | `former`; defaults to `current` when omitted. ' +
326
+ 'Without `folder_path`, person entries route to People/ and organization entries to Organizations/; ' +
327
+ 'other types land at the repo root. Pass `folder_path: ""` to force the repo root, ' +
328
+ 'or any subfolder string (e.g. "Clients/Acme") to place it explicitly. ' +
329
+ 'Response includes the final repo-relative `path`.',
330
+ inputSchema: createSchema,
331
+ }, async (args) => {
332
+ const { repo, entity_type, entity_id, data, content, folder_path } = createSchema.parse(args);
333
+ if (!hasRepoAccess(user, repo, wm, authService))
334
+ return notFound(repo);
335
+ if (!canWriteRepo(user, repo, wm, authService)) {
336
+ return fail(new Error(`You do not have write access to folder "${repo}"`));
337
+ }
338
+ // Defense in depth: MCP SDK may not enforce zod enum strictly on all clients.
339
+ if (!mcpAllowedSet.has(entity_type)) {
340
+ const hint = isCuratedEntityType(entity_type)
341
+ ? '' // shouldn't happen for any other curated type — they're all allowed
342
+ : ` Allowed: ${mcpAllowedCreateTypes.join(', ')}.`;
343
+ return fail(new Error(`Entity type "${entity_type}" is not a known canonical or workspace custom type.${hint}`));
344
+ }
345
+ // Explicit folder_path (including "") wins; otherwise apply the per-type
346
+ // default so the agent doesn't have to know the workspace convention.
347
+ const effectiveFolder = folder_path !== undefined
348
+ ? folder_path
349
+ : (DEFAULT_FOLDER_BY_TYPE[entity_type] ?? '');
350
+ // Enforce the user↔person bridge invariant on person creates, matching
351
+ // graph-api + graph-tools: at most one person entity per auth handle
352
+ // workspace-wide (validateUserHandleInPayload), and only a workspace
353
+ // owner may stamp a handle (assertCanChangeUserHandle). Without this,
354
+ // create_entity over MCP was the one write path that could plant a
355
+ // SECOND linked record — violating "multiple person entries, but only
356
+ // one linked".
357
+ if (entity_type === 'person') {
358
+ try {
359
+ const incoming = (data ?? {});
360
+ validateUserHandleInPayload(wm, incoming);
361
+ if (Object.prototype.hasOwnProperty.call(incoming, 'user_handle')) {
362
+ assertCanChangeUserHandle(user, '', incoming.user_handle);
363
+ }
364
+ }
365
+ catch (err) {
366
+ if (err instanceof BridgeError)
367
+ return fail(err);
368
+ throw err;
369
+ }
370
+ }
371
+ // Scope ref fields (today: task.assignee → person). Reject a wikilink
372
+ // that resolves to a non-person; forward references are allowed.
93
373
  try {
94
- const entity = await wm.getGraph(repo).create({
95
- entityType: entity_type,
96
- entityId: entity_id,
97
- data: data,
98
- content,
99
- });
100
- return ok({ success: true, id: entity.id, type: entity.entityType });
374
+ assertEntityRefs(wm, entity_type, data, { userExists: (id) => !!authService.findUserById(Number(id)) });
101
375
  }
102
376
  catch (err) {
103
377
  return fail(err);
104
378
  }
379
+ const actor = buildActor(user);
380
+ const options = prepareCreatePayload({
381
+ entityType: entity_type,
382
+ entityId: entity_id,
383
+ data: data,
384
+ content,
385
+ folderPath: effectiveFolder || undefined,
386
+ }, actor);
387
+ return withAgentActivity(repo, 'creating', async () => {
388
+ try {
389
+ const graph = wm.getGraph(repo);
390
+ // Detect implicit subfolder creation: if the entity lands in a folder
391
+ // that didn't exist yet, the entity_change below only refreshes the
392
+ // entry list — clients need a _folder event to refetch the folder
393
+ // tree (sidebar + list/gallery folder rows). Normalize the same way
394
+ // graph.create does so the existence check matches the real path.
395
+ const normFolder = effectiveFolder ? validateFolderPath(effectiveFolder) : '';
396
+ const folderExisted = !normFolder || existsSync(join(graph.getRepoPath(), normFolder));
397
+ const entity = await graph.create(options);
398
+ emitEntityChange('created', repo, entity.entityType, entity.id);
399
+ if (!folderExisted)
400
+ emitEntityChange('created', repo, '_folder', normFolder);
401
+ return ok({
402
+ success: true,
403
+ id: entity.id,
404
+ type: entity.entityType,
405
+ repo,
406
+ path: relPathOf(entity.path, graph.getRepoPath()),
407
+ folder_path: entity.folder_path,
408
+ });
409
+ }
410
+ catch (err) {
411
+ return fail(err);
412
+ }
413
+ });
105
414
  });
106
415
  // ── update_entity ─────────────────────────────────────────────────────────
416
+ //
417
+ // Bare success envelopes were misleading agents: callers couldn't tell
418
+ // whether their write landed, whether validation silently dropped a field,
419
+ // or whether they'd just rewritten the file with identical bytes. The
420
+ // response now includes path, commit, before/after hashes, per-section
421
+ // changed flags, and the post-write entity snapshot so agents can verify
422
+ // their intent matches reality without a follow-up get_entity round-trip.
423
+ //
424
+ // No-op detection compares semantic frontmatter (excluding auto-stamped
425
+ // `updated_at` / `updated_by`) and raw content. A no-op is reported as
426
+ // success with `noop: true` — not an error — so idempotent re-runs are
427
+ // explicit. If the caller passed data or content but the on-disk file is
428
+ // byte-identical after the write, that's a silent-drop signal: the call
429
+ // fails loudly with a message that names which inputs were ignored.
107
430
  const updateSchema = z.object({
108
- repo: z.string().describe('Collection name'),
431
+ repo: z.string().describe('Folder name'),
109
432
  entity_type: z.string().describe('Entity type'),
110
433
  entity_id: z.string().describe('Entity ID'),
111
- data: z.record(z.unknown()).optional().describe('Frontmatter fields to update (merged with existing)'),
112
- content: z.string().optional().describe('New markdown body content'),
434
+ data: z.record(z.string(), z.unknown()).optional().describe('Frontmatter fields to update (merged with existing)'),
435
+ content: z.string().optional().describe('New markdown body content (replaces the entire body)'),
436
+ allow_image_removal: z.boolean().optional().describe('Whole-body writes are rejected with code ASSET_REMOVAL_BLOCKED when the submitted content would drop ' +
437
+ 'image/attachment embeds that the current document still has (a common silent-data-loss bug when an agent ' +
438
+ 'edits stale content). Set true ONLY when you intend to delete those embeds. Prefer patch_entity for small edits.'),
113
439
  });
114
- server.registerTool('update_entity', { description: 'Update an existing entity. Data fields are merged with existing frontmatter.', inputSchema: updateSchema }, async (args) => {
115
- const { repo, entity_type, entity_id, data, content } = updateSchema.parse(args);
440
+ server.registerTool('update_entity', {
441
+ description: 'Update an existing entity. Data fields are merged with existing frontmatter; content replaces the markdown body. ' +
442
+ 'Callers do not need to resend immutable base fields (entity_id, created_at, created_by) — they are preserved from disk. ' +
443
+ '`updated_at` and `updated_by` are stamped automatically. ' +
444
+ 'For person entries, `status` synonyms are normalized to `current` | `former` when supplied. ' +
445
+ 'Returns the post-write entity snapshot plus diagnostic flags (frontmatter_changed, content_changed, noop, commit) ' +
446
+ 'so the caller can verify the change landed without a separate get_entity call.',
447
+ inputSchema: updateSchema,
448
+ }, async (args) => {
449
+ const { repo, entity_type, entity_id, data, content, allow_image_removal } = updateSchema.parse(args);
450
+ if (!hasRepoAccess(user, repo, wm, authService))
451
+ return notFound(repo);
452
+ if (!canWriteRepo(user, repo, wm, authService)) {
453
+ return fail(new Error(`You do not have write access to folder "${repo}"`));
454
+ }
455
+ if (data === undefined && content === undefined) {
456
+ return fail(new Error('update_entity requires at least one of `data` or `content`'));
457
+ }
458
+ // Enforce the user↔person bridge invariant on person updates, matching
459
+ // graph-api + graph-tools: workspace-wide handle uniqueness (skipping the
460
+ // entity being written) + owner-only authz to change `user_handle`. Keeps
461
+ // update_entity from becoming a back door around "only one linked record".
462
+ if (entity_type === 'person' && data) {
463
+ try {
464
+ const incoming = data;
465
+ validateUserHandleInPayload(wm, incoming, { repo, entityId: entity_id });
466
+ if (Object.prototype.hasOwnProperty.call(incoming, 'user_handle')) {
467
+ let currentHandle = '';
468
+ try {
469
+ currentHandle = (wm.getGraph(repo).get('person', entity_id)?.data?.user_handle ?? '');
470
+ }
471
+ catch { /* new/missing entity — treat as empty */ }
472
+ assertCanChangeUserHandle(user, currentHandle, incoming.user_handle);
473
+ }
474
+ }
475
+ catch (err) {
476
+ if (err instanceof BridgeError)
477
+ return fail(err);
478
+ throw err;
479
+ }
480
+ }
481
+ // Scope ref fields (today: task.assignee → person). Reject a wikilink
482
+ // that resolves to a non-person; forward references are allowed.
116
483
  try {
117
- const entity = await wm.getGraph(repo).update({
118
- entityType: entity_type,
119
- entityId: entity_id,
120
- data: data,
121
- content,
122
- });
123
- return ok({ success: true, id: entity.id, type: entity.entityType });
484
+ assertEntityRefs(wm, entity_type, data, { userExists: (id) => !!authService.findUserById(Number(id)) });
124
485
  }
125
486
  catch (err) {
126
487
  return fail(err);
127
488
  }
489
+ const actor = buildActor(user);
490
+ const options = prepareUpdatePayload({
491
+ entityType: entity_type,
492
+ entityId: entity_id,
493
+ data: data,
494
+ content,
495
+ }, actor);
496
+ return withAgentActivity(repo, 'editing', async () => {
497
+ try {
498
+ const graph = wm.getGraph(repo);
499
+ // Diagnosed update (shared with the agent surface): snapshots
500
+ // before, runs the server-write path (disk + commit serialize via
501
+ // the per-doc lock; live clients get the post-commit broadcast),
502
+ // and throws SilentDropError when the caller intended a change
503
+ // that produced no on-disk diff. The outer catch maps that to fail.
504
+ const { entity, frontmatter_changed, content_changed, noop, broadcast } = await diagnosedUpdate(graph, options, { data, content }, { allowAssetRemoval: allow_image_removal });
505
+ emitEntityChange('updated', repo, entity.entityType, entity.id);
506
+ // Repo-relative path so external agents don't see the workspace
507
+ // absolute path. The HEAD commit is captured after graph.update
508
+ // commits the transaction — null when noGit is on or no commit
509
+ // was produced (e.g. transaction self-cleared because there was
510
+ // no staged diff).
511
+ const repoRoot = graph.getRepoPath();
512
+ const relPath = entity.path.startsWith(repoRoot + '/')
513
+ ? entity.path.slice(repoRoot.length + 1)
514
+ : entity.path;
515
+ const commit = graph.getGitService()?.getHeadCommit() ?? null;
516
+ return ok({
517
+ success: true,
518
+ id: entity.id,
519
+ type: entity.entityType,
520
+ repo,
521
+ path: relPath,
522
+ commit,
523
+ frontmatter_changed,
524
+ content_changed,
525
+ noop,
526
+ broadcast,
527
+ updated_at: entity.data.updated_at ?? null,
528
+ entity: {
529
+ id: entity.id,
530
+ type: entity.entityType,
531
+ data: entity.data,
532
+ content: entity.document.content,
533
+ },
534
+ });
535
+ }
536
+ catch (err) {
537
+ if (err instanceof DroppedAssetError) {
538
+ return ok({
539
+ success: false,
540
+ code: 'ASSET_REMOVAL_BLOCKED',
541
+ droppedAssets: err.dropped,
542
+ message: err.message,
543
+ });
544
+ }
545
+ return fail(err);
546
+ }
547
+ });
548
+ });
549
+ // ── patch_entity ──────────────────────────────────────────────────────────
550
+ //
551
+ // Surgical body edit: replace an exact substring without resending the
552
+ // whole body. The motivating failure was an agent fetching content,
553
+ // renaming a heading, and resending the entire body — which dropped
554
+ // editor-placed image embeds it never saw. patch_entity can't drop what it
555
+ // doesn't send: it reads the CURRENT body (live editor when open, else
556
+ // disk), applies the literal find→replace, and writes the result through
557
+ // the same guarded server-write path. The asset-drop guard still runs, so
558
+ // a patch that happens to delete an embed is rejected unless the substring
559
+ // is itself the embed being intentionally removed.
560
+ const patchEntitySchema = z.object({
561
+ repo: z.string().describe('Folder name'),
562
+ entity_type: z.string().describe('Entity type'),
563
+ entity_id: z.string().describe('Entity ID'),
564
+ find: z.string().describe('Exact substring to locate in the current body (verbatim, including whitespace).'),
565
+ replace: z.string().describe('Replacement text. Empty string deletes the matched substring.'),
566
+ expected_count: z.number().int().positive().optional().describe('Optional safety check: require `find` to occur exactly this many times. The patch is rejected with ' +
567
+ 'NO_MATCH / AMBIGUOUS_MATCH when the actual count differs, so you never edit the wrong occurrence.'),
568
+ });
569
+ server.registerTool('patch_entity', {
570
+ description: 'Surgically edit an entry body by replacing an exact substring — without rewriting the whole body. ' +
571
+ 'Prefer this over update_entity for small edits (renaming a heading, fixing a sentence): it operates on ' +
572
+ 'the live editor body and cannot drop image/asset embeds it did not touch. Returns the same diagnostic ' +
573
+ 'flags as update_entity. Use `expected_count` to guard against ambiguous matches.',
574
+ inputSchema: patchEntitySchema,
575
+ }, async (args) => {
576
+ const { repo, entity_type, entity_id, find, replace, expected_count } = patchEntitySchema.parse(args);
577
+ if (!hasRepoAccess(user, repo, wm, authService))
578
+ return notFound(repo);
579
+ if (!canWriteRepo(user, repo, wm, authService)) {
580
+ return fail(new Error(`You do not have write access to folder "${repo}"`));
581
+ }
582
+ if (find === '')
583
+ return fail(new Error('patch_entity requires a non-empty `find` string'));
584
+ if (find === replace)
585
+ return fail(new Error('patch_entity `find` and `replace` are identical — nothing to do'));
586
+ return withAgentActivity(repo, 'editing', async () => {
587
+ try {
588
+ const graph = wm.getGraph(repo);
589
+ const entity = graph.get(entity_type, entity_id);
590
+ // Patch against the live editor body when one is open, so we don't
591
+ // reintroduce the stale-read problem we're fixing.
592
+ const currentBody = graph.getLiveBody(entity_type, entity_id) ?? entity.document.content;
593
+ // Count occurrences of the literal substring (no regex).
594
+ let count = 0;
595
+ for (let i = currentBody.indexOf(find); i !== -1; i = currentBody.indexOf(find, i + find.length))
596
+ count++;
597
+ if (count === 0) {
598
+ return ok({ success: false, code: 'NO_MATCH', message: `\`find\` substring not present in ${entity_type}/${entity_id}.` });
599
+ }
600
+ if (expected_count !== undefined && count !== expected_count) {
601
+ return ok({ success: false, code: 'AMBIGUOUS_MATCH', occurrences: count, message: `Expected ${expected_count} occurrence(s) of \`find\`, found ${count}.` });
602
+ }
603
+ const newBody = currentBody.split(find).join(replace);
604
+ const options = prepareUpdatePayload({ entityType: entity_type, entityId: entity_id, content: newBody }, buildActor(user));
605
+ const { entity: updated, frontmatter_changed, content_changed, noop, broadcast } = await diagnosedUpdate(graph, options, { content: newBody });
606
+ emitEntityChange('updated', repo, updated.entityType, updated.id);
607
+ const repoRoot = graph.getRepoPath();
608
+ const relPath = updated.path.startsWith(repoRoot + '/') ? updated.path.slice(repoRoot.length + 1) : updated.path;
609
+ return ok({
610
+ success: true,
611
+ id: updated.id, type: updated.entityType, repo, path: relPath,
612
+ commit: graph.getGitService()?.getHeadCommit() ?? null,
613
+ occurrences: count, frontmatter_changed, content_changed, noop, broadcast,
614
+ });
615
+ }
616
+ catch (err) {
617
+ if (err instanceof DroppedAssetError) {
618
+ return ok({ success: false, code: 'ASSET_REMOVAL_BLOCKED', droppedAssets: err.dropped, message: err.message });
619
+ }
620
+ return fail(err);
621
+ }
622
+ });
623
+ });
624
+ // ── list_assets ─────────────────────────────────────────────────────────
625
+ //
626
+ // Read-only discovery of assets (images, PDFs, files) already uploaded to a
627
+ // folder. Shares listRepoAssets() with the HTTP asset endpoints, so the
628
+ // shape — including the render-safe `embed` string — is identical. Assets
629
+ // are created only through the upload routes / workspace UI; this tool never
630
+ // creates one, it only surfaces existing ones so an agent can reference them
631
+ // in an entry body without guessing a URL or embed syntax.
632
+ const listAssetsSchema = z.object({
633
+ repo: z.string().describe('Folder name'),
634
+ entity_type: z.string().optional().describe('Filter to assets owned by entries of this type'),
635
+ entity_id: z.string().optional().describe('Filter to assets owned by this entry id'),
636
+ });
637
+ server.registerTool('list_assets', {
638
+ description: 'List assets (images, PDFs, files) already uploaded to a folder. Each result includes a ready-to-paste ' +
639
+ '`embed` — standard markdown `![name](url)` — that renders in the editor. To display an asset in an entry, ' +
640
+ 'place that exact `embed` string via attach_asset_to_entity (or patch_entity for append/insert). ' +
641
+ 'NEVER write `![[filename]]` transclusion syntax: it does not resolve to a stored asset and shows as dead ' +
642
+ 'text. Assets are uploaded via the workspace UI — this tool only references existing ones. Optionally ' +
643
+ 'filter by entity_type and/or entity_id to list a single entry\'s assets.',
644
+ inputSchema: listAssetsSchema,
645
+ }, async (args) => {
646
+ const { repo, entity_type, entity_id } = listAssetsSchema.parse(args);
647
+ if (!hasRepoAccess(user, repo, wm, authService))
648
+ return notFound(repo);
649
+ try {
650
+ wm.getGraph(repo);
651
+ }
652
+ catch {
653
+ return notFound(repo);
654
+ }
655
+ let assets = await listRepoAssets(repo, wm);
656
+ if (entity_type)
657
+ assets = assets.filter(a => a.entityType === entity_type);
658
+ if (entity_id)
659
+ assets = assets.filter(a => a.entityId === entity_id);
660
+ return ok({
661
+ repo,
662
+ count: assets.length,
663
+ assets: assets.map(a => ({
664
+ asset_id: a.assetId,
665
+ filename: a.filename,
666
+ mime_type: a.contentType,
667
+ entity_type: a.entityType,
668
+ entity_id: a.entityId,
669
+ entity_name: a.entityName,
670
+ url: a.url,
671
+ embed: a.embed,
672
+ })),
673
+ });
674
+ });
675
+ // ── attach_asset_to_entity ──────────────────────────────────────────────
676
+ //
677
+ // Place an already-uploaded asset (from list_assets) into an entry body
678
+ // without rewriting the whole body. Thin convenience over the patch_entity
679
+ // machinery: it builds the render-safe `![alt](url)` embed and either
680
+ // appends it or swaps a placeholder for it, then writes through the same
681
+ // guarded server-write path.
682
+ //
683
+ // `replace_placeholder` is the sanctioned way to fix a dead `![[Foo.png]]`
684
+ // placeholder. Note: that swap necessarily *drops* the transclusion target
685
+ // (`Foo.png`) the asset-drop guard recognizes, so a plain patch_entity of
686
+ // the same span would be rejected with ASSET_REMOVAL_BLOCKED. Here we pass
687
+ // allowAssetRemoval for replace_placeholder only — the agent is explicitly
688
+ // targeting that placeholder and we're re-adding the image as a working
689
+ // embed, so no real asset is lost. `append` keeps the guard on.
690
+ const attachAssetSchema = z.object({
691
+ repo: z.string().describe('Folder name'),
692
+ entity_type: z.string().describe('Entity type of the target entry'),
693
+ entity_id: z.string().describe('Entity ID of the target entry'),
694
+ url: z.string().describe('Asset url, taken verbatim from list_assets (e.g. /api/assets/<id>/<file>)'),
695
+ alt: z.string().optional().describe('Alt text / caption for the embed. Defaults to the asset filename.'),
696
+ mode: z.enum(['append', 'replace_placeholder']).default('append').describe('"append" adds the embed at the end of the body. "replace_placeholder" swaps `placeholder` text ' +
697
+ '(e.g. a dead `![[Foo.png]]` written earlier) for the working embed.'),
698
+ placeholder: z.string().optional().describe('Required when mode="replace_placeholder": exact text to replace.'),
699
+ expected_count: z.number().int().positive().optional().describe('For replace_placeholder: require `placeholder` to occur exactly this many times, else reject (AMBIGUOUS_MATCH).'),
700
+ });
701
+ server.registerTool('attach_asset_to_entity', {
702
+ description: 'Embed an already-uploaded asset (from list_assets) into an entry body using its render-safe markdown, ' +
703
+ 'without rewriting the whole body. mode="append" adds it at the end; mode="replace_placeholder" swaps dead ' +
704
+ 'placeholder text (e.g. an `![[Foo.png]]` an agent wrote earlier) for the working embed. Drop-guarded on ' +
705
+ 'append: rejects with ASSET_REMOVAL_BLOCKED if it would remove other image embeds.',
706
+ inputSchema: attachAssetSchema,
707
+ }, async (args) => {
708
+ const { repo, entity_type, entity_id, url, alt, mode, placeholder, expected_count } = attachAssetSchema.parse(args);
709
+ if (!hasRepoAccess(user, repo, wm, authService))
710
+ return notFound(repo);
711
+ if (!canWriteRepo(user, repo, wm, authService)) {
712
+ return fail(new Error(`You do not have write access to folder "${repo}"`));
713
+ }
714
+ if (!url.trim())
715
+ return fail(new Error('attach_asset_to_entity requires a non-empty `url`'));
716
+ if (mode === 'replace_placeholder' && !placeholder) {
717
+ return fail(new Error('mode="replace_placeholder" requires a non-empty `placeholder`'));
718
+ }
719
+ const filename = alt ?? (url.split('/').pop() || 'asset').split('?')[0];
720
+ const embed = assetEmbed(filename, url);
721
+ return withAgentActivity(repo, 'editing', async () => {
722
+ try {
723
+ const graph = wm.getGraph(repo);
724
+ const entity = graph.get(entity_type, entity_id);
725
+ const currentBody = graph.getLiveBody(entity_type, entity_id) ?? entity.document.content;
726
+ let newBody;
727
+ let occurrences;
728
+ let allowAssetRemoval = false;
729
+ if (mode === 'replace_placeholder') {
730
+ const ph = placeholder;
731
+ let count = 0;
732
+ for (let i = currentBody.indexOf(ph); i !== -1; i = currentBody.indexOf(ph, i + ph.length))
733
+ count++;
734
+ if (count === 0) {
735
+ return ok({ success: false, code: 'NO_MATCH', message: `placeholder not present in ${entity_type}/${entity_id}.` });
736
+ }
737
+ if (expected_count !== undefined && count !== expected_count) {
738
+ return ok({ success: false, code: 'AMBIGUOUS_MATCH', occurrences: count, message: `Expected ${expected_count} occurrence(s) of placeholder, found ${count}.` });
739
+ }
740
+ occurrences = count;
741
+ newBody = currentBody.split(ph).join(embed);
742
+ // The placeholder we're removing is itself a recognized embed
743
+ // target; swapping it for the working embed is the whole point.
744
+ allowAssetRemoval = true;
745
+ }
746
+ else {
747
+ if (currentBody.includes(embed)) {
748
+ return ok({ success: false, code: 'ALREADY_PRESENT', message: `Asset embed already present in ${entity_type}/${entity_id}.` });
749
+ }
750
+ newBody = currentBody.trimEnd() + '\n\n' + embed + '\n';
751
+ }
752
+ const options = prepareUpdatePayload({ entityType: entity_type, entityId: entity_id, content: newBody }, buildActor(user));
753
+ const { entity: updated, frontmatter_changed, content_changed, noop, broadcast } = await diagnosedUpdate(graph, options, { content: newBody }, { allowAssetRemoval });
754
+ emitEntityChange('updated', repo, updated.entityType, updated.id);
755
+ const repoRoot = graph.getRepoPath();
756
+ const relPath = updated.path.startsWith(repoRoot + '/') ? updated.path.slice(repoRoot.length + 1) : updated.path;
757
+ return ok({
758
+ success: true,
759
+ id: updated.id, type: updated.entityType, repo, path: relPath,
760
+ embed, mode, occurrences,
761
+ commit: graph.getGitService()?.getHeadCommit() ?? null,
762
+ frontmatter_changed, content_changed, noop, broadcast,
763
+ });
764
+ }
765
+ catch (err) {
766
+ if (err instanceof DroppedAssetError) {
767
+ return ok({ success: false, code: 'ASSET_REMOVAL_BLOCKED', droppedAssets: err.dropped, message: err.message });
768
+ }
769
+ return fail(err);
770
+ }
771
+ });
772
+ });
773
+ // ── create_asset_upload ─────────────────────────────────────────────────
774
+ //
775
+ // Step 1 of 3 for the pre-signed asset upload flow. Validates request,
776
+ // resolves target folder (defaults to the workspace_wide Assets store),
777
+ // mints a pre-signed PUT URL the agent uploads to directly, and returns
778
+ // an HMAC token to pass back to finalize_asset_upload. Bytes never travel
779
+ // through this MCP server — only authz + indexing do.
780
+ //
781
+ // The tool description is load-bearing: it's what the agent reads to
782
+ // plan the three-step flow. Be explicit about each step and the exact
783
+ // shape of the PUT.
784
+ const createAssetUploadSchema = z.object({
785
+ repo: z.string().optional().describe('Folder name. Omit to upload into the shared "Assets" store (created on first use).'),
786
+ filename: z.string().describe('Filename including extension (e.g. "logo.png"). Sanitized server-side; no path segments.'),
787
+ // Registry-driven (P4-V1): the presign path only accepts formats safe as
788
+ // raw bytes (the app never holds them, so it can't sanitize). SVG +
789
+ // documents are excluded here and go through upload_asset_inline instead.
790
+ mime_type: z.enum(PRESIGN_MIME_TUPLE).describe(`Image MIME accepted by the presign flow: ${PRESIGN_MIME_TUPLE.join(', ')}. ` +
791
+ `SVG and documents are not presignable (use upload_asset_inline).`),
792
+ });
793
+ server.registerTool('create_asset_upload', {
794
+ description: 'STEP 1 of 3 for uploading an image (PNG or JPEG, max 20MB) from outside the model context. ' +
795
+ 'Returns { assetId, uploadUrl, headers, token, expiresAt, repo }.\n\n' +
796
+ 'STEP 2 (not an MCP tool): issue an HTTP PUT to `uploadUrl` with the raw image bytes as the body and ' +
797
+ 'the returned `headers` set verbatim (notably `Content-Type`). The URL expires in 15 minutes. ' +
798
+ 'Most HTTP clients can do this; if yours cannot PUT binary, use the workspace upload UI instead.\n\n' +
799
+ 'STEP 3: call `finalize_asset_upload({ token })` to register the asset and get a permanent URL. ' +
800
+ 'Optionally call `attach_asset_to_entity({ url, ... })` after that to embed the asset into an entry body.\n\n' +
801
+ 'Errors with code "local_backend" when the workspace uses local filesystem storage (R2 only).',
802
+ inputSchema: createAssetUploadSchema,
803
+ }, async (args) => {
804
+ const parsed = createAssetUploadSchema.parse(args);
805
+ try {
806
+ // Asset-as-embed (B2): the upload always produces a FREE-STANDING,
807
+ // folder-owned asset. There is no entity-ownership handoff — embed it
808
+ // into an entry afterwards via attach_asset_to_entity.
809
+ const result = await presignAssetUpload({
810
+ workspaceManager: wm,
811
+ authService,
812
+ user,
813
+ repo: parsed.repo,
814
+ filename: parsed.filename,
815
+ mimeType: parsed.mime_type,
816
+ });
817
+ return ok({
818
+ assetId: result.assetId,
819
+ uploadUrl: result.uploadUrl,
820
+ headers: result.headers,
821
+ token: result.token,
822
+ expiresAt: result.expiresAt,
823
+ repo: result.repo,
824
+ });
825
+ }
826
+ catch (err) {
827
+ return errorToMcpResult(err);
828
+ }
829
+ });
830
+ // ── finalize_asset_upload ───────────────────────────────────────────────
831
+ //
832
+ // Step 3 of 3. Verifies the upload landed at the pre-signed URL,
833
+ // validates content-type + size at the wire, promotes the blob from
834
+ // `pending/` into the canonical keyspace, and registers a FREE-STANDING,
835
+ // folder-owned asset (no entity). Idempotent on token replay:
836
+ // a second call returns the existing assetId + URL.
837
+ //
838
+ // Identity-bound (R1): the user calling finalize must be the same user
839
+ // who minted the token — leaked tokens cannot be replayed by another
840
+ // folder-writer. Workspace owners are NOT exempt.
841
+ const finalizeAssetUploadSchema = z.object({
842
+ token: z.string().describe('HMAC token returned by create_asset_upload.'),
843
+ name: z.string().optional().describe('Optional display name for the asset entry. Defaults to a title-cased version of the filename stem.'),
844
+ });
845
+ server.registerTool('finalize_asset_upload', {
846
+ description: 'STEP 3 of 3. Call this after PUTting bytes to the uploadUrl returned by create_asset_upload. ' +
847
+ 'Verifies the upload landed, validates content type and size, registers a free-standing asset, and returns ' +
848
+ '{ assetId, url, ownerType, ownerId, repo }. Embed it into an entry afterwards via attach_asset_to_entity. ' +
849
+ 'Idempotent: calling with the same token twice returns the existing asset.\n\n' +
850
+ 'Errors with code "upload_not_received" if the PUT never happened (or the 15-min window expired); ' +
851
+ '"upload_validation" if content type or size doesn\'t match the presign contract; "token_invalid" if ' +
852
+ 'the token is tampered or expired; "forbidden" if the caller is not the original presigner or has lost ' +
853
+ 'folder access in the interim.',
854
+ inputSchema: finalizeAssetUploadSchema,
855
+ }, async (args) => {
856
+ const parsed = finalizeAssetUploadSchema.parse(args);
857
+ try {
858
+ const result = await finalizeAssetUpload({
859
+ workspaceManager: wm,
860
+ authService,
861
+ user,
862
+ token: parsed.token,
863
+ name: parsed.name,
864
+ });
865
+ // Asset-as-embed (B2): finalize registers a FREE-STANDING asset, not an
866
+ // entity, so there's no entity_change to broadcast — it surfaces in the
867
+ // asset manager on its next load. Its image caption is derived for
868
+ // search by the asset-index sweep (the legacy live drain was keyed to
869
+ // `asset` entities, which this no longer creates).
870
+ return ok({
871
+ assetId: result.assetId,
872
+ url: result.url,
873
+ ownerType: result.ownerType,
874
+ ownerId: result.ownerId,
875
+ repo: result.repo,
876
+ });
877
+ }
878
+ catch (err) {
879
+ return errorToMcpResult(err);
880
+ }
881
+ });
882
+ // ── upload_asset_inline ─────────────────────────────────────────────────────
883
+ //
884
+ // V3: single-call asset upload for SMALL files where the bytes can ride
885
+ // inline (base64). Unlike create_asset_upload (R2-only presign, 3 steps,
886
+ // bytes never touch the app), this works on local OR R2 backends and is one
887
+ // round-trip — the tradeoff is a tight size cap (base64 inflates the model
888
+ // context ~33%, and the bytes traverse this server). For large files or when
889
+ // an R2 backend is available, prefer the presign flow.
890
+ //
891
+ // Indexing reaches web parity: after the asset entity is committed we enqueue
892
+ // the live caption/extract drain (same as a web upload), so an inline-
893
+ // uploaded image is captioned while the server runs.
894
+ const uploadAssetInlineSchema = z.object({
895
+ repo: z.string().optional().describe('Folder name. Omit to upload into the shared "Assets" store (created on first use).'),
896
+ filename: z.string().describe('Filename including extension (e.g. "diagram.png"). Sanitized server-side; no path segments.'),
897
+ data_base64: z.string().describe('The file bytes, base64-encoded. Keep under ~4.5MB raw (6MB base64) — larger files must use create_asset_upload.'),
898
+ name: z.string().optional().describe('Optional display name for the asset entry. Defaults to a title-cased filename stem.'),
899
+ folder_path: z.string().optional().describe('Optional repo-relative subfolder for the entry .md (e.g. "Diagrams"). Defaults to repo root.'),
900
+ });
901
+ server.registerTool('upload_asset_inline', {
902
+ description: 'Ingest a SMALL file (image or document) as a typed entry in ONE call by passing its bytes ' +
903
+ 'base64-encoded. The file is stored as a free-standing asset and a typed entry that embeds it ' +
904
+ 'is created — image→material, doc/pdf→document (extracted text in the body), xlsx/csv→dataset — ' +
905
+ 'exactly as a web import would. Returns { assetId, url, repo, entities: [{ entityType, entityId }] }.\n\n' +
906
+ 'Size limit ~4.5MB raw (6MB base64) — for larger files use create_asset_upload (R2 presign, 3 steps). ' +
907
+ 'Accepted types are the workspace upload set (images + documents); SVG is not yet accepted here. ' +
908
+ 'Images are captioned for search automatically in the background.',
909
+ inputSchema: uploadAssetInlineSchema,
910
+ }, async (args) => {
911
+ const parsed = uploadAssetInlineSchema.parse(args);
912
+ // 1. Format gate: resolve the filename to a registry format and check it
913
+ // directly via isInlineUploadAllowed — NOT via detectContentType, whose
914
+ // CONTENT_TYPES map returns application/octet-stream for several
915
+ // registry-accepted assets (.tsv/.psd/.ai/.aac/...), which would wrongly
916
+ // reject them. Both the gate and the allowlist now derive from the same
917
+ // registry predicate, so they can't disagree. Rejects SVG (transitional
918
+ // until sanitize-html), unaccepted docs, and unknown types (fallback).
919
+ const format = resolveFormat(parsed.filename);
920
+ if (!isInlineUploadAllowed(format)) {
921
+ return fail(new Error(`"${parsed.filename}" is not accepted by upload_asset_inline. ` +
922
+ `Accepted: ${INLINE_UPLOAD_MIME_LIST.join(', ')}.`));
923
+ }
924
+ // 2. Decode + size gate. Node's Buffer.from(..,'base64') silently DROPS
925
+ // invalid characters instead of throwing, so a garbage string would
926
+ // "decode" to junk bytes. Validate the shape first (strip one optional
927
+ // data: prefix + whitespace, then assert the strict base64 charset),
928
+ // and re-encode-compare to catch truncation.
929
+ const raw = parsed.data_base64.replace(/^data:[^;]+;base64,/, '').replace(/\s+/g, '');
930
+ if (raw.length === 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(raw) || raw.length % 4 !== 0) {
931
+ return fail(new Error('data_base64 is not valid base64.'));
932
+ }
933
+ const buffer = Buffer.from(raw, 'base64');
934
+ if (buffer.length === 0 || buffer.toString('base64') !== raw) {
935
+ return fail(new Error('data_base64 is not valid base64.'));
936
+ }
937
+ if (buffer.length > INLINE_MAX_BYTES) {
938
+ return fail(new Error(`Decoded size ${buffer.length} bytes exceeds the inline ${INLINE_MAX_BYTES}-byte cap. Use create_asset_upload for larger files.`));
939
+ }
940
+ // 3. Resolve the target repo (default → shared Assets store) + authz.
941
+ let repo;
942
+ try {
943
+ repo = parsed.repo
944
+ ?? await resolveWorkspaceAssetsRepo(new Workspace(wm.getWorkspacePath()), wm);
945
+ }
946
+ catch (err) {
947
+ return errorToMcpResult(err);
948
+ }
949
+ if (!canWriteRepo(user, repo, wm, authService)) {
950
+ return fail(`You don't have permission to write to "${repo}". Editor or admin role required.`);
951
+ }
952
+ let graph;
953
+ try {
954
+ graph = wm.getGraph(repo);
955
+ }
956
+ catch (err) {
957
+ return errorToMcpResult(err);
958
+ }
959
+ // 4. Ingest via the asset-as-embed import: store the bytes as a
960
+ // free-standing folder-owned asset + create the typed entry(ies) whose
961
+ // body embeds it (image→material, doc→document, xlsx→dataset×N).
962
+ // Auto-commits. Same path as web import/drag-drop.
963
+ try {
964
+ const result = await withAgentActivity(repo, 'creating', () => importAssetAsEntity({
965
+ graph,
966
+ filename: parsed.filename,
967
+ buffer,
968
+ folderPath: parsed.folder_path || undefined,
969
+ name: parsed.name,
970
+ user: buildActor(user),
971
+ uploaderUserId: String(user.id),
972
+ }));
973
+ for (const e of result.entities)
974
+ emitEntityChange('created', repo, e.entityType, e.entityId);
975
+ // V3 indexing parity: the created entries' bodies are vector-indexed
976
+ // natively; the embedded image asset's caption drains in the background.
977
+ return ok({
978
+ assetId: result.assetId,
979
+ url: result.asset_url,
980
+ repo,
981
+ entities: result.entities.map(e => ({ entityType: e.entityType, entityId: e.entityId })),
982
+ });
983
+ }
984
+ catch (err) {
985
+ return errorToMcpResult(err);
986
+ }
987
+ });
988
+ // ── move_entity ───────────────────────────────────────────────────────────
989
+ //
990
+ // Relocate an entity to a different folder within the same repo. Wraps
991
+ // graph.move() which renames the file on disk and commits the rename so
992
+ // git's similarity detection preserves history. The (type, id) identity
993
+ // is unchanged — get_entity, search, list, validate_wikilinks, and the
994
+ // history tools all walk the entire repo tree and continue to find the
995
+ // entry at its new path. For cross-repo transfers, the web UI's bulk-move
996
+ // dialog or POST /api/repos/:repo/transfer is the right surface.
997
+ const moveEntitySchema = z.object({
998
+ repo: z.string().describe('Folder name containing the entry'),
999
+ entity_type: z.string().describe('Entity type'),
1000
+ entity_id: z.string().describe('Entity ID'),
1001
+ folder_path: z.string().describe('Target repo-relative folder path (e.g. "People", "Clients/Acme"). ' +
1002
+ 'Empty string moves the entry to the repo root. Parent folders are auto-created.'),
1003
+ overwrite: z.boolean().optional().describe('When true, replace an existing entry at the destination. The occupant ' +
1004
+ 'must itself be a parseable entity — README/.gitkeep/etc. are never ' +
1005
+ 'clobbered. Defaults to false; the call errors with "Path already ' +
1006
+ 'occupied" when the destination is taken.'),
1007
+ });
1008
+ server.registerTool('move_entity', {
1009
+ description: 'Move an existing entry to a different folder within the same folder/repo. ' +
1010
+ 'Preserves frontmatter, markdown content, entity ID, and git history (file is renamed, not rewritten). ' +
1011
+ 'Use this to organise entries into subfolders after creation — e.g. moving a person into People/. ' +
1012
+ 'By default, errors if the destination already has an entry; pass `overwrite: true` to replace.',
1013
+ inputSchema: moveEntitySchema,
1014
+ }, async (args) => {
1015
+ const { repo, entity_type, entity_id, folder_path, overwrite } = moveEntitySchema.parse(args);
1016
+ if (!hasRepoAccess(user, repo, wm, authService))
1017
+ return notFound(repo);
1018
+ if (!canWriteRepo(user, repo, wm, authService)) {
1019
+ return fail(new Error(`You do not have write access to folder "${repo}"`));
1020
+ }
1021
+ const actor = buildActor(user);
1022
+ return withAgentActivity(repo, 'editing', async () => {
1023
+ try {
1024
+ const graph = wm.getGraph(repo);
1025
+ // If the destination folder doesn't exist yet, the move creates it —
1026
+ // emit a _folder event (alongside the entry update) so clients
1027
+ // refetch the folder tree, not just the entry list.
1028
+ const normTarget = folder_path ? validateFolderPath(folder_path) : '';
1029
+ const targetExisted = !normTarget || existsSync(join(graph.getRepoPath(), normTarget));
1030
+ const moved = await graph.move(entity_type, entity_id, folder_path, undefined, actor, overwrite);
1031
+ emitEntityChange('updated', repo, moved.entityType, moved.id);
1032
+ if (!targetExisted)
1033
+ emitEntityChange('created', repo, '_folder', normTarget);
1034
+ return ok({
1035
+ success: true,
1036
+ id: moved.id,
1037
+ type: moved.entityType,
1038
+ repo,
1039
+ path: relPathOf(moved.path, graph.getRepoPath()),
1040
+ folder_path: moved.folder_path,
1041
+ });
1042
+ }
1043
+ catch (err) {
1044
+ return fail(err);
1045
+ }
1046
+ });
1047
+ });
1048
+ // ── create_subfolder ──────────────────────────────────────────────────────
1049
+ //
1050
+ // Create a nested subfolder inside an existing folder/collection. Wraps
1051
+ // graph.createFolder(). Distinct from create_repo, which registers a new
1052
+ // top-level collection. Emits the _folder sentinel so live clients refetch
1053
+ // the folder tree (sidebar + list/gallery folder rows) without a reload.
1054
+ const createSubfolderSchema = z.object({
1055
+ repo: z.string().describe('Folder name (collection) to create the subfolder inside'),
1056
+ path: z.string().describe('Repo-relative POSIX path of the new subfolder (e.g. "Clients/Acme"). Parent segments are auto-created.'),
1057
+ display_name: z.string().optional().describe('Optional human-readable label. Omit when the title-cased folder name is the right display ' +
1058
+ '(pass it for casing the slug can\'t express, e.g. "HR" or "Schema_OS").'),
1059
+ });
1060
+ server.registerTool('create_subfolder', {
1061
+ description: 'Create a new subfolder inside an existing folder/collection. Path is repo-relative POSIX (e.g. "Clients/Acme"); parent segments are auto-created. ' +
1062
+ 'Use it to organise entries, then place entries inside via create_entity (folder_path) or move_entity. ' +
1063
+ 'For a brand-new top-level collection, use create_repo instead.',
1064
+ inputSchema: createSubfolderSchema,
1065
+ }, async (args) => {
1066
+ const { repo, path, display_name } = createSubfolderSchema.parse(args);
1067
+ if (!hasRepoAccess(user, repo, wm, authService))
1068
+ return notFound(repo);
1069
+ if (!canWriteRepo(user, repo, wm, authService)) {
1070
+ return fail(new Error(`You do not have write access to folder "${repo}"`));
1071
+ }
1072
+ const actor = buildActor(user);
1073
+ return withAgentActivity(repo, 'creating', async () => {
1074
+ try {
1075
+ const graph = wm.getGraph(repo);
1076
+ await graph.createFolder(path, undefined, actor, { displayName: display_name });
1077
+ emitEntityChange('created', repo, '_folder', path);
1078
+ return ok({ success: true, repo, path, folder_path: path });
1079
+ }
1080
+ catch (err) {
1081
+ return fail(err);
1082
+ }
1083
+ });
128
1084
  });
129
1085
  // ── validate_wikilinks ────────────────────────────────────────────────────
130
1086
  const validateWikilinksSchema = z.object({
131
- repo: z.string().describe('Collection name'),
1087
+ repo: z.string().describe('Folder name'),
132
1088
  entity_type: z.string().describe('Entity type'),
133
1089
  entity_id: z.string().describe('Entity ID'),
134
1090
  });
135
1091
  server.registerTool('validate_wikilinks', { description: 'Check which wikilinks in an entity resolve to real entities and which are broken', inputSchema: validateWikilinksSchema }, async (args) => {
136
1092
  const { repo, entity_type, entity_id } = validateWikilinksSchema.parse(args);
1093
+ if (!hasRepoAccess(user, repo, wm, authService))
1094
+ return notFound(repo);
137
1095
  try {
138
1096
  const result = wm.getGraph(repo).validateWikilinks(entity_type, entity_id);
139
- return ok({ entity_id, valid: result.valid, broken: result.broken, total: result.valid.length + result.broken.length });
1097
+ const accessibleIds = getAccessibleEntityIds(user, wm, authService);
1098
+ const valid = filterWikilinks(result.valid, accessibleIds);
1099
+ // Anything the user can't see is reported as broken rather than valid —
1100
+ // it shouldn't leak the target's existence.
1101
+ const hiddenFromValid = result.valid.filter(id => !valid.includes(id));
1102
+ const broken = [...result.broken, ...hiddenFromValid];
1103
+ return ok({ entity_id, valid, broken, total: valid.length + broken.length });
140
1104
  }
141
1105
  catch (err) {
142
1106
  return fail(err);
@@ -144,7 +1108,7 @@ export function registerTools(server, wm, authService) {
144
1108
  });
145
1109
  // ── find_related ──────────────────────────────────────────────────────────
146
1110
  const relatedSchema = z.object({
147
- repo: z.string().describe('Collection name'),
1111
+ repo: z.string().describe('Folder name'),
148
1112
  entity_type: z.string().describe('Entity type'),
149
1113
  entity_id: z.string().describe('Entity ID'),
150
1114
  direction: z.enum(['outgoing', 'incoming', 'both']).default('both')
@@ -152,15 +1116,33 @@ export function registerTools(server, wm, authService) {
152
1116
  });
153
1117
  server.registerTool('find_related', { description: 'Find entities related via wikilinks (outgoing) or backlinks (incoming)', inputSchema: relatedSchema }, async (args) => {
154
1118
  const { repo, entity_type, entity_id, direction } = relatedSchema.parse(args);
1119
+ if (!hasRepoAccess(user, repo, wm, authService))
1120
+ return notFound(repo);
155
1121
  try {
1122
+ const accessibleIds = getAccessibleEntityIds(user, wm, authService);
156
1123
  const results = [];
157
1124
  if (direction === 'outgoing' || direction === 'both') {
158
1125
  const related = wm.getGraph(repo).getRelated(entity_type, entity_id);
159
- results.push(...related.map(e => shape(e.id, e.entityType, e.data, { direction: 'outgoing' })));
1126
+ for (const e of related) {
1127
+ if (accessibleIds && !accessibleIds.has(e.id))
1128
+ continue;
1129
+ results.push(shape(e.id, e.entityType, e.data, { direction: 'outgoing' }));
1130
+ }
160
1131
  }
161
1132
  if (direction === 'incoming' || direction === 'both') {
1133
+ // Comments anchored to this entry surface as incoming backlinks.
1134
+ if (commentService) {
1135
+ const anchored = commentVirtualEntity.findRelatedComments(commentService, repo, entity_type, entity_id);
1136
+ for (const e of anchored) {
1137
+ results.push(shape(e.id, e.entityType, e.data, { direction: 'incoming', repo }));
1138
+ }
1139
+ }
162
1140
  const backlinks = wm.getBacklinks(repo, entity_type, entity_id);
163
- results.push(...backlinks.map(e => shape(e.id, e.entityType, e.data, { direction: 'incoming', repo: e.repoName })));
1141
+ for (const e of backlinks) {
1142
+ if (!hasRepoAccess(user, e.repoName, wm, authService))
1143
+ continue;
1144
+ results.push(shape(e.id, e.entityType, e.data, { direction: 'incoming', repo: e.repoName }));
1145
+ }
164
1146
  }
165
1147
  return ok(results);
166
1148
  }
@@ -168,84 +1150,351 @@ export function registerTools(server, wm, authService) {
168
1150
  return fail(err);
169
1151
  }
170
1152
  });
171
- // ── View management tools ────────────────────────────────────────────────
172
- if (authService) {
173
- server.registerTool('list_views', { description: 'List the current user\'s saved views.', inputSchema: z.object({}) }, async () => {
174
- try {
175
- return ok(authService.getUserViews(0));
1153
+ // ── list_skills ──────────────────────────────────────────────────────────
1154
+ //
1155
+ // Surfaces user-authored `skill` entities to external MCP clients so
1156
+ // connected agents (Claude Desktop, Cursor, etc.) can discover and run
1157
+ // the workspace's codified workflows. Only graph skills (entities) are
1158
+ // exposed; bundled filesystem skills (onboarding/interview/enrichment
1159
+ // prompts) stay internal to Studiograph's own agent.
1160
+ const listSkillsSchema = z.object({
1161
+ repo: z.string().optional().describe('Folder name — omit to list across all folders you have access to'),
1162
+ });
1163
+ function projectSkill(entity, repo) {
1164
+ const data = entity.data;
1165
+ return {
1166
+ id: entity.id,
1167
+ name: data.name || entity.id,
1168
+ description: data.description ?? '',
1169
+ repo,
1170
+ loading: data.loading === 'eager' ? 'eager' : 'on-demand',
1171
+ };
1172
+ }
1173
+ // `graph.list('skill')` is lenient — root-level .md files without a
1174
+ // declared `entity_type` (READMEs, CHANGELOGs) get tagged as whatever the
1175
+ // caller asks for. For MCP we want only real skills, so require the
1176
+ // frontmatter to explicitly say `entity_type: skill`.
1177
+ function isRealSkill(entity) {
1178
+ return entity.data.entity_type === 'skill';
1179
+ }
1180
+ server.registerTool('list_skills', {
1181
+ description: 'List skills (reusable agent instructions) available in the Studiograph workspace. ' +
1182
+ 'Skills are user-authored markdown — call get_skill to read the full body and follow ' +
1183
+ 'its instructions. Optionally filter by folder.',
1184
+ inputSchema: listSkillsSchema,
1185
+ }, async (args) => {
1186
+ const { repo } = listSkillsSchema.parse(args);
1187
+ try {
1188
+ if (repo) {
1189
+ if (!hasRepoAccess(user, repo, wm, authService))
1190
+ return notFound(repo);
1191
+ const skills = wm.getGraph(repo).list('skill');
1192
+ return ok(skills.filter(isRealSkill).map(e => projectSkill(e, repo)));
176
1193
  }
177
- catch (err) {
178
- return fail(err);
1194
+ const accessible = getAccessibleRepos(user, wm, authService);
1195
+ const results = [];
1196
+ for (const r of accessible) {
1197
+ try {
1198
+ const skills = wm.getGraph(r.name).list('skill');
1199
+ for (const e of skills) {
1200
+ if (isRealSkill(e))
1201
+ results.push(projectSkill(e, r.name));
1202
+ }
1203
+ }
1204
+ catch { /* skip unmounted repos */ }
179
1205
  }
180
- });
181
- const createViewSchema = z.object({
182
- name: z.string().describe('View name'),
183
- selected_type: z.string().optional().describe('Entity type filter (e.g. "task")'),
184
- group_by: z.string().optional().describe('Column to group by (e.g. "status")'),
185
- });
186
- server.registerTool('create_view', { description: 'Create a new saved view. Views appear as tabs in the web UI toolbar.', inputSchema: createViewSchema }, async (args) => {
187
- const { name, selected_type, group_by } = createViewSchema.parse(args);
188
- try {
189
- const config = {
190
- selectedType: selected_type ?? null,
191
- groupBy: group_by ?? null,
192
- sortKey: 'name',
193
- sortAsc: true,
194
- filters: { text: {}, enum: {}, date: {} },
195
- };
196
- const view = authService.createUserView(0, name, 'list', config);
197
- return ok({ success: true, view: { id: view.id, name: view.name, config: view.config } });
1206
+ return ok(results);
1207
+ }
1208
+ catch (err) {
1209
+ return fail(err);
1210
+ }
1211
+ });
1212
+ // ── get_skill ────────────────────────────────────────────────────────────
1213
+ //
1214
+ // Returns the full markdown body of a skill alongside its metadata. The
1215
+ // body is instructions to follow — the MCP client is the runtime. No
1216
+ // server-side agent loop, no parameter substitution in v1.
1217
+ const getSkillSchema = z.object({
1218
+ name: z.string().describe('Skill id (the entity_id of the skill entity)'),
1219
+ repo: z.string().optional().describe('Folder to look in. Omit to search across all accessible folders.'),
1220
+ });
1221
+ server.registerTool('get_skill', {
1222
+ description: 'Fetch the full content of a skill. Returns the skill\'s markdown body along with its ' +
1223
+ 'metadata. The body contains instructions to follow read it and apply it to the current task.',
1224
+ inputSchema: getSkillSchema,
1225
+ }, async (args) => {
1226
+ const { name, repo } = getSkillSchema.parse(args);
1227
+ try {
1228
+ if (repo) {
1229
+ if (!hasRepoAccess(user, repo, wm, authService))
1230
+ return notFound(repo);
1231
+ try {
1232
+ const entity = wm.getGraph(repo).get('skill', name);
1233
+ if (!isRealSkill({ data: entity.data })) {
1234
+ return fail(new Error(`Skill "${name}" not found`));
1235
+ }
1236
+ return ok({
1237
+ ...projectSkill({ id: entity.id, data: entity.data }, repo),
1238
+ content: entity.document.content,
1239
+ });
1240
+ }
1241
+ catch {
1242
+ return fail(new Error(`Skill "${name}" not found`));
1243
+ }
198
1244
  }
199
- catch (err) {
200
- return fail(err);
1245
+ // No repo — search accessible folders for the skill by id.
1246
+ const accessible = getAccessibleRepos(user, wm, authService);
1247
+ const matches = [];
1248
+ for (const r of accessible) {
1249
+ try {
1250
+ const entity = wm.getGraph(r.name).get('skill', name);
1251
+ if (!isRealSkill({ data: entity.data }))
1252
+ continue;
1253
+ matches.push({ repo: r.name, entity });
1254
+ }
1255
+ catch { /* not in this repo */ }
201
1256
  }
202
- });
203
- const updateViewSchema = z.object({
204
- id: z.number().describe('View ID'),
205
- name: z.string().optional().describe('New view name'),
206
- selected_type: z.string().optional().describe('Entity type filter (use "all" to clear)'),
207
- group_by: z.string().optional().describe('Column to group by (use "none" to clear)'),
208
- });
209
- server.registerTool('update_view', { description: 'Update a saved view\'s name or configuration.', inputSchema: updateViewSchema }, async (args) => {
210
- const { id, name, selected_type, group_by } = updateViewSchema.parse(args);
1257
+ if (matches.length === 0)
1258
+ return fail(new Error(`Skill "${name}" not found`));
1259
+ if (matches.length > 1) {
1260
+ const folders = matches.map(m => m.repo).join(', ');
1261
+ return fail(new Error(`Skill "${name}" exists in multiple folders (${folders}). Specify repo.`));
1262
+ }
1263
+ const { repo: matchRepo, entity } = matches[0];
1264
+ return ok({
1265
+ ...projectSkill({ id: entity.id, data: entity.data }, matchRepo),
1266
+ content: entity.document.content,
1267
+ });
1268
+ }
1269
+ catch (err) {
1270
+ return fail(err);
1271
+ }
1272
+ });
1273
+ // ── Git history tools ──────────────────────────────────────────────────────
1274
+ //
1275
+ // Mirrors the agent's history-tools.ts surface so external MCP clients get
1276
+ // the same primitives. Reads gated on hasRepoAccess; restore_file gated on
1277
+ // canWriteRepo. Single-entity scope only — multi-entity rollback is
1278
+ // intentionally absent (deferred to a future revert_commit).
1279
+ const listFileHistorySchema = z.object({
1280
+ repo: z.string().describe('Folder name'),
1281
+ entity_type: z.string().describe('Entity type'),
1282
+ entity_id: z.string().describe('Entry ID'),
1283
+ limit: z.number().optional().describe('Max commits (default 20, max 100)'),
1284
+ });
1285
+ server.registerTool('list_file_history', { description: 'List commits that touched a single entry, newest first.', inputSchema: listFileHistorySchema }, async (args) => {
1286
+ const { repo, entity_type, entity_id, limit } = listFileHistorySchema.parse(args);
1287
+ try {
1288
+ if (!hasRepoAccess(user, repo, wm, authService))
1289
+ return fail(`Folder "${repo}" not found`);
1290
+ const graph = wm.getGraph(repo);
1291
+ const gitService = graph.getGitService();
1292
+ if (!gitService)
1293
+ return fail('Folder is not git-backed');
1294
+ let entityPath;
211
1295
  try {
212
- const existing = authService.getUserView(id, 0);
213
- if (!existing)
214
- return fail(`View ${id} not found`);
215
- const fields = {};
216
- if (name)
217
- fields.name = name;
218
- if (selected_type !== undefined || group_by !== undefined) {
219
- const config = { ...existing.config };
220
- if (selected_type !== undefined)
221
- config.selectedType = selected_type === 'all' ? null : selected_type;
222
- if (group_by !== undefined)
223
- config.groupBy = group_by === 'none' ? null : group_by;
224
- fields.config = config;
225
- }
226
- authService.updateUserView(id, 0, fields);
227
- return ok({ success: true });
1296
+ const entity = graph.get(entity_type, entity_id);
1297
+ const { relative: relativePath } = await import('path');
1298
+ entityPath = relativePath(graph.getRepoPath(), entity.path);
228
1299
  }
229
- catch (err) {
230
- return fail(err);
1300
+ catch {
1301
+ const idLower = `${entity_id}.md`.toLowerCase();
1302
+ const match = gitService.listRecentDeletions(30).find((d) => d.filePath.toLowerCase().endsWith(idLower));
1303
+ if (!match)
1304
+ return fail(`Entry ${entity_type}/${entity_id} not found in "${repo}".`);
1305
+ entityPath = match.filePath;
231
1306
  }
232
- });
233
- const deleteViewSchema = z.object({
234
- id: z.number().describe('View ID to delete'),
235
- });
236
- server.registerTool('delete_view', { description: 'Delete a saved view.', inputSchema: deleteViewSchema }, async (args) => {
237
- const { id } = deleteViewSchema.parse(args);
238
- try {
239
- const existing = authService.getUserView(id, 0);
240
- if (!existing)
241
- return fail(`View ${id} not found`);
242
- authService.deleteUserView(id, 0);
243
- return ok({ success: true, message: `Deleted view "${existing.name}"` });
1307
+ const cap = Math.min(100, Math.max(1, limit ?? 20));
1308
+ const commits = gitService.getFileHistory(entityPath, cap).map((c) => ({
1309
+ hash: c.hash.slice(0, 8),
1310
+ fullHash: c.hash,
1311
+ author: c.author,
1312
+ timestamp: c.timestamp,
1313
+ message: c.message,
1314
+ }));
1315
+ return ok({ repo, entityType: entity_type, entityId: entity_id, commits });
1316
+ }
1317
+ catch (err) {
1318
+ return fail(err);
1319
+ }
1320
+ });
1321
+ const listFolderHistorySchema = z.object({
1322
+ repo: z.string().describe('Folder name'),
1323
+ limit: z.number().optional().describe('Max commits (default 30, max 200)'),
1324
+ });
1325
+ server.registerTool('list_folder_history', { description: 'List recent commits across an entire folder.', inputSchema: listFolderHistorySchema }, async (args) => {
1326
+ const { repo, limit } = listFolderHistorySchema.parse(args);
1327
+ try {
1328
+ if (!hasRepoAccess(user, repo, wm, authService))
1329
+ return fail(`Folder "${repo}" not found`);
1330
+ const gitService = wm.getGraph(repo).getGitService();
1331
+ if (!gitService)
1332
+ return fail('Folder is not git-backed');
1333
+ const cap = Math.min(200, Math.max(1, limit ?? 30));
1334
+ const commits = gitService.getHistory(cap).map((c) => ({
1335
+ hash: c.hash.slice(0, 8),
1336
+ fullHash: c.hash,
1337
+ author: c.author,
1338
+ timestamp: c.timestamp,
1339
+ message: c.message,
1340
+ }));
1341
+ return ok({ repo, commits });
1342
+ }
1343
+ catch (err) {
1344
+ return fail(err);
1345
+ }
1346
+ });
1347
+ const listRecentDeletionsSchema = z.object({
1348
+ repo: z.string().describe('Folder name'),
1349
+ within_days: z.number().optional().describe('Lookback window (default 7, max 90)'),
1350
+ });
1351
+ server.registerTool('list_recent_deletions', { description: 'List entries deleted within the last N days. Use before restore_file to find a target.', inputSchema: listRecentDeletionsSchema }, async (args) => {
1352
+ const { repo, within_days } = listRecentDeletionsSchema.parse(args);
1353
+ try {
1354
+ if (!hasRepoAccess(user, repo, wm, authService))
1355
+ return fail(`Folder "${repo}" not found`);
1356
+ const gitService = wm.getGraph(repo).getGitService();
1357
+ if (!gitService)
1358
+ return fail('Folder is not git-backed');
1359
+ const days = Math.min(90, Math.max(1, within_days ?? 7));
1360
+ const raw = gitService.listRecentDeletions(days);
1361
+ // Naive coords: use filename basename for entity_id; entity_type
1362
+ // sniffed from frontmatter at lastVersionCommit.
1363
+ const deletions = raw.map((d) => {
1364
+ const idMatch = d.filePath.match(/([^/]+)\.md$/i);
1365
+ const entityId = idMatch ? idMatch[1] : null;
1366
+ const content = entityId ? gitService.getFileAtCommit(d.filePath, d.lastVersionCommit) : null;
1367
+ let entityType = null;
1368
+ if (content) {
1369
+ const fm = content.match(/^---\s*\n([\s\S]*?)\n---/);
1370
+ const tm = fm?.[1].match(/^entity_type:\s*['"]?([\w-]+)['"]?\s*$/m);
1371
+ if (tm)
1372
+ entityType = tm[1];
1373
+ }
1374
+ if (!entityId || !entityType)
1375
+ return null;
1376
+ return {
1377
+ entityType,
1378
+ entityId,
1379
+ deletedAt: d.deletedAt,
1380
+ deletedBy: d.deletedBy.name,
1381
+ deletedInCommit: d.deletedAtCommit.slice(0, 8),
1382
+ lastVersionCommit: d.lastVersionCommit,
1383
+ commitMessage: d.commitMessage,
1384
+ path: d.filePath,
1385
+ };
1386
+ }).filter((x) => x !== null);
1387
+ return ok({ repo, withinDays: days, deletions });
1388
+ }
1389
+ catch (err) {
1390
+ return fail(err);
1391
+ }
1392
+ });
1393
+ const readFileAtCommitSchema = z.object({
1394
+ repo: z.string().describe('Folder name'),
1395
+ entity_type: z.string().describe('Entity type'),
1396
+ entity_id: z.string().describe('Entry ID'),
1397
+ commit_hash: z.string().describe('Commit hash (short or full)'),
1398
+ });
1399
+ server.registerTool('read_file_at_commit', { description: 'Read an entry\'s full content at a specific commit.', inputSchema: readFileAtCommitSchema }, async (args) => {
1400
+ const { repo, entity_type, entity_id, commit_hash } = readFileAtCommitSchema.parse(args);
1401
+ try {
1402
+ if (!hasRepoAccess(user, repo, wm, authService))
1403
+ return fail(`Folder "${repo}" not found`);
1404
+ const graph = wm.getGraph(repo);
1405
+ const found = graph.getEntityAtCommit(entity_type, entity_id, commit_hash);
1406
+ if (!found)
1407
+ return fail(`Entry ${entity_type}/${entity_id} not found at commit ${commit_hash}`);
1408
+ // Surface the image/asset embeds present in the body at this commit so
1409
+ // a caller can verify whether images existed here without diffing the
1410
+ // raw markdown by eye. Asset *binaries* aren't in git — these are the
1411
+ // body references, the only image evidence git retains.
1412
+ const embeds = extractAssetEmbeds(stripFrontmatter(found.content));
1413
+ return ok({ repo, entityType: entity_type, entityId: entity_id, commitHash: commit_hash, path: found.path, content: found.content, embeds, embedCount: embeds.length });
1414
+ }
1415
+ catch (err) {
1416
+ return fail(err);
1417
+ }
1418
+ });
1419
+ const restoreFileSchema = z.object({
1420
+ repo: z.string().describe('Folder name'),
1421
+ entity_type: z.string().describe('Entity type'),
1422
+ entity_id: z.string().describe('Entry ID'),
1423
+ commit_hash: z.string().describe('Commit hash to restore from'),
1424
+ confirm: z.boolean().optional().describe('Set to true ONLY after the user has approved the preview. Defaults to false.'),
1425
+ });
1426
+ server.registerTool('restore_file', { description: 'Restore an entry to its content at a specific commit. Preview-then-confirm: first call returns the preview payload, re-invoke with confirm: true to execute.', inputSchema: restoreFileSchema }, async (args) => {
1427
+ const { repo, entity_type, entity_id, commit_hash, confirm } = restoreFileSchema.parse(args);
1428
+ try {
1429
+ if (!hasRepoAccess(user, repo, wm, authService))
1430
+ return fail(`Folder "${repo}" not found`);
1431
+ if (!canWriteRepo(user, repo, wm, authService))
1432
+ return fail(`You don't have permission to write to "${repo}". Editor or admin role required.`);
1433
+ const graph = wm.getGraph(repo);
1434
+ if (confirm !== true) {
1435
+ const found = graph.getEntityAtCommit(entity_type, entity_id, commit_hash);
1436
+ if (!found)
1437
+ return fail(`Entry ${entity_type}/${entity_id} not found at commit ${commit_hash}`);
1438
+ let action = 'recreate';
1439
+ try {
1440
+ graph.get(entity_type, entity_id);
1441
+ action = 'overwrite';
1442
+ }
1443
+ catch { }
1444
+ const sizeBytes = Buffer.byteLength(found.content, 'utf-8');
1445
+ const shortHash = commit_hash.length > 8 ? commit_hash.slice(0, 8) : commit_hash;
1446
+ // Embeds the restored body will re-link. Restore rewrites the .md
1447
+ // body only; asset binaries live outside git and are NOT touched by
1448
+ // restore — they remain wherever they are (intact unless separately
1449
+ // deleted), so restoring the body re-links any that still exist.
1450
+ const embeds = extractAssetEmbeds(stripFrontmatter(found.content));
1451
+ const assetNote = embeds.length
1452
+ ? `Restores the body and re-links ${embeds.length} embedded asset reference(s): ${embeds.join(', ')}. ` +
1453
+ `Asset binaries are stored outside git and are not modified by restore (they remain intact unless separately deleted). `
1454
+ : '';
1455
+ return ok({
1456
+ success: false,
1457
+ code: 'PREVIEW_REQUIRED',
1458
+ preview: { action, targetPath: found.path, sizeBytes, commitHash: shortHash, embeds, embedCount: embeds.length },
1459
+ message: `Will ${action} ${entity_type}/${entity_id} from ${shortHash} (${sizeBytes} bytes). ${assetNote}Re-invoke with confirm: true after approval.`,
1460
+ });
244
1461
  }
245
- catch (err) {
246
- return fail(err);
1462
+ const result = await withAgentActivity(repo, 'editing', async () => {
1463
+ const { PathConflictError } = await import('../core/graph.js');
1464
+ try {
1465
+ return await graph.restoreFile(entity_type, entity_id, commit_hash);
1466
+ }
1467
+ catch (err) {
1468
+ if (err instanceof PathConflictError) {
1469
+ return { conflict: { path: err.path, occupiedBy: err.occupiedBy } };
1470
+ }
1471
+ throw err;
1472
+ }
1473
+ });
1474
+ if ('conflict' in result) {
1475
+ return ok({
1476
+ success: false,
1477
+ code: 'PATH_CONFLICT',
1478
+ conflict: result.conflict,
1479
+ message: `Cannot restore — ${result.conflict.path} is occupied by ${result.conflict.occupiedBy.entityType}/${result.conflict.occupiedBy.entityId}.`,
1480
+ });
247
1481
  }
248
- });
249
- }
1482
+ emitEntityChange(result.action === 'recreate' ? 'created' : 'updated', repo, entity_type, entity_id);
1483
+ const shortHash = commit_hash.length > 8 ? commit_hash.slice(0, 8) : commit_hash;
1484
+ return ok({
1485
+ success: true,
1486
+ repo,
1487
+ entityType: entity_type,
1488
+ entityId: entity_id,
1489
+ action: result.action,
1490
+ path: result.path,
1491
+ commitHash: shortHash,
1492
+ message: `Restored ${entity_type}/${entity_id} from ${shortHash} (${result.action}).`,
1493
+ });
1494
+ }
1495
+ catch (err) {
1496
+ return fail(err);
1497
+ }
1498
+ });
250
1499
  }
251
1500
  //# sourceMappingURL=tools.js.map