studiograph 1.1.2 → 1.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (349) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +301 -10
  3. package/dist/agent/orchestrator.d.ts +17 -9
  4. package/dist/agent/orchestrator.js +142 -97
  5. package/dist/agent/orchestrator.js.map +1 -1
  6. package/dist/agent/prompts/system.md +186 -0
  7. package/dist/agent/skill-loader.d.ts +48 -0
  8. package/dist/agent/skill-loader.js +166 -0
  9. package/dist/agent/skill-loader.js.map +1 -0
  10. package/dist/agent/skills/enrich-entities.md +136 -0
  11. package/dist/agent/skills/entity-schema.md +502 -0
  12. package/dist/agent/skills/gather-context.md +46 -0
  13. package/dist/agent/skills/obsidian-source-setup.md +246 -0
  14. package/dist/agent/skills/skill-loader.d.ts +48 -0
  15. package/dist/agent/skills/skill-loader.js +166 -0
  16. package/dist/agent/skills/skill-loader.js.map +1 -0
  17. package/dist/agent/skills/sync-configuration.md +144 -0
  18. package/dist/agent/skills/sync-setup.md +68 -0
  19. package/dist/agent/tools/connector-tools.d.ts +37 -0
  20. package/dist/agent/tools/connector-tools.js +132 -0
  21. package/dist/agent/tools/connector-tools.js.map +1 -0
  22. package/dist/agent/tools/fs-tools.d.ts +39 -0
  23. package/dist/agent/tools/fs-tools.js +106 -0
  24. package/dist/agent/tools/fs-tools.js.map +1 -0
  25. package/dist/agent/tools/graph-tools.d.ts +30 -2
  26. package/dist/agent/tools/graph-tools.js +154 -37
  27. package/dist/agent/tools/graph-tools.js.map +1 -1
  28. package/dist/agent/tools/load-skill.d.ts +42 -0
  29. package/dist/agent/tools/load-skill.js +45 -0
  30. package/dist/agent/tools/load-skill.js.map +1 -0
  31. package/dist/agent/tools/sync-tools.d.ts +25 -0
  32. package/dist/agent/tools/sync-tools.js +691 -0
  33. package/dist/agent/tools/sync-tools.js.map +1 -0
  34. package/dist/agent/tools/tool-loader.d.ts +25 -0
  35. package/dist/agent/tools/tool-loader.js +73 -0
  36. package/dist/agent/tools/tool-loader.js.map +1 -0
  37. package/dist/auth/github.d.ts +11 -8
  38. package/dist/auth/github.js +56 -75
  39. package/dist/auth/github.js.map +1 -1
  40. package/dist/cli/colors.d.ts +54 -0
  41. package/dist/cli/colors.js +133 -0
  42. package/dist/cli/colors.js.map +1 -0
  43. package/dist/cli/commands/app.d.ts +7 -0
  44. package/dist/cli/commands/app.js +167 -0
  45. package/dist/cli/commands/app.js.map +1 -0
  46. package/dist/cli/commands/auth.d.ts +1 -1
  47. package/dist/cli/commands/auth.js +26 -10
  48. package/dist/cli/commands/auth.js.map +1 -1
  49. package/dist/cli/commands/clone.d.ts +9 -0
  50. package/dist/cli/commands/clone.js +167 -0
  51. package/dist/cli/commands/clone.js.map +1 -0
  52. package/dist/cli/commands/commit.d.ts +8 -0
  53. package/dist/cli/commands/commit.js +43 -0
  54. package/dist/cli/commands/commit.js.map +1 -0
  55. package/dist/cli/commands/config.d.ts +13 -0
  56. package/dist/cli/commands/config.js +276 -0
  57. package/dist/cli/commands/config.js.map +1 -0
  58. package/dist/cli/commands/connector.d.ts +33 -0
  59. package/dist/cli/commands/connector.js +178 -0
  60. package/dist/cli/commands/connector.js.map +1 -0
  61. package/dist/cli/commands/deploy.d.ts +11 -0
  62. package/dist/cli/commands/deploy.js +153 -0
  63. package/dist/cli/commands/deploy.js.map +1 -0
  64. package/dist/cli/commands/enrich.d.ts +11 -0
  65. package/dist/cli/commands/enrich.js +135 -0
  66. package/dist/cli/commands/enrich.js.map +1 -0
  67. package/dist/cli/commands/graphrag.d.ts +12 -0
  68. package/dist/cli/commands/graphrag.js +122 -0
  69. package/dist/cli/commands/graphrag.js.map +1 -0
  70. package/dist/cli/commands/index.d.ts +15 -0
  71. package/dist/cli/commands/index.js +117 -0
  72. package/dist/cli/commands/index.js.map +1 -0
  73. package/dist/cli/commands/init.js +110 -210
  74. package/dist/cli/commands/init.js.map +1 -1
  75. package/dist/cli/commands/join.js +89 -24
  76. package/dist/cli/commands/join.js.map +1 -1
  77. package/dist/cli/commands/lint.d.ts +8 -0
  78. package/dist/cli/commands/lint.js +70 -0
  79. package/dist/cli/commands/lint.js.map +1 -0
  80. package/dist/cli/commands/mcp.d.ts +27 -0
  81. package/dist/cli/commands/mcp.js +56 -0
  82. package/dist/cli/commands/mcp.js.map +1 -0
  83. package/dist/cli/commands/orphans.d.ts +8 -0
  84. package/dist/cli/commands/orphans.js +125 -0
  85. package/dist/cli/commands/orphans.js.map +1 -0
  86. package/dist/cli/commands/provision.d.ts +8 -0
  87. package/dist/cli/commands/provision.js +116 -0
  88. package/dist/cli/commands/provision.js.map +1 -0
  89. package/dist/cli/commands/r2.d.ts +2 -0
  90. package/dist/cli/commands/r2.js +87 -6
  91. package/dist/cli/commands/r2.js.map +1 -1
  92. package/dist/cli/commands/reset.d.ts +12 -0
  93. package/dist/cli/commands/reset.js +137 -0
  94. package/dist/cli/commands/reset.js.map +1 -0
  95. package/dist/cli/commands/review.d.ts +19 -0
  96. package/dist/cli/commands/review.js +128 -0
  97. package/dist/cli/commands/review.js.map +1 -0
  98. package/dist/cli/commands/serve.js +47 -2
  99. package/dist/cli/commands/serve.js.map +1 -1
  100. package/dist/cli/commands/source.d.ts +16 -0
  101. package/dist/cli/commands/source.js +159 -0
  102. package/dist/cli/commands/source.js.map +1 -0
  103. package/dist/cli/commands/start.js +472 -103
  104. package/dist/cli/commands/start.js.map +1 -1
  105. package/dist/cli/commands/sync-entities.d.ts +13 -0
  106. package/dist/cli/commands/sync-entities.js +242 -0
  107. package/dist/cli/commands/sync-entities.js.map +1 -0
  108. package/dist/cli/commands/sync.js +40 -9
  109. package/dist/cli/commands/sync.js.map +1 -1
  110. package/dist/cli/commands/update.d.ts +8 -0
  111. package/dist/cli/commands/update.js +155 -0
  112. package/dist/cli/commands/update.js.map +1 -0
  113. package/dist/cli/index.js +114 -3
  114. package/dist/cli/index.js.map +1 -1
  115. package/dist/cli/scaffolding.d.ts +10 -0
  116. package/dist/cli/scaffolding.js +302 -0
  117. package/dist/cli/scaffolding.js.map +1 -0
  118. package/dist/cli/setup-wizard.d.ts +30 -0
  119. package/dist/cli/setup-wizard.js +244 -0
  120. package/dist/cli/setup-wizard.js.map +1 -0
  121. package/dist/cli/sync-review-interactive.d.ts +31 -0
  122. package/dist/cli/sync-review-interactive.js +393 -0
  123. package/dist/cli/sync-review-interactive.js.map +1 -0
  124. package/dist/cli/theme.d.ts +31 -0
  125. package/dist/cli/theme.js +116 -0
  126. package/dist/cli/theme.js.map +1 -0
  127. package/dist/core/graph.d.ts +16 -9
  128. package/dist/core/graph.js +263 -145
  129. package/dist/core/graph.js.map +1 -1
  130. package/dist/core/migration-runner.d.ts +42 -0
  131. package/dist/core/migration-runner.js +232 -0
  132. package/dist/core/migration-runner.js.map +1 -0
  133. package/dist/core/migration-types.d.ts +101 -0
  134. package/dist/core/migration-types.js +21 -0
  135. package/dist/core/migration-types.js.map +1 -0
  136. package/dist/core/migrations/20260219-formalize-memory-location.d.ts +2 -0
  137. package/dist/core/migrations/20260219-formalize-memory-location.js +35 -0
  138. package/dist/core/migrations/20260219-formalize-memory-location.js.map +1 -0
  139. package/dist/core/migrations/20260220-add-workspace-metadata.d.ts +12 -0
  140. package/dist/core/migrations/20260220-add-workspace-metadata.js +65 -0
  141. package/dist/core/migrations/20260220-add-workspace-metadata.js.map +1 -0
  142. package/dist/core/migrations/20260220-add-workspace-readme.d.ts +11 -0
  143. package/dist/core/migrations/20260220-add-workspace-readme.js +82 -0
  144. package/dist/core/migrations/20260220-add-workspace-readme.js.map +1 -0
  145. package/dist/core/migrations/20260220-migrate-yaml-to-json.d.ts +9 -0
  146. package/dist/core/migrations/20260220-migrate-yaml-to-json.js +64 -0
  147. package/dist/core/migrations/20260220-migrate-yaml-to-json.js.map +1 -0
  148. package/dist/core/migrations/index.d.ts +11 -0
  149. package/dist/core/migrations/index.js +23 -0
  150. package/dist/core/migrations/index.js.map +1 -0
  151. package/dist/core/schema-registry.d.ts +36 -0
  152. package/dist/core/schema-registry.js +161 -0
  153. package/dist/core/schema-registry.js.map +1 -0
  154. package/dist/core/types.d.ts +242 -3
  155. package/dist/core/types.js +21 -2
  156. package/dist/core/types.js.map +1 -1
  157. package/dist/core/user-config.d.ts +16 -0
  158. package/dist/core/user-config.js +8 -0
  159. package/dist/core/user-config.js.map +1 -1
  160. package/dist/core/validation.d.ts +973 -32
  161. package/dist/core/validation.js +163 -4
  162. package/dist/core/validation.js.map +1 -1
  163. package/dist/core/workspace-manager.d.ts +26 -2
  164. package/dist/core/workspace-manager.js +113 -15
  165. package/dist/core/workspace-manager.js.map +1 -1
  166. package/dist/core/workspace.d.ts +20 -11
  167. package/dist/core/workspace.js +123 -34
  168. package/dist/core/workspace.js.map +1 -1
  169. package/dist/mcp/connector-manager.d.ts +65 -0
  170. package/dist/mcp/connector-manager.js +223 -0
  171. package/dist/mcp/connector-manager.js.map +1 -0
  172. package/dist/mcp/connectors/asana.d.ts +2 -0
  173. package/dist/mcp/connectors/asana.js +20 -0
  174. package/dist/mcp/connectors/asana.js.map +1 -0
  175. package/dist/mcp/connectors/definitions.d.ts +45 -0
  176. package/dist/mcp/connectors/definitions.js +32 -0
  177. package/dist/mcp/connectors/definitions.js.map +1 -0
  178. package/dist/mcp/connectors/figma.d.ts +5 -0
  179. package/dist/mcp/connectors/figma.js +21 -0
  180. package/dist/mcp/connectors/figma.js.map +1 -0
  181. package/dist/mcp/connectors/gdrive.d.ts +2 -0
  182. package/dist/mcp/connectors/gdrive.js +20 -0
  183. package/dist/mcp/connectors/gdrive.js.map +1 -0
  184. package/dist/mcp/connectors/granola.d.ts +2 -0
  185. package/dist/mcp/connectors/granola.js +12 -0
  186. package/dist/mcp/connectors/granola.js.map +1 -0
  187. package/dist/mcp/connectors/linear.d.ts +2 -0
  188. package/dist/mcp/connectors/linear.js +19 -0
  189. package/dist/mcp/connectors/linear.js.map +1 -0
  190. package/dist/mcp/connectors/obsidian.d.ts +2 -0
  191. package/dist/mcp/connectors/obsidian.js +19 -0
  192. package/dist/mcp/connectors/obsidian.js.map +1 -0
  193. package/dist/mcp/connectors/pipedrive.d.ts +2 -0
  194. package/dist/mcp/connectors/pipedrive.js +20 -0
  195. package/dist/mcp/connectors/pipedrive.js.map +1 -0
  196. package/dist/mcp/connectors/slack.d.ts +2 -0
  197. package/dist/mcp/connectors/slack.js +21 -0
  198. package/dist/mcp/connectors/slack.js.map +1 -0
  199. package/dist/mcp/oauth-provider.d.ts +41 -0
  200. package/dist/mcp/oauth-provider.js +160 -0
  201. package/dist/mcp/oauth-provider.js.map +1 -0
  202. package/dist/mcp/server.d.ts +11 -0
  203. package/dist/mcp/server.js +28 -0
  204. package/dist/mcp/server.js.map +1 -0
  205. package/dist/mcp/tools.d.ts +14 -0
  206. package/dist/mcp/tools.js +172 -0
  207. package/dist/mcp/tools.js.map +1 -0
  208. package/dist/server/index.js +17 -4
  209. package/dist/server/index.js.map +1 -1
  210. package/dist/server/plugin-loader.d.ts +15 -0
  211. package/dist/server/plugin-loader.js +68 -2
  212. package/dist/server/plugin-loader.js.map +1 -1
  213. package/dist/server/routes/graph-api.js +1 -1
  214. package/dist/server/routes/graph-api.js.map +1 -1
  215. package/dist/server/routes/webhook.js +33 -0
  216. package/dist/server/routes/webhook.js.map +1 -1
  217. package/dist/services/github-provisioner.d.ts +9 -3
  218. package/dist/services/github-provisioner.js +46 -8
  219. package/dist/services/github-provisioner.js.map +1 -1
  220. package/dist/services/lint-service.d.ts +27 -0
  221. package/dist/services/lint-service.js +83 -0
  222. package/dist/services/lint-service.js.map +1 -0
  223. package/dist/services/markdown.d.ts +9 -0
  224. package/dist/services/markdown.js +26 -5
  225. package/dist/services/markdown.js.map +1 -1
  226. package/dist/services/memory-service.d.ts +1 -2
  227. package/dist/services/memory-service.js +5 -4
  228. package/dist/services/memory-service.js.map +1 -1
  229. package/dist/services/orphan-service.d.ts +31 -0
  230. package/dist/services/orphan-service.js +100 -0
  231. package/dist/services/orphan-service.js.map +1 -0
  232. package/dist/services/sync/commit.d.ts +58 -0
  233. package/dist/services/sync/commit.js +350 -0
  234. package/dist/services/sync/commit.js.map +1 -0
  235. package/dist/services/sync/context-index.d.ts +69 -0
  236. package/dist/services/sync/context-index.js +280 -0
  237. package/dist/services/sync/context-index.js.map +1 -0
  238. package/dist/services/sync/derive.d.ts +34 -0
  239. package/dist/services/sync/derive.js +164 -0
  240. package/dist/services/sync/derive.js.map +1 -0
  241. package/dist/services/sync/enrichment-state.d.ts +31 -0
  242. package/dist/services/sync/enrichment-state.js +63 -0
  243. package/dist/services/sync/enrichment-state.js.map +1 -0
  244. package/dist/services/sync/enrichment.d.ts +25 -0
  245. package/dist/services/sync/enrichment.js +121 -0
  246. package/dist/services/sync/enrichment.js.map +1 -0
  247. package/dist/services/sync/frontmatter-extractor.d.ts +40 -0
  248. package/dist/services/sync/frontmatter-extractor.js +273 -0
  249. package/dist/services/sync/frontmatter-extractor.js.map +1 -0
  250. package/dist/services/sync/graph-match-state.d.ts +33 -0
  251. package/dist/services/sync/graph-match-state.js +61 -0
  252. package/dist/services/sync/graph-match-state.js.map +1 -0
  253. package/dist/services/sync/graph-match.d.ts +53 -0
  254. package/dist/services/sync/graph-match.js +316 -0
  255. package/dist/services/sync/graph-match.js.map +1 -0
  256. package/dist/services/sync/graphrag-client.d.ts +43 -0
  257. package/dist/services/sync/graphrag-client.js +94 -0
  258. package/dist/services/sync/graphrag-client.js.map +1 -0
  259. package/dist/services/sync/graphrag-config.d.ts +16 -0
  260. package/dist/services/sync/graphrag-config.js +39 -0
  261. package/dist/services/sync/graphrag-config.js.map +1 -0
  262. package/dist/services/sync/graphrag-context.d.ts +14 -0
  263. package/dist/services/sync/graphrag-context.js +109 -0
  264. package/dist/services/sync/graphrag-context.js.map +1 -0
  265. package/dist/services/sync/graphrag-indexer.d.ts +30 -0
  266. package/dist/services/sync/graphrag-indexer.js +358 -0
  267. package/dist/services/sync/graphrag-indexer.js.map +1 -0
  268. package/dist/services/sync/llm.d.ts +32 -0
  269. package/dist/services/sync/llm.js +115 -0
  270. package/dist/services/sync/llm.js.map +1 -0
  271. package/dist/services/sync/mcp-client.d.ts +59 -0
  272. package/dist/services/sync/mcp-client.js +285 -0
  273. package/dist/services/sync/mcp-client.js.map +1 -0
  274. package/dist/services/sync/model-factory.d.ts +10 -0
  275. package/dist/services/sync/model-factory.js +24 -0
  276. package/dist/services/sync/model-factory.js.map +1 -0
  277. package/dist/services/sync/name-quality.d.ts +31 -0
  278. package/dist/services/sync/name-quality.js +60 -0
  279. package/dist/services/sync/name-quality.js.map +1 -0
  280. package/dist/services/sync/output-schemas.d.ts +92 -0
  281. package/dist/services/sync/output-schemas.js +43 -0
  282. package/dist/services/sync/output-schemas.js.map +1 -0
  283. package/dist/services/sync/prompts.d.ts +19 -0
  284. package/dist/services/sync/prompts.js +128 -0
  285. package/dist/services/sync/prompts.js.map +1 -0
  286. package/dist/services/sync/reconciler.d.ts +48 -0
  287. package/dist/services/sync/reconciler.js +295 -0
  288. package/dist/services/sync/reconciler.js.map +1 -0
  289. package/dist/services/sync/source-config.d.ts +45 -0
  290. package/dist/services/sync/source-config.js +208 -0
  291. package/dist/services/sync/source-config.js.map +1 -0
  292. package/dist/services/sync/source-definitions/asana.d.ts +15 -0
  293. package/dist/services/sync/source-definitions/asana.js +48 -0
  294. package/dist/services/sync/source-definitions/asana.js.map +1 -0
  295. package/dist/services/sync/source-definitions/definitions.d.ts +21 -0
  296. package/dist/services/sync/source-definitions/definitions.js +26 -0
  297. package/dist/services/sync/source-definitions/definitions.js.map +1 -0
  298. package/dist/services/sync/source-definitions/gdrive.d.ts +16 -0
  299. package/dist/services/sync/source-definitions/gdrive.js +68 -0
  300. package/dist/services/sync/source-definitions/gdrive.js.map +1 -0
  301. package/dist/services/sync/source-definitions/granola.d.ts +2 -0
  302. package/dist/services/sync/source-definitions/granola.js +28 -0
  303. package/dist/services/sync/source-definitions/granola.js.map +1 -0
  304. package/dist/services/sync/source-definitions/linear.d.ts +2 -0
  305. package/dist/services/sync/source-definitions/linear.js +60 -0
  306. package/dist/services/sync/source-definitions/linear.js.map +1 -0
  307. package/dist/services/sync/source-definitions/obsidian.d.ts +2 -0
  308. package/dist/services/sync/source-definitions/obsidian.js +55 -0
  309. package/dist/services/sync/source-definitions/obsidian.js.map +1 -0
  310. package/dist/services/sync/source-definitions/pipedrive.d.ts +2 -0
  311. package/dist/services/sync/source-definitions/pipedrive.js +52 -0
  312. package/dist/services/sync/source-definitions/pipedrive.js.map +1 -0
  313. package/dist/services/sync/staging.d.ts +53 -0
  314. package/dist/services/sync/staging.js +131 -0
  315. package/dist/services/sync/staging.js.map +1 -0
  316. package/dist/services/sync/structured-extractor.d.ts +49 -0
  317. package/dist/services/sync/structured-extractor.js +344 -0
  318. package/dist/services/sync/structured-extractor.js.map +1 -0
  319. package/dist/services/sync/sync-runner.d.ts +32 -0
  320. package/dist/services/sync/sync-runner.js +195 -0
  321. package/dist/services/sync/sync-runner.js.map +1 -0
  322. package/dist/services/sync/sync-state.d.ts +43 -0
  323. package/dist/services/sync/sync-state.js +154 -0
  324. package/dist/services/sync/sync-state.js.map +1 -0
  325. package/dist/services/sync/types.d.ts +203 -0
  326. package/dist/services/sync/types.js +8 -0
  327. package/dist/services/sync/types.js.map +1 -0
  328. package/dist/services/sync/unstructured-extractor.d.ts +29 -0
  329. package/dist/services/sync/unstructured-extractor.js +197 -0
  330. package/dist/services/sync/unstructured-extractor.js.map +1 -0
  331. package/dist/services/vector-service.d.ts +88 -0
  332. package/dist/services/vector-service.js +322 -0
  333. package/dist/services/vector-service.js.map +1 -0
  334. package/dist/utils/git.d.ts +26 -4
  335. package/dist/utils/git.js +55 -7
  336. package/dist/utils/git.js.map +1 -1
  337. package/dist/utils/merge-resolver.d.ts +34 -0
  338. package/dist/utils/merge-resolver.js +201 -0
  339. package/dist/utils/merge-resolver.js.map +1 -0
  340. package/dist/utils/preflight.d.ts +2 -1
  341. package/dist/utils/preflight.js +8 -1
  342. package/dist/utils/preflight.js.map +1 -1
  343. package/dist/utils/version-checker.d.ts +23 -0
  344. package/dist/utils/version-checker.js +116 -0
  345. package/dist/utils/version-checker.js.map +1 -0
  346. package/dist/utils/workspace-config.d.ts +8 -0
  347. package/dist/utils/workspace-config.js +22 -0
  348. package/dist/utils/workspace-config.js.map +1 -0
  349. package/package.json +24 -11
