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,92 @@
1
+ /**
2
+ * Zod schemas for AI SDK Output.object() structured outputs.
3
+ *
4
+ * Because constrained decoding requires `additionalProperties: false`,
5
+ * we use a `custom_fields` catch-all for dynamic frontmatter fields.
6
+ * After extraction, flattenCustomFields() merges them back into the root.
7
+ */
8
+ import { z } from 'zod';
9
+ export declare const ExtractOutputSchema: z.ZodObject<{
10
+ frontmatter: z.ZodObject<{
11
+ entity_type: z.ZodOptional<z.ZodString>;
12
+ entity_id: z.ZodOptional<z.ZodString>;
13
+ name: z.ZodOptional<z.ZodString>;
14
+ custom_fields: z.ZodOptional<z.ZodString>;
15
+ }, "strip", z.ZodTypeAny, {
16
+ name?: string | undefined;
17
+ entity_type?: string | undefined;
18
+ entity_id?: string | undefined;
19
+ custom_fields?: string | undefined;
20
+ }, {
21
+ name?: string | undefined;
22
+ entity_type?: string | undefined;
23
+ entity_id?: string | undefined;
24
+ custom_fields?: string | undefined;
25
+ }>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ frontmatter: {
28
+ name?: string | undefined;
29
+ entity_type?: string | undefined;
30
+ entity_id?: string | undefined;
31
+ custom_fields?: string | undefined;
32
+ };
33
+ }, {
34
+ frontmatter: {
35
+ name?: string | undefined;
36
+ entity_type?: string | undefined;
37
+ entity_id?: string | undefined;
38
+ custom_fields?: string | undefined;
39
+ };
40
+ }>;
41
+ export declare const EnrichOutputSchema: z.ZodObject<{
42
+ frontmatter: z.ZodObject<{
43
+ entity_type: z.ZodOptional<z.ZodString>;
44
+ entity_id: z.ZodOptional<z.ZodString>;
45
+ name: z.ZodOptional<z.ZodString>;
46
+ custom_fields: z.ZodOptional<z.ZodString>;
47
+ }, "strip", z.ZodTypeAny, {
48
+ name?: string | undefined;
49
+ entity_type?: string | undefined;
50
+ entity_id?: string | undefined;
51
+ custom_fields?: string | undefined;
52
+ }, {
53
+ name?: string | undefined;
54
+ entity_type?: string | undefined;
55
+ entity_id?: string | undefined;
56
+ custom_fields?: string | undefined;
57
+ }>;
58
+ content: z.ZodString;
59
+ }, "strip", z.ZodTypeAny, {
60
+ content: string;
61
+ frontmatter: {
62
+ name?: string | undefined;
63
+ entity_type?: string | undefined;
64
+ entity_id?: string | undefined;
65
+ custom_fields?: string | undefined;
66
+ };
67
+ }, {
68
+ content: string;
69
+ frontmatter: {
70
+ name?: string | undefined;
71
+ entity_type?: string | undefined;
72
+ entity_id?: string | undefined;
73
+ custom_fields?: string | undefined;
74
+ };
75
+ }>;
76
+ export declare const GraphMatchOutputSchema: z.ZodObject<{
77
+ is_same: z.ZodBoolean;
78
+ confidence: z.ZodNumber;
79
+ reasoning: z.ZodString;
80
+ }, "strip", z.ZodTypeAny, {
81
+ confidence: number;
82
+ is_same: boolean;
83
+ reasoning: string;
84
+ }, {
85
+ confidence: number;
86
+ is_same: boolean;
87
+ reasoning: string;
88
+ }>;
89
+ /**
90
+ * Merge custom_fields back into the root object and drop the key.
91
+ */
92
+ export declare function flattenCustomFields(obj: Record<string, any>): Record<string, any>;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Zod schemas for AI SDK Output.object() structured outputs.
3
+ *
4
+ * Because constrained decoding requires `additionalProperties: false`,
5
+ * we use a `custom_fields` catch-all for dynamic frontmatter fields.
6
+ * After extraction, flattenCustomFields() merges them back into the root.
7
+ */
8
+ import { z } from 'zod';
9
+ const FrontmatterSchema = z.object({
10
+ entity_type: z.string().optional(),
11
+ entity_id: z.string().optional(),
12
+ name: z.string().optional(),
13
+ custom_fields: z.string().optional()
14
+ .describe('JSON object string of additional fields not listed above, e.g. {"status":"active","tags":["design"]}'),
15
+ });
16
+ export const ExtractOutputSchema = z.object({
17
+ frontmatter: FrontmatterSchema,
18
+ });
19
+ export const EnrichOutputSchema = z.object({
20
+ frontmatter: FrontmatterSchema,
21
+ content: z.string().describe('Markdown body'),
22
+ });
23
+ export const GraphMatchOutputSchema = z.object({
24
+ is_same: z.boolean(),
25
+ confidence: z.number(),
26
+ reasoning: z.string(),
27
+ });
28
+ /**
29
+ * Merge custom_fields back into the root object and drop the key.
30
+ */
31
+ export function flattenCustomFields(obj) {
32
+ const { custom_fields, ...rest } = obj;
33
+ if (!custom_fields)
34
+ return rest;
35
+ try {
36
+ const parsed = typeof custom_fields === 'string' ? JSON.parse(custom_fields) : custom_fields;
37
+ return typeof parsed === 'object' && parsed !== null ? { ...rest, ...parsed } : rest;
38
+ }
39
+ catch {
40
+ return rest;
41
+ }
42
+ }
43
+ //# sourceMappingURL=output-schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-schemas.js","sourceRoot":"","sources":["../../../src/services/sync/output-schemas.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;SACjC,QAAQ,CAAC,sGAAsG,CAAC;CACpH,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,WAAW,EAAE,iBAAiB;CAC/B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,WAAW,EAAE,iBAAiB;IAC9B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC;CAC9C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;IACpB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAwB;IAC1D,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,GAAG,GAAG,CAAC;IACvC,IAAI,CAAC,aAAa;QAAE,OAAO,IAAI,CAAC;IAChC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;QAC7F,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACvF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Prompt templates for LLM-based extraction and enrichment.
3
+ */
4
+ /**
5
+ * Build the extraction prompt for unstructured content.
6
+ */
7
+ export declare function buildExtractionPrompt(content: string, entityType: string, schemaDescription: string, graphragContext?: string): string;
8
+ /**
9
+ * Build the enrichment prompt for adding context to an existing entity.
10
+ */
11
+ export declare function buildEnrichmentPrompt(entityType: string, currentFrontmatter: Record<string, any>, contextBundle: string, schemaDescription: string): string;
12
+ /**
13
+ * Build the graph match prompt to compare a staged entity against an existing graph entity.
14
+ */
15
+ export declare function buildGraphMatchPrompt(stagedFrontmatter: Record<string, any>, existingFrontmatter: Record<string, any>, entityType: string): string;
16
+ /**
17
+ * Describe a Zod schema's fields for use in prompts.
18
+ */
19
+ export declare function describeSchema(schema: any): string;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Prompt templates for LLM-based extraction and enrichment.
3
+ */
4
+ /**
5
+ * Build the extraction prompt for unstructured content.
6
+ */
7
+ export function buildExtractionPrompt(content, entityType, schemaDescription, graphragContext) {
8
+ const contextSection = graphragContext
9
+ ? `\n## Cross-Document Context\nThe following entities and relationships are known from other documents in this knowledge base:\n${graphragContext}\n\nUse this context to resolve ambiguous names, fill in missing details, and create accurate wikilinks.\n`
10
+ : '';
11
+ return `You are extracting structured data from a document to create a ${entityType} entity.
12
+
13
+ ## Entity Schema
14
+ ${schemaDescription}
15
+ ${contextSection}
16
+ ## Source Document
17
+ ${content}
18
+
19
+ ## Instructions
20
+ Extract the relevant fields from the document above to populate the ${entityType} entity.
21
+
22
+ Important:
23
+ - Use kebab-case for entity_id values
24
+ - Use ISO 8601 format for dates
25
+ - For wikilink fields, use the format "[[entity-id]]"
26
+ - Only include fields you can confidently extract
27
+ - Leave optional fields out rather than guessing`;
28
+ }
29
+ /**
30
+ * Build the enrichment prompt for adding context to an existing entity.
31
+ */
32
+ export function buildEnrichmentPrompt(entityType, currentFrontmatter, contextBundle, schemaDescription) {
33
+ return `You are enriching a ${entityType} entity with additional context from related entities.
34
+
35
+ ## Current Entity Data
36
+ ${JSON.stringify(currentFrontmatter, null, 2)}
37
+
38
+ ## Entity Schema
39
+ ${schemaDescription}
40
+
41
+ ## Cross-Reference Context
42
+ ${contextBundle}
43
+
44
+ ## Instructions
45
+ Based on the context above, enrich the entity with additional information.
46
+
47
+ Rules:
48
+ - Preserve all existing frontmatter values unless you have clearly better data
49
+ - Fill in empty optional fields where the context provides clear information
50
+ - Use wikilink format "[[entity-id]]" for entity references
51
+ - Write concise, factual content — no speculation
52
+ - Do not fabricate information not present in the context`;
53
+ }
54
+ /**
55
+ * Build the graph match prompt to compare a staged entity against an existing graph entity.
56
+ */
57
+ export function buildGraphMatchPrompt(stagedFrontmatter, existingFrontmatter, entityType) {
58
+ return `You are comparing two ${entityType} entities to determine if they represent the same real-world entity.
59
+
60
+ Names and IDs may differ across systems (e.g. an Asana project called "Existence Dataviz Redesign" may be the same as an entity with ID "existence").
61
+
62
+ ## Staged Entity (from external source)
63
+ ${JSON.stringify(stagedFrontmatter, null, 2)}
64
+
65
+ ## Existing Entity (already in graph)
66
+ ${JSON.stringify(existingFrontmatter, null, 2)}
67
+
68
+ ## Instructions
69
+ Determine whether these two entities represent the same real-world ${entityType}.
70
+
71
+ Consider:
72
+ - Name similarity (one name may be a longer/shorter version of the other)
73
+ - Shared references (same client, team members, attendees)
74
+ - Overlapping dates or time periods
75
+ - Matching identifiers (email, URL, external IDs)
76
+
77
+ Be conservative — only match if you're reasonably confident they are the same entity. Different entities at the same organization or with similar names should NOT be matched.`;
78
+ }
79
+ /**
80
+ * Describe a Zod schema's fields for use in prompts.
81
+ */
82
+ export function describeSchema(schema) {
83
+ try {
84
+ const shape = schema._def?.shape?.() ?? schema.shape ?? {};
85
+ const lines = [];
86
+ for (const [key, value] of Object.entries(shape)) {
87
+ const def = value?._def;
88
+ const desc = def?.description ?? '';
89
+ const typeName = getZodTypeName(value);
90
+ const optional = isOptional(value) ? '(optional)' : '(required)';
91
+ lines.push(`- ${key}: ${typeName} ${optional}${desc ? ` — ${desc}` : ''}`);
92
+ }
93
+ return lines.join('\n');
94
+ }
95
+ catch {
96
+ return `Entity type fields (see documentation)`;
97
+ }
98
+ }
99
+ function getZodTypeName(zodType) {
100
+ const def = zodType?._def;
101
+ if (!def)
102
+ return 'unknown';
103
+ const typeName = def.typeName;
104
+ if (typeName === 'ZodString')
105
+ return 'string';
106
+ if (typeName === 'ZodNumber')
107
+ return 'number';
108
+ if (typeName === 'ZodBoolean')
109
+ return 'boolean';
110
+ if (typeName === 'ZodArray')
111
+ return 'string[]';
112
+ if (typeName === 'ZodEnum')
113
+ return `enum(${def.values?.join('|') ?? '...'})`;
114
+ if (typeName === 'ZodLiteral')
115
+ return `"${def.value}"`;
116
+ if (typeName === 'ZodOptional')
117
+ return getZodTypeName(def.innerType);
118
+ if (typeName === 'ZodDefault')
119
+ return getZodTypeName(def.innerType);
120
+ return 'string';
121
+ }
122
+ function isOptional(zodType) {
123
+ const def = zodType?._def;
124
+ if (!def)
125
+ return false;
126
+ return def.typeName === 'ZodOptional' || def.typeName === 'ZodDefault';
127
+ }
128
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/services/sync/prompts.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAe,EACf,UAAkB,EAClB,iBAAyB,EACzB,eAAwB;IAExB,MAAM,cAAc,GAAG,eAAe;QACpC,CAAC,CAAC,iIAAiI,eAAe,4GAA4G;QAC9P,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO,kEAAkE,UAAU;;;EAGnF,iBAAiB;EACjB,cAAc;;EAEd,OAAO;;;sEAG6D,UAAU;;;;;;;iDAO/B,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAAkB,EAClB,kBAAuC,EACvC,aAAqB,EACrB,iBAAyB;IAEzB,OAAO,uBAAuB,UAAU;;;EAGxC,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC;;;EAG3C,iBAAiB;;;EAGjB,aAAa;;;;;;;;;;0DAU2C,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,iBAAsC,EACtC,mBAAwC,EACxC,UAAkB;IAElB,OAAO,yBAAyB,UAAU;;;;;EAK1C,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;;;EAG1C,IAAI,CAAC,SAAS,CAAC,mBAAmB,EAAE,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E,OAAO,QAAQ,CAAC;IAC9C,IAAI,QAAQ,KAAK,YAAY;QAAE,OAAO,SAAS,CAAC;IAChD,IAAI,QAAQ,KAAK,UAAU;QAAE,OAAO,UAAU,CAAC;IAC/C,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,QAAQ,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC;IAC7E,IAAI,QAAQ,KAAK,YAAY;QAAE,OAAO,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC;IACvD,IAAI,QAAQ,KAAK,aAAa;QAAE,OAAO,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACrE,IAAI,QAAQ,KAAK,YAAY;QAAE,OAAO,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACpE,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,UAAU,CAAC,OAAY;IAC9B,MAAM,GAAG,GAAG,OAAO,EAAE,IAAI,CAAC;IAC1B,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IACvB,OAAO,GAAG,CAAC,QAAQ,KAAK,aAAa,IAAI,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;AACzE,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Reconciler
3
+ *
4
+ * Multi-tier matching to deduplicate extracted records from multiple sources.
5
+ * Merges records using source priority, then determines create vs update.
6
+ */
7
+ import { SyncStateManager } from './sync-state.js';
8
+ import type { SchemaRegistry } from '../../core/schema-registry.js';
9
+ import type { ExtractedRecord, ReconciliationMatch, SourceConfig } from './types.js';
10
+ export declare class Reconciler {
11
+ private workspacePath;
12
+ private schemaRegistry;
13
+ private syncState;
14
+ private sourceConfigs;
15
+ constructor(workspacePath: string, schemaRegistry: SchemaRegistry, syncState: SyncStateManager, sourceConfigs?: SourceConfig[]);
16
+ /**
17
+ * Takes ALL extracted records from ALL sources, returns deduplicated matches.
18
+ * Filters out tombstoned entities before matching.
19
+ */
20
+ reconcile(records: ExtractedRecord[], onProgress?: (msg: string) => void): ReconciliationMatch[];
21
+ /**
22
+ * Composite key: `entity_type::entity_id`.
23
+ * Ensures entities of different types with the same slug don't collide.
24
+ */
25
+ private compositeKey;
26
+ /** Extract entity_id from a composite key. */
27
+ private parseEntityId;
28
+ /**
29
+ * Find the match key for a record by running through matching tiers.
30
+ * Returns a composite key (`entity_type::entity_id`).
31
+ */
32
+ private findMatchKey;
33
+ /**
34
+ * Determine match type from a group of matched records.
35
+ */
36
+ private determineMatchType;
37
+ /**
38
+ * Merge multiple records into one. Uses source priority.
39
+ */
40
+ private mergeRecords;
41
+ /**
42
+ * Check against existing graph entities for create vs update.
43
+ */
44
+ private checkExisting;
45
+ private loadWorkspaceConfig;
46
+ private getSourcePriority;
47
+ private getFieldPrioritySource;
48
+ }
@@ -0,0 +1,295 @@
1
+ /**
2
+ * Reconciler
3
+ *
4
+ * Multi-tier matching to deduplicate extracted records from multiple sources.
5
+ * Merges records using source priority, then determines create vs update.
6
+ */
7
+ import { existsSync } from 'fs';
8
+ import { join } from 'path';
9
+ import { loadWorkspaceConfig } from '../../utils/workspace-config.js';
10
+ export class Reconciler {
11
+ workspacePath;
12
+ schemaRegistry;
13
+ syncState;
14
+ sourceConfigs;
15
+ constructor(workspacePath, schemaRegistry, syncState, sourceConfigs = []) {
16
+ this.workspacePath = workspacePath;
17
+ this.schemaRegistry = schemaRegistry;
18
+ this.syncState = syncState;
19
+ this.sourceConfigs = sourceConfigs;
20
+ }
21
+ /**
22
+ * Takes ALL extracted records from ALL sources, returns deduplicated matches.
23
+ * Filters out tombstoned entities before matching.
24
+ */
25
+ reconcile(records, onProgress) {
26
+ // Filter tombstoned
27
+ const filtered = records.filter(r => !this.syncState.isTombstoned(r.entity_id));
28
+ // Group by entity_id
29
+ const groups = new Map();
30
+ for (let i = 0; i < filtered.length; i++) {
31
+ const record = filtered[i];
32
+ if (onProgress && i > 0 && i % 500 === 0) {
33
+ onProgress(` Reconciling ${i}/${filtered.length}...`);
34
+ }
35
+ const key = this.findMatchKey(record, groups);
36
+ if (!groups.has(key)) {
37
+ groups.set(key, []);
38
+ }
39
+ groups.get(key).push(record);
40
+ }
41
+ // Build reconciliation matches
42
+ const matches = [];
43
+ for (const [key, group] of groups) {
44
+ const entityId = this.parseEntityId(key);
45
+ const matchType = group.length === 1 ? 'single' : this.determineMatchType(group);
46
+ const merged = this.mergeRecords(group);
47
+ const action = this.checkExisting(group[0].entity_type, entityId, group[0].target_repo);
48
+ matches.push({
49
+ entity_id: entityId,
50
+ entity_type: group[0].entity_type,
51
+ target_repo: group[0].target_repo,
52
+ records: group,
53
+ match_type: matchType,
54
+ action,
55
+ merged_frontmatter: merged.frontmatter,
56
+ merged_content: merged.content,
57
+ confidence: merged.confidence,
58
+ notes: merged.notes,
59
+ field_sources: merged.fieldSources,
60
+ ...(group[0].co_locate ? { co_locate: group[0].co_locate } : {}),
61
+ ...(group[0].write_mode ? { write_mode: group[0].write_mode } : {}),
62
+ });
63
+ }
64
+ return matches;
65
+ }
66
+ /**
67
+ * Composite key: `entity_type::entity_id`.
68
+ * Ensures entities of different types with the same slug don't collide.
69
+ */
70
+ compositeKey(entityType, entityId) {
71
+ return `${entityType}::${entityId}`;
72
+ }
73
+ /** Extract entity_id from a composite key. */
74
+ parseEntityId(key) {
75
+ const idx = key.indexOf('::');
76
+ return idx >= 0 ? key.slice(idx + 2) : key;
77
+ }
78
+ /**
79
+ * Find the match key for a record by running through matching tiers.
80
+ * Returns a composite key (`entity_type::entity_id`).
81
+ */
82
+ findMatchKey(record, existing) {
83
+ const selfKey = this.compositeKey(record.entity_type, record.entity_id);
84
+ // Tier 1: Exact entity_type + entity_id match
85
+ if (existing.has(selfKey)) {
86
+ return selfKey;
87
+ }
88
+ // Tier 2: Source ref match via sync state provenance
89
+ for (const [key, group] of existing) {
90
+ for (const other of group) {
91
+ if (other.entity_type !== record.entity_type)
92
+ continue;
93
+ const ref = this.syncState.findBySourceRef(record.source_name, record.source_ref);
94
+ if (ref && ref === this.parseEntityId(key))
95
+ return key;
96
+ }
97
+ }
98
+ // Tier 3: Email match (person entities)
99
+ if (record.entity_type === 'person' && record.frontmatter.email) {
100
+ for (const [key, group] of existing) {
101
+ for (const other of group) {
102
+ if (other.entity_type === 'person' && other.frontmatter.email === record.frontmatter.email) {
103
+ return key;
104
+ }
105
+ }
106
+ }
107
+ }
108
+ // Tier 4: Name variant match
109
+ for (const [key, group] of existing) {
110
+ for (const other of group) {
111
+ if (other.entity_type !== record.entity_type)
112
+ continue;
113
+ if (isNameVariant(record.entity_id, this.parseEntityId(key))) {
114
+ return key;
115
+ }
116
+ }
117
+ }
118
+ // Tier 5: Fuzzy name match (Levenshtein)
119
+ // Only match when distance is small relative to ID length (< 15%)
120
+ // to avoid false merges on short numeric IDs like sch-10/sch-11
121
+ for (const [key, group] of existing) {
122
+ for (const other of group) {
123
+ if (other.entity_type !== record.entity_type)
124
+ continue;
125
+ const otherId = this.parseEntityId(key);
126
+ const dist = levenshtein(record.entity_id, otherId);
127
+ const maxLen = Math.max(record.entity_id.length, otherId.length);
128
+ if (dist <= 2 && maxLen >= 14 && dist / maxLen < 0.15) {
129
+ return key;
130
+ }
131
+ }
132
+ }
133
+ // No match — new group
134
+ return selfKey;
135
+ }
136
+ /**
137
+ * Determine match type from a group of matched records.
138
+ */
139
+ determineMatchType(group) {
140
+ if (group.length <= 1)
141
+ return 'single';
142
+ const ids = new Set(group.map(r => r.entity_id));
143
+ if (ids.size === 1)
144
+ return 'exact-id';
145
+ const emails = group.filter(r => r.frontmatter.email).map(r => r.frontmatter.email);
146
+ if (emails.length > 1 && new Set(emails).size === 1)
147
+ return 'email';
148
+ // Check name variants
149
+ const idList = [...ids];
150
+ for (let i = 0; i < idList.length; i++) {
151
+ for (let j = i + 1; j < idList.length; j++) {
152
+ if (isNameVariant(idList[i], idList[j]))
153
+ return 'name-variant';
154
+ }
155
+ }
156
+ return 'fuzzy-name';
157
+ }
158
+ /**
159
+ * Merge multiple records into one. Uses source priority.
160
+ */
161
+ mergeRecords(records) {
162
+ if (records.length === 1) {
163
+ const fieldSources = {};
164
+ for (const key of Object.keys(records[0].frontmatter)) {
165
+ if (records[0].frontmatter[key] !== undefined && records[0].frontmatter[key] !== null) {
166
+ fieldSources[key] = records[0].source_name;
167
+ }
168
+ }
169
+ return {
170
+ frontmatter: records[0].frontmatter,
171
+ content: records[0].content,
172
+ confidence: records[0].confidence,
173
+ notes: `Single source: ${records[0].source_name}`,
174
+ fieldSources,
175
+ };
176
+ }
177
+ // Sort by confidence (highest first), then by extraction mode priority
178
+ // Structured API sources beat derived data
179
+ const sorted = [...records].sort((a, b) => {
180
+ // Check source-level priority
181
+ const aPriority = this.getSourcePriority(a.source_name);
182
+ const bPriority = this.getSourcePriority(b.source_name);
183
+ if (aPriority !== bPriority)
184
+ return bPriority - aPriority;
185
+ return b.confidence - a.confidence;
186
+ });
187
+ // Merge: first-seen value wins (highest priority record first)
188
+ const frontmatter = {};
189
+ const fieldSources = {};
190
+ const notes = [];
191
+ let bestContent = '';
192
+ let totalConfidence = 0;
193
+ for (const record of sorted) {
194
+ for (const [key, value] of Object.entries(record.frontmatter)) {
195
+ if (value === undefined || value === null)
196
+ continue;
197
+ // Apply field-level priority overrides
198
+ const fieldSource = this.getFieldPrioritySource(key);
199
+ if (fieldSource && record.source_name !== fieldSource && frontmatter[key] !== undefined) {
200
+ continue;
201
+ }
202
+ if (frontmatter[key] === undefined) {
203
+ frontmatter[key] = value;
204
+ fieldSources[key] = record.source_name;
205
+ }
206
+ else if (frontmatter[key] !== value && typeof value === 'string') {
207
+ // Track alternatives in notes
208
+ notes.push(`${key}: alt "${value}" from ${record.source_name}`);
209
+ }
210
+ }
211
+ if (record.content && !bestContent) {
212
+ bestContent = record.content;
213
+ }
214
+ totalConfidence += record.confidence;
215
+ }
216
+ return {
217
+ frontmatter,
218
+ content: bestContent,
219
+ confidence: totalConfidence / sorted.length,
220
+ notes: notes.length > 0
221
+ ? `Merged from ${sorted.length} sources: ${sorted.map(r => r.source_name).join(', ')}. ${notes.join('; ')}`
222
+ : `Merged from ${sorted.length} sources: ${sorted.map(r => r.source_name).join(', ')}`,
223
+ fieldSources,
224
+ };
225
+ }
226
+ /**
227
+ * Check against existing graph entities for create vs update.
228
+ */
229
+ checkExisting(entityType, entityId, targetRepo) {
230
+ // Look for existing entity file in the target repo
231
+ const config = this.loadWorkspaceConfig();
232
+ if (!config)
233
+ return 'create';
234
+ const repo = config.repos?.find((r) => r.name === targetRepo);
235
+ const repoPath = repo ? join(this.workspacePath, repo.path) : join(this.workspacePath, targetRepo);
236
+ const entityPath = join(repoPath, entityId, 'main.md');
237
+ return existsSync(entityPath) ? 'update' : 'create';
238
+ }
239
+ loadWorkspaceConfig() {
240
+ return loadWorkspaceConfig(this.workspacePath);
241
+ }
242
+ getSourcePriority(sourceName) {
243
+ // Structured API sources get higher priority
244
+ const config = this.sourceConfigs.find(c => c.name === sourceName);
245
+ if (!config)
246
+ return 0;
247
+ const hasStructured = config.entity_mappings.some(m => m.extraction_mode === 'structured');
248
+ return hasStructured ? 2 : 1;
249
+ }
250
+ getFieldPrioritySource(field) {
251
+ for (const config of this.sourceConfigs) {
252
+ if (config.field_priority && config.field_priority[field]) {
253
+ return config.field_priority[field];
254
+ }
255
+ }
256
+ return null;
257
+ }
258
+ }
259
+ /**
260
+ * Check if two entity IDs are name variants.
261
+ * e.g. "diane-terrell" ↔ "diane-s-terrell"
262
+ */
263
+ function isNameVariant(a, b) {
264
+ // Strip middle initials/names
265
+ const normalize = (s) => s.replace(/-[a-z]-/g, '-').replace(/-+/g, '-');
266
+ if (normalize(a) === normalize(b))
267
+ return true;
268
+ // Check if one is prefix of the other
269
+ const shorter = a.length < b.length ? a : b;
270
+ const longer = a.length < b.length ? b : a;
271
+ if (longer.startsWith(shorter + '-') || longer.endsWith('-' + shorter))
272
+ return true;
273
+ return false;
274
+ }
275
+ /**
276
+ * Simple Levenshtein distance.
277
+ */
278
+ function levenshtein(a, b) {
279
+ const m = a.length;
280
+ const n = b.length;
281
+ const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
282
+ for (let i = 0; i <= m; i++)
283
+ dp[i][0] = i;
284
+ for (let j = 0; j <= n; j++)
285
+ dp[0][j] = j;
286
+ for (let i = 1; i <= m; i++) {
287
+ for (let j = 1; j <= n; j++) {
288
+ dp[i][j] = a[i - 1] === b[j - 1]
289
+ ? dp[i - 1][j - 1]
290
+ : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
291
+ }
292
+ }
293
+ return dp[m][n];
294
+ }
295
+ //# sourceMappingURL=reconciler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconciler.js","sourceRoot":"","sources":["../../../src/services/sync/reconciler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAItE,MAAM,OAAO,UAAU;IACb,aAAa,CAAS;IACtB,cAAc,CAAiB;IAC/B,SAAS,CAAmB;IAC5B,aAAa,CAAiB;IAEtC,YACE,aAAqB,EACrB,cAA8B,EAC9B,SAA2B,EAC3B,gBAAgC,EAAE;QAElC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,OAA0B,EAAE,UAAkC;QACtE,oBAAoB;QACpB,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAA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