@@ -0,0 +1,109 @@
1
+ /**
2
+ * GraphRAG context builder — synchronous graph traversal.
3
+ *
4
+ * Scans source content for known node names, collects neighbors
5
+ * and edge descriptions, and formats as markdown context sections.
6
+ */
7
+ /**
8
+ * Find entities mentioned in source content and collect their graph neighbors.
9
+ */
10
+ export function getEntityContext(graph, entityName, entityType, sourceContent) {
11
+ if (graph.order === 0) {
12
+ return { formattedContext: '' };
13
+ }
14
+ const contentLower = sourceContent.toLowerCase();
15
+ // Collect all node names that appear in the source content
16
+ const matchedNodes = [];
17
+ graph.forEachNode((node, attrs) => {
18
+ const name = attrs.name ?? node;
19
+ if (name.length < 3)
20
+ return; // skip very short names to avoid false matches
21
+ if (contentLower.includes(name.toLowerCase())) {
22
+ matchedNodes.push(node);
23
+ }
24
+ });
25
+ // Also check for the explicit entity name
26
+ const entityNodeKey = findNodeByName(graph, entityName);
27
+ if (entityNodeKey && !matchedNodes.includes(entityNodeKey)) {
28
+ matchedNodes.push(entityNodeKey);
29
+ }
30
+ if (matchedNodes.length === 0) {
31
+ return { formattedContext: '' };
32
+ }
33
+ // Collect related entities and relationships
34
+ const relatedEntities = new Map();
35
+ const relationships = [];
36
+ for (const nodeKey of matchedNodes) {
37
+ const nodeAttrs = graph.getNodeAttributes(nodeKey);
38
+ // Add the matched node itself as context
39
+ relatedEntities.set(nodeKey, {
40
+ name: nodeAttrs.name ?? nodeKey,
41
+ type: nodeAttrs.type ?? 'unknown',
42
+ description: nodeAttrs.description ?? '',
43
+ });
44
+ // Traverse neighbors
45
+ graph.forEachNeighbor(nodeKey, (neighbor, neighborAttrs) => {
46
+ if (!relatedEntities.has(neighbor)) {
47
+ relatedEntities.set(neighbor, {
48
+ name: neighborAttrs.name ?? neighbor,
49
+ type: neighborAttrs.type ?? 'unknown',
50
+ description: neighborAttrs.description ?? '',
51
+ });
52
+ }
53
+ });
54
+ // Collect edges from this node
55
+ graph.forEachEdge(nodeKey, (_edge, edgeAttrs, source, target) => {
56
+ const sourceAttrs = graph.getNodeAttributes(source);
57
+ const targetAttrs = graph.getNodeAttributes(target);
58
+ relationships.push({
59
+ source: sourceAttrs.name ?? source,
60
+ target: targetAttrs.name ?? target,
61
+ description: edgeAttrs.description ?? '',
62
+ });
63
+ });
64
+ }
65
+ // Format as markdown
66
+ const sections = [];
67
+ if (relatedEntities.size > 0) {
68
+ const lines = ['### Related Entities'];
69
+ for (const [, entity] of relatedEntities) {
70
+ const desc = entity.description ? ` — ${entity.description}` : '';
71
+ lines.push(`- **${entity.name}** (${entity.type})${desc}`);
72
+ }
73
+ sections.push(lines.join('\n'));
74
+ }
75
+ if (relationships.length > 0) {
76
+ // Deduplicate relationships
77
+ const seen = new Set();
78
+ const lines = ['### Relationships'];
79
+ for (const rel of relationships) {
80
+ const key = `${rel.source}→${rel.target}`;
81
+ if (seen.has(key))
82
+ continue;
83
+ seen.add(key);
84
+ const desc = rel.description ? `: ${rel.description}` : '';
85
+ lines.push(`- ${rel.source} → ${rel.target}${desc}`);
86
+ }
87
+ sections.push(lines.join('\n'));
88
+ }
89
+ return {
90
+ formattedContext: sections.join('\n\n'),
91
+ };
92
+ }
93
+ /**
94
+ * Look up a node by its name attribute (case-insensitive).
95
+ */
96
+ function findNodeByName(graph, name) {
97
+ const nameLower = name.toLowerCase();
98
+ let found;
99
+ graph.forEachNode((node, attrs) => {
100
+ if (found)
101
+ return;
102
+ const nodeName = attrs.name ?? node;
103
+ if (nodeName.toLowerCase() === nameLower) {
104
+ found = node;
105
+ }
106
+ });
107
+ return found;
108
+ }
109
+ //# sourceMappingURL=graphrag-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphrag-context.js","sourceRo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AAC,CAAC,CAAC;IAClC,CAAC;IAED,OAAO;QACL,gBAAgB,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;KACxC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,KAAY,EAAE,IAAY;IAChD,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACrC,IAAI,KAAyB,CAAC;IAC9B,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAChC,IAAI,KAAK;YAAE,OAAO;QAClB,MAAM,QAAQ,GAAI,KAAK,CAAC,IAAe,IAAI,IAAI,CAAC;QAChD,IAAI,QAAQ,CAAC,WAAW,EAAE,KAAK,SAAS,EAAE,CAAC;YACzC,KAAK,GAAG,IAAI,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * GraphRAG Indexer — batch LLM extraction into a Graphology graph.
3
+ *
4
+ * Reads markdown files from a source directory, batches them into groups,
5
+ * sends each batch to the LLM for entity/relationship extraction, and
6
+ * builds a Graphology graph serialized to disk.
7
+ */
8
+ import type { GraphRAGConfig } from './graphrag-config.js';
9
+ interface IndexedFile {
10
+ path: string;
11
+ relativePath: string;
12
+ content: string;
13
+ }
14
+ export interface IndexResult {
15
+ files_processed: number;
16
+ entities_extracted: number;
17
+ relationships_extracted: number;
18
+ graph_path: string;
19
+ }
20
+ /**
21
+ * Index a directory of markdown files into a Graphology knowledge graph.
22
+ */
23
+ export declare function indexIntoGraphRAG(options: {
24
+ sourcePath: string;
25
+ config: GraphRAGConfig;
26
+ incremental?: boolean;
27
+ onProgress?: (msg: string) => void;
28
+ }): Promise<IndexResult>;
29
+ export declare function collectMarkdownFiles(dirPath: string): IndexedFile[];
30
+ export {};
@@ -0,0 +1,358 @@
1
+ /**
2
+ * GraphRAG Indexer — batch LLM extraction into a Graphology graph.
3
+ *
4
+ * Reads markdown files from a source directory, batches them into groups,
5
+ * sends each batch to the LLM for entity/relationship extraction, and
6
+ * builds a Graphology graph serialized to disk.
7
+ */
8
+ import Graph from 'graphology';
9
+ import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'fs';
10
+ import { join, dirname, relative, extname } from 'path';
11
+ import { generateText } from 'ai';
12
+ import { z } from 'zod';
13
+ import { createModel } from './model-factory.js';
14
+ import { loadUserConfig, getAnthropicCredential } from '../../core/user-config.js';
15
+ import { saveGraphRAGConfig } from './graphrag-config.js';
16
+ const BATCH_SIZE = 12;
17
+ const MAX_CHARS_PER_BATCH = 40_000; // ~10k tokens
18
+ const BATCH_CONCURRENCY = 5;
19
+ const DEFAULT_INDEXING_MODEL = 'claude-haiku-4-5-20251001';
20
+ const DEFAULT_PROVIDER = 'anthropic';
21
+ // ── Zod schemas for structured LLM output ───────────────────────────────────
22
+ const EntitySchema = z.object({
23
+ name: z.string().describe('Canonical name of the entity'),
24
+ type: z.string().describe('Entity type: person, client, project, meeting, process, deliverable, tool, concept, or other'),
25
+ description: z.string().describe('One-sentence description'),
26
+ sources: z.array(z.string()).describe('Which document filenames mention this entity'),
27
+ });
28
+ const RelationshipSchema = z.object({
29
+ source: z.string().describe('Source entity name (must match an entity name exactly)'),
30
+ target: z.string().describe('Target entity name (must match an entity name exactly)'),
31
+ description: z.string().describe('Description of the relationship'),
32
+ sources: z.array(z.string()).describe('Which document filenames evidence this relationship'),
33
+ });
34
+ const ExtractionResultSchema = z.object({
35
+ entities: z.array(EntitySchema),
36
+ relationships: z.array(RelationshipSchema).default([]),
37
+ });
38
+ const JSON_INSTRUCTION = `
39
+
40
+ Respond with ONLY a JSON object — no markdown fences, no commentary. Use this exact shape:
41
+ {
42
+ "entities": [{ "name": "...", "type": "person|client|project|meeting|process|deliverable|tool|concept", "description": "...", "sources": ["filename.md"] }],
43
+ "relationships": [{ "source": "Entity Name", "target": "Entity Name", "description": "...", "sources": ["filename.md"] }]
44
+ }`;
45
+ // ── Public API ──────────────────────────────────────────────────────────────
46
+ /**
47
+ * Index a directory of markdown files into a Graphology knowledge graph.
48
+ */
49
+ export async function indexIntoGraphRAG(options) {
50
+ const { sourcePath, config, onProgress } = options;
51
+ const log = onProgress ?? (() => { });
52
+ // Collect markdown files
53
+ log('Scanning for markdown files...');
54
+ const files = collectMarkdownFiles(sourcePath);
55
+ log(`Found ${files.length} markdown files`);
56
+ if (files.length === 0) {
57
+ return { files_processed: 0, entities_extracted: 0, relationships_extracted: 0, graph_path: config.graph_path };
58
+ }
59
+ // Load existing graph for incremental, or start fresh
60
+ const graph = new Graph();
61
+ if (options.incremental && existsSync(config.graph_path)) {
62
+ try {
63
+ const data = JSON.parse(readFileSync(config.graph_path, 'utf-8'));
64
+ graph.import(data);
65
+ log(`Loaded existing graph: ${graph.order} nodes, ${graph.size} edges`);
66
+ }
67
+ catch {
68
+ log('Could not load existing graph, starting fresh');
69
+ }
70
+ }
71
+ // Batch files
72
+ const batches = batchFiles(files);
73
+ log(`Processing ${batches.length} batches...`);
74
+ let totalEntities = 0;
75
+ let totalRelationships = 0;
76
+ // Resolve model config
77
+ const userConfig = loadUserConfig();
78
+ const provider = userConfig.model_provider ?? DEFAULT_PROVIDER;
79
+ const modelId = DEFAULT_INDEXING_MODEL; // Always use Haiku for bulk indexing — 12x cheaper than Sonnet
80
+ const apiKey = getAnthropicCredential(userConfig) ?? undefined;
81
+ const llmModel = createModel(provider, modelId, apiKey);
82
+ log(`Using model: ${modelId}`);
83
+ const failedBatches = [];
84
+ // Process batches concurrently in groups of 3
85
+ for (let i = 0; i < batches.length; i += BATCH_CONCURRENCY) {
86
+ const group = batches.slice(i, i + BATCH_CONCURRENCY);
87
+ const groupStart = i;
88
+ const results = await Promise.all(group.map(async (batch, j) => {
89
+ const batchNum = groupStart + j + 1;
90
+ log(` Batch ${batchNum}/${batches.length} (${batch.length} files)...`);
91
+ return processBatch(llmModel, batch, batchNum, batches.length, log);
92
+ }));
93
+ // Merge successes, queue failures for retry
94
+ for (let j = 0; j < results.length; j++) {
95
+ const extraction = results[j];
96
+ if (!extraction) {
97
+ failedBatches.push({ batchNum: groupStart + j + 1, batch: group[j] });
98
+ continue;
99
+ }
100
+ mergeExtraction(graph, extraction);
101
+ totalEntities += extraction.entities.length;
102
+ totalRelationships += extraction.relationships.length;
103
+ }
104
+ }
105
+ // Retry failed batches sequentially (no concurrency pressure)
106
+ if (failedBatches.length > 0) {
107
+ log(`\nRetrying ${failedBatches.length} failed batches sequentially...`);
108
+ for (const { batchNum, batch } of failedBatches) {
109
+ log(` Retry batch ${batchNum} (${batch.length} files)...`);
110
+ // Small delay to avoid rate limit
111
+ await new Promise(r => setTimeout(r, 1000));
112
+ const extraction = await processBatch(llmModel, batch, batchNum, batches.length, log);
113
+ if (extraction) {
114
+ mergeExtraction(graph, extraction);
115
+ totalEntities += extraction.entities.length;
116
+ totalRelationships += extraction.relationships.length;
117
+ }
118
+ }
119
+ }
120
+ function mergeExtraction(g, extraction) {
121
+ for (const entity of extraction.entities) {
122
+ const nodeKey = entity.name.toLowerCase().replace(/\s+/g, '-');
123
+ g.mergeNode(nodeKey, {
124
+ name: entity.name,
125
+ type: entity.type,
126
+ description: entity.description,
127
+ sources: JSON.stringify(entity.sources),
128
+ });
129
+ }
130
+ for (const rel of extraction.relationships) {
131
+ const sourceKey = rel.source.toLowerCase().replace(/\s+/g, '-');
132
+ const targetKey = rel.target.toLowerCase().replace(/\s+/g, '-');
133
+ if (g.hasNode(sourceKey) && g.hasNode(targetKey)) {
134
+ g.mergeEdge(sourceKey, targetKey, {
135
+ description: rel.description,
136
+ sources: JSON.stringify(rel.sources),
137
+ });
138
+ }
139
+ }
140
+ }
141
+ // Serialize graph to disk
142
+ mkdirSync(dirname(config.graph_path), { recursive: true });
143
+ const serialized = graph.export();
144
+ writeFileSync(config.graph_path, JSON.stringify(serialized, null, 2));
145
+ log(`\nGraph saved: ${graph.order} nodes, ${graph.size} edges → ${config.graph_path}`);
146
+ // Update config
147
+ config.last_indexed = new Date().toISOString();
148
+ config.files_indexed = files.length;
149
+ saveGraphRAGConfig(config);
150
+ return {
151
+ files_processed: files.length,
152
+ entities_extracted: totalEntities,
153
+ relationships_extracted: totalRelationships,
154
+ graph_path: config.graph_path,
155
+ };
156
+ }
157
+ // ── Single batch processor ──────────────────────────────────────────────────
158
+ async function processBatch(llmModel, batch, batchNum, totalBatches, log) {
159
+ try {
160
+ // Use plain text mode — no structured output wrapper.
161
+ // Structured output (tool use) causes frequent "No output generated" errors.
162
+ const prompt = buildBatchPrompt(batch) + JSON_INSTRUCTION;
163
+ const result = await generateText({
164
+ model: llmModel,
165
+ prompt,
166
+ maxOutputTokens: 8192,
167
+ maxRetries: 0,
168
+ });
169
+ const raw = result.text ?? '';
170
+ if (!raw) {
171
+ log(` Batch ${batchNum}: empty response`);
172
+ return null;
173
+ }
174
+ // Extract JSON from the response text
175
+ const jsonMatch = raw.match(/\{[\s\S]*"entities"[\s\S]*/);
176
+ if (!jsonMatch) {
177
+ log(` Batch ${batchNum}: no JSON found (rawLen: ${raw.length})`);
178
+ return null;
179
+ }
180
+ // Repair truncated JSON — close unclosed arrays/objects
181
+ let jsonStr = jsonMatch[0];
182
+ try {
183
+ JSON.parse(jsonStr);
184
+ }
185
+ catch {
186
+ jsonStr = repairTruncatedJSON(jsonStr);
187
+ }
188
+ // Sanitize before Zod parsing — handle truncated objects
189
+ const rawObj = JSON.parse(jsonStr);
190
+ if (Array.isArray(rawObj.relationships)) {
191
+ rawObj.relationships = rawObj.relationships.filter((r) => r && typeof r.source === 'string' && typeof r.target === 'string');
192
+ }
193
+ const extraction = ExtractionResultSchema.parse(rawObj);
194
+ log(` Batch ${batchNum}: ${extraction.entities.length} entities, ${extraction.relationships.length} relationships`);
195
+ return extraction;
196
+ }
197
+ catch (err) {
198
+ const msg = err instanceof Error ? err.message : String(err);
199
+ log(` Batch ${batchNum}: error — ${msg}`);
200
+ return null;
201
+ }
202
+ }
203
+ // ── JSON repair ─────────────────────────────────────────────────────────────
204
+ /**
205
+ * Attempt to repair truncated JSON by removing the last incomplete element
206
+ * and closing unclosed arrays/objects.
207
+ */
208
+ function repairTruncatedJSON(str) {
209
+ // Remove trailing incomplete object — find the last complete }, then close arrays/root
210
+ let s = str;
211
+ // Strip any trailing partial string/value after the last complete element
212
+ // Find the last complete JSON object boundary ("},")
213
+ const lastCompleteObj = s.lastIndexOf('},');
214
+ const lastCompleteArr = s.lastIndexOf('],');
215
+ const cutPoint = Math.max(lastCompleteObj, lastCompleteArr);
216
+ if (cutPoint > 0) {
217
+ s = s.slice(0, cutPoint + 1); // keep the } or ]
218
+ }
219
+ // Count unclosed brackets
220
+ let openBraces = 0;
221
+ let openBrackets = 0;
222
+ let inString = false;
223
+ let escape = false;
224
+ for (const ch of s) {
225
+ if (escape) {
226
+ escape = false;
227
+ continue;
228
+ }
229
+ if (ch === '\\' && inString) {
230
+ escape = true;
231
+ continue;
232
+ }
233
+ if (ch === '"') {
234
+ inString = !inString;
235
+ continue;
236
+ }
237
+ if (inString)
238
+ continue;
239
+ if (ch === '{')
240
+ openBraces++;
241
+ if (ch === '}')
242
+ openBraces--;
243
+ if (ch === '[')
244
+ openBrackets++;
245
+ if (ch === ']')
246
+ openBrackets--;
247
+ }
248
+ // Close unclosed brackets
249
+ while (openBrackets > 0) {
250
+ s += ']';
251
+ openBrackets--;
252
+ }
253
+ while (openBraces > 0) {
254
+ s += '}';
255
+ openBraces--;
256
+ }
257
+ return s;
258
+ }
259
+ // ── File collection ─────────────────────────────────────────────────────────
260
+ export function collectMarkdownFiles(dirPath) {
261
+ const files = [];
262
+ walkDir(dirPath, dirPath, files);
263
+ return files;
264
+ }
265
+ function walkDir(basePath, currentPath, files) {
266
+ let entries;
267
+ try {
268
+ entries = readdirSync(currentPath);
269
+ }
270
+ catch {
271
+ return;
272
+ }
273
+ for (const entry of entries) {
274
+ // Skip hidden dirs and common noise
275
+ if (entry.startsWith('.') || entry === 'node_modules')
276
+ continue;
277
+ const fullPath = join(currentPath, entry);
278
+ let stat;
279
+ try {
280
+ stat = statSync(fullPath);
281
+ }
282
+ catch {
283
+ continue;
284
+ }
285
+ if (stat.isDirectory()) {
286
+ walkDir(basePath, fullPath, files);
287
+ }
288
+ else if (extname(entry) === '.md') {
289
+ try {
290
+ const content = readFileSync(fullPath, 'utf-8');
291
+ if (content.length > 0) {
292
+ files.push({
293
+ path: fullPath,
294
+ relativePath: relative(basePath, fullPath),
295
+ content,
296
+ });
297
+ }
298
+ }
299
+ catch {
300
+ // skip unreadable files
301
+ }
302
+ }
303
+ }
304
+ }
305
+ // ── Batching ────────────────────────────────────────────────────────────────
306
+ function batchFiles(files) {
307
+ const batches = [];
308
+ let currentBatch = [];
309
+ let currentChars = 0;
310
+ for (const file of files) {
311
+ const fileChars = file.content.length;
312
+ // Start a new batch if adding this file would exceed limits
313
+ if (currentBatch.length >= BATCH_SIZE || (currentChars + fileChars > MAX_CHARS_PER_BATCH && currentBatch.length > 0)) {
314
+ batches.push(currentBatch);
315
+ currentBatch = [];
316
+ currentChars = 0;
317
+ }
318
+ // Truncate very large files
319
+ const truncated = file.content.length > 8000
320
+ ? file.content.slice(0, 8000) + '\n\n[... truncated]'
321
+ : file.content;
322
+ currentBatch.push({ ...file, content: truncated });
323
+ currentChars += truncated.length;
324
+ }
325
+ if (currentBatch.length > 0) {
326
+ batches.push(currentBatch);
327
+ }
328
+ return batches;
329
+ }
330
+ // ── Prompt ──────────────────────────────────────────────────────────────────
331
+ function buildBatchPrompt(files) {
332
+ const docs = files.map(f => `### [${f.relativePath}]\n${f.content}`).join('\n\n---\n\n');
333
+ return `Extract all named entities and their relationships from these documents.
334
+
335
+ Focus on:
336
+ - People (team members, clients, contacts)
337
+ - Organizations/clients
338
+ - Projects and engagements
339
+ - Meetings and events
340
+ - Processes and workflows
341
+ - Deliverables and artifacts
342
+ - Tools and platforms
343
+
344
+ For each entity, identify:
345
+ - A canonical name (full name preferred, e.g. "Kenton Powell" not "Kenton")
346
+ - Its type (person, client, project, meeting, process, deliverable, tool, concept)
347
+ - A brief one-sentence description
348
+ - Which documents mention it
349
+
350
+ For relationships, capture how entities connect (e.g. "works on", "attended", "delivered to", "uses").
351
+
352
+ ## Documents
353
+
354
+ ${docs}
355
+
356
+ Extract all entities and relationships you can identify across these documents. Merge duplicate references to the same entity (e.g. "Kenton" and "Kenton Powell" should be one entity).`;
357
+ }
358
+ //# sourceMappingURL=graphrag-indexer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphrag-indexer.js","sourceRoot":"","sources":["../../../src/services/sync/graphrag-indexer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC/F,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,mBAAmB,GAAG,MAAM,CAAC,CAAC,cAAc;AAClD,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B,MAAM,sBAAsB,GAAG,2BAA2B,CAAC;AAC3D,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAErC,+EAA+E;AAE/E,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CA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AAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CACzB,QAAQ,CAAC,CAAC,YAAY,MAAM,CAAC,CAAC,OAAO,EAAE,CACxC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAEtB,OAAO;;;;;;;;;;;;;;;;;;;;;EAqBP,IAAI;;wLAEkL,CAAC;AACzL,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * LLM utilities for the sync pipeline — powered by the Vercel AI SDK.
3
+ *
4
+ * - llmExtract: Structured extraction from unstructured content
5
+ * - llmEnrich: Enrichment with cross-source context
6
+ * - llmGraphMatch: Entity deduplication comparison
7
+ *
8
+ * All three functions use generateText + Output.object() for Zod-validated
9
+ * structured output. Provider is configurable via user config:
10
+ * enrichment_model_id → model_id → 'claude-sonnet-4-5-20250929'
11
+ * enrichment_model_provider → model_provider → 'anthropic'
12
+ */
13
+ /**
14
+ * Extract structured frontmatter from content using LLM.
15
+ */
16
+ export declare function llmExtract(content: string, entityType: string, schema: any, graphragContext?: string): Promise<Record<string, any>>;
17
+ /**
18
+ * Enrich an entity with cross-source context using LLM.
19
+ * Returns updated frontmatter and generated content.
20
+ */
21
+ export declare function llmEnrich(entityData: Record<string, any>, contextBundle: string, entityType: string, schema: any): Promise<{
22
+ frontmatter: Record<string, any>;
23
+ content: string;
24
+ }>;
25
+ /**
26
+ * Ask LLM whether two entities (staged vs existing) are the same real-world entity.
27
+ */
28
+ export declare function llmGraphMatch(stagedFrontmatter: Record<string, any>, existingFrontmatter: Record<string, any>, entityType: string): Promise<{
29
+ is_same: boolean;
30
+ confidence: number;
31
+ reasoning: string;
32
+ }>;