@monoes/monograph 1.3.0 → 1.4.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 (301) hide show
  1. package/.monomind/registry.json +6 -0
  2. package/__tests__/staleness/git-staleness.test.ts +3 -3
  3. package/dist/src/analysis/benchmark.js.map +1 -1
  4. package/dist/src/analysis/changed-files.d.ts.map +1 -1
  5. package/dist/src/analysis/changed-files.js +11 -2
  6. package/dist/src/analysis/changed-files.js.map +1 -1
  7. package/dist/src/analysis/changed-workspaces.d.ts.map +1 -1
  8. package/dist/src/analysis/changed-workspaces.js +11 -3
  9. package/dist/src/analysis/changed-workspaces.js.map +1 -1
  10. package/dist/src/analysis/churn.d.ts +1 -1
  11. package/dist/src/analysis/churn.d.ts.map +1 -1
  12. package/dist/src/analysis/churn.js +56 -10
  13. package/dist/src/analysis/churn.js.map +1 -1
  14. package/dist/src/analysis/cluster-quality.d.ts +4 -4
  15. package/dist/src/analysis/cluster-quality.d.ts.map +1 -1
  16. package/dist/src/analysis/cluster-quality.js +24 -27
  17. package/dist/src/analysis/cluster-quality.js.map +1 -1
  18. package/dist/src/analysis/combined.d.ts.map +1 -1
  19. package/dist/src/analysis/combined.js +2 -0
  20. package/dist/src/analysis/combined.js.map +1 -1
  21. package/dist/src/analysis/feature-flags.d.ts.map +1 -1
  22. package/dist/src/analysis/feature-flags.js +11 -5
  23. package/dist/src/analysis/feature-flags.js.map +1 -1
  24. package/dist/src/analysis/progress.d.ts.map +1 -1
  25. package/dist/src/analysis/project-state.d.ts.map +1 -1
  26. package/dist/src/analysis/shape-extractor.js.map +1 -1
  27. package/dist/src/analysis/suppression-context.d.ts.map +1 -1
  28. package/dist/src/analysis/surprise-scorer.js.map +1 -1
  29. package/dist/src/analysis/targets.d.ts.map +1 -1
  30. package/dist/src/analysis/targets.js +4 -5
  31. package/dist/src/analysis/targets.js.map +1 -1
  32. package/dist/src/analysis/worker-pool.d.ts.map +1 -1
  33. package/dist/src/analysis/worker-pool.js.map +1 -1
  34. package/dist/src/analyze/unused-deps.js.map +1 -1
  35. package/dist/src/analyze/unused-exports.js.map +1 -1
  36. package/dist/src/analyze/unused-files.js.map +1 -1
  37. package/dist/src/cache/augment-cache.js.map +1 -1
  38. package/dist/src/cache/extraction-cache.d.ts +21 -0
  39. package/dist/src/cache/extraction-cache.d.ts.map +1 -1
  40. package/dist/src/cache/extraction-cache.js +62 -6
  41. package/dist/src/cache/extraction-cache.js.map +1 -1
  42. package/dist/src/check/index.js.map +1 -1
  43. package/dist/src/cli/check-update.js.map +1 -1
  44. package/dist/src/cli/doctor.d.ts.map +1 -1
  45. package/dist/src/cli/doctor.js +6 -10
  46. package/dist/src/cli/doctor.js.map +1 -1
  47. package/dist/src/config/boundary-config.js.map +1 -1
  48. package/dist/src/config/config-parsing.d.ts +1 -1
  49. package/dist/src/config/config-parsing.d.ts.map +1 -1
  50. package/dist/src/config/migration-types.d.ts +2 -2
  51. package/dist/src/config/migration-types.d.ts.map +1 -1
  52. package/dist/src/config/migration-types.js.map +1 -1
  53. package/dist/src/config/used-class-members.js.map +1 -1
  54. package/dist/src/config/workspace.js.map +1 -1
  55. package/dist/src/coverage/upload-source-maps.js.map +1 -1
  56. package/dist/src/duplicates/detect/filtering.d.ts.map +1 -1
  57. package/dist/src/duplicates/shingle-filter.js.map +1 -1
  58. package/dist/src/error/fallow-error.d.ts.map +1 -1
  59. package/dist/src/error/fallow-error.js.map +1 -1
  60. package/dist/src/error.d.ts.map +1 -1
  61. package/dist/src/error.js.map +1 -1
  62. package/dist/src/export/analysis-json.js +1 -1
  63. package/dist/src/export/analysis-json.js.map +1 -1
  64. package/dist/src/export/badge.js.map +1 -1
  65. package/dist/src/export/dot.js.map +1 -1
  66. package/dist/src/export/sarif.d.ts.map +1 -1
  67. package/dist/src/export/sarif.js +13 -2
  68. package/dist/src/export/sarif.js.map +1 -1
  69. package/dist/src/fix/orchestrator.js.map +1 -1
  70. package/dist/src/graph/baseline.d.ts.map +1 -1
  71. package/dist/src/graph/baseline.js +29 -20
  72. package/dist/src/graph/baseline.js.map +1 -1
  73. package/dist/src/graph/cycle-detection.js.map +1 -1
  74. package/dist/src/graph/dead-code.d.ts +7 -2
  75. package/dist/src/graph/dead-code.d.ts.map +1 -1
  76. package/dist/src/graph/dead-code.js +19 -16
  77. package/dist/src/graph/dead-code.js.map +1 -1
  78. package/dist/src/graph/dfs.js.map +1 -1
  79. package/dist/src/graph/edge-filter.js.map +1 -1
  80. package/dist/src/graph/health-score.d.ts.map +1 -1
  81. package/dist/src/graph/health-score.js +11 -14
  82. package/dist/src/graph/health-score.js.map +1 -1
  83. package/dist/src/graph/hotspots.d.ts.map +1 -1
  84. package/dist/src/graph/hotspots.js +8 -4
  85. package/dist/src/graph/hotspots.js.map +1 -1
  86. package/dist/src/graph/import-chain.js.map +1 -1
  87. package/dist/src/graph/merge.js.map +1 -1
  88. package/dist/src/graph/node-search.js.map +1 -1
  89. package/dist/src/graph/node-types.d.ts.map +1 -1
  90. package/dist/src/graph/pagerank.d.ts.map +1 -1
  91. package/dist/src/graph/pagerank.js +10 -1
  92. package/dist/src/graph/pagerank.js.map +1 -1
  93. package/dist/src/graph/regex-search.js.map +1 -1
  94. package/dist/src/graph/regression.d.ts.map +1 -1
  95. package/dist/src/graph/resolve/discover-types.js.map +1 -1
  96. package/dist/src/graph/resolve/types.d.ts +3 -3
  97. package/dist/src/graph/resolve/types.d.ts.map +1 -1
  98. package/dist/src/graph/statistics.d.ts +3 -2
  99. package/dist/src/graph/statistics.d.ts.map +1 -1
  100. package/dist/src/graph/statistics.js +18 -7
  101. package/dist/src/graph/statistics.js.map +1 -1
  102. package/dist/src/graph/stats.d.ts.map +1 -1
  103. package/dist/src/graph/stats.js +2 -1
  104. package/dist/src/graph/stats.js.map +1 -1
  105. package/dist/src/groups/group-search.d.ts.map +1 -1
  106. package/dist/src/groups/group-search.js +9 -18
  107. package/dist/src/groups/group-search.js.map +1 -1
  108. package/dist/src/health/complexity-findings.js.map +1 -1
  109. package/dist/src/health/grouping.js.map +1 -1
  110. package/dist/src/health/health-report-types.js.map +1 -1
  111. package/dist/src/health/health-report.js.map +1 -1
  112. package/dist/src/health/targets.js.map +1 -1
  113. package/dist/src/index.d.ts +3 -0
  114. package/dist/src/index.d.ts.map +1 -1
  115. package/dist/src/index.js +3 -0
  116. package/dist/src/index.js.map +1 -1
  117. package/dist/src/ingest/transcribe.js.map +1 -1
  118. package/dist/src/ingest/url-ingest.js.map +1 -1
  119. package/dist/src/license/manager.d.ts.map +1 -1
  120. package/dist/src/license/manager.js.map +1 -1
  121. package/dist/src/lsp/diagnostics-push.js.map +1 -1
  122. package/dist/src/mcp-tools/impact.d.ts.map +1 -1
  123. package/dist/src/mcp-tools/impact.js +7 -1
  124. package/dist/src/mcp-tools/impact.js.map +1 -1
  125. package/dist/src/mcp-tools/list-repos.d.ts +1 -1
  126. package/dist/src/mcp-tools/list-repos.d.ts.map +1 -1
  127. package/dist/src/mcp-tools/query.d.ts +1 -1
  128. package/dist/src/mcp-tools/query.d.ts.map +1 -1
  129. package/dist/src/parsers/c.js.map +1 -1
  130. package/dist/src/parsers/cpp.js.map +1 -1
  131. package/dist/src/parsers/csharp.js.map +1 -1
  132. package/dist/src/parsers/dart.js.map +1 -1
  133. package/dist/src/parsers/go.js.map +1 -1
  134. package/dist/src/parsers/java.js.map +1 -1
  135. package/dist/src/parsers/kotlin.js.map +1 -1
  136. package/dist/src/parsers/loader.js.map +1 -1
  137. package/dist/src/parsers/php.js.map +1 -1
  138. package/dist/src/parsers/python.js.map +1 -1
  139. package/dist/src/parsers/ruby.js.map +1 -1
  140. package/dist/src/parsers/rust.js.map +1 -1
  141. package/dist/src/parsers/swift.js.map +1 -1
  142. package/dist/src/parsers/typescript.js.map +1 -1
  143. package/dist/src/parsers/vue.js.map +1 -1
  144. package/dist/src/pipeline/effort.js.map +1 -1
  145. package/dist/src/pipeline/orchestrator.d.ts.map +1 -1
  146. package/dist/src/pipeline/orchestrator.js +85 -24
  147. package/dist/src/pipeline/orchestrator.js.map +1 -1
  148. package/dist/src/pipeline/phases/bridge-adapters/electron-ipc.d.ts +11 -0
  149. package/dist/src/pipeline/phases/bridge-adapters/electron-ipc.d.ts.map +1 -0
  150. package/dist/src/pipeline/phases/bridge-adapters/electron-ipc.js +96 -0
  151. package/dist/src/pipeline/phases/bridge-adapters/electron-ipc.js.map +1 -0
  152. package/dist/src/pipeline/phases/bridge-adapters/registry.d.ts +3 -0
  153. package/dist/src/pipeline/phases/bridge-adapters/registry.d.ts.map +1 -0
  154. package/dist/src/pipeline/phases/bridge-adapters/registry.js +13 -0
  155. package/dist/src/pipeline/phases/bridge-adapters/registry.js.map +1 -0
  156. package/dist/src/pipeline/phases/bridge-adapters/tauri.d.ts +10 -0
  157. package/dist/src/pipeline/phases/bridge-adapters/tauri.d.ts.map +1 -0
  158. package/dist/src/pipeline/phases/bridge-adapters/tauri.js +104 -0
  159. package/dist/src/pipeline/phases/bridge-adapters/tauri.js.map +1 -0
  160. package/dist/src/pipeline/phases/bridge-adapters/types.d.ts +30 -0
  161. package/dist/src/pipeline/phases/bridge-adapters/types.d.ts.map +1 -0
  162. package/dist/src/pipeline/phases/bridge-adapters/types.js +2 -0
  163. package/dist/src/pipeline/phases/bridge-adapters/types.js.map +1 -0
  164. package/dist/src/pipeline/phases/bridge-adapters/wails.d.ts +10 -0
  165. package/dist/src/pipeline/phases/bridge-adapters/wails.d.ts.map +1 -0
  166. package/dist/src/pipeline/phases/bridge-adapters/wails.js +27 -0
  167. package/dist/src/pipeline/phases/bridge-adapters/wails.js.map +1 -0
  168. package/dist/src/pipeline/phases/bridge-resolver.d.ts +23 -0
  169. package/dist/src/pipeline/phases/bridge-resolver.d.ts.map +1 -0
  170. package/dist/src/pipeline/phases/bridge-resolver.js +70 -0
  171. package/dist/src/pipeline/phases/bridge-resolver.js.map +1 -0
  172. package/dist/src/pipeline/phases/cross-file.d.ts.map +1 -1
  173. package/dist/src/pipeline/phases/cross-file.js +70 -27
  174. package/dist/src/pipeline/phases/cross-file.js.map +1 -1
  175. package/dist/src/pipeline/phases/leiden.js.map +1 -1
  176. package/dist/src/pipeline/phases/parse.d.ts.map +1 -1
  177. package/dist/src/pipeline/phases/parse.js +58 -17
  178. package/dist/src/pipeline/phases/parse.js.map +1 -1
  179. package/dist/src/pipeline/phases/scan.d.ts.map +1 -1
  180. package/dist/src/pipeline/phases/scan.js +12 -5
  181. package/dist/src/pipeline/phases/scan.js.map +1 -1
  182. package/dist/src/pipeline/phases/scope-resolution.d.ts +13 -0
  183. package/dist/src/pipeline/phases/scope-resolution.d.ts.map +1 -1
  184. package/dist/src/pipeline/phases/scope-resolution.js +18 -4
  185. package/dist/src/pipeline/phases/scope-resolution.js.map +1 -1
  186. package/dist/src/pipeline/progress.d.ts.map +1 -1
  187. package/dist/src/pipeline/runner.d.ts.map +1 -1
  188. package/dist/src/pipeline/runner.js.map +1 -1
  189. package/dist/src/pipeline/types.d.ts +2 -0
  190. package/dist/src/pipeline/types.d.ts.map +1 -1
  191. package/dist/src/pipeline/types.js +1 -0
  192. package/dist/src/pipeline/types.js.map +1 -1
  193. package/dist/src/regression/baseline.js.map +1 -1
  194. package/dist/src/regression/outcome.js.map +1 -1
  195. package/dist/src/report/badge-svg.js.map +1 -1
  196. package/dist/src/report/duplication-grouping.js.map +1 -1
  197. package/dist/src/report/human-check.js.map +1 -1
  198. package/dist/src/report/human-dupes.js.map +1 -1
  199. package/dist/src/report/human-health.js.map +1 -1
  200. package/dist/src/report/json-builders.js.map +1 -1
  201. package/dist/src/report/number-format.js.map +1 -1
  202. package/dist/src/reporting/graph-report.d.ts.map +1 -1
  203. package/dist/src/reporting/graph-report.js +8 -9
  204. package/dist/src/reporting/graph-report.js.map +1 -1
  205. package/dist/src/scope-resolution/evidence-weights.d.ts.map +1 -1
  206. package/dist/src/search/hybrid-query.js.map +1 -1
  207. package/dist/src/security/safe-fetch.js.map +1 -1
  208. package/dist/src/staleness/git-staleness.d.ts.map +1 -1
  209. package/dist/src/staleness/git-staleness.js +5 -2
  210. package/dist/src/staleness/git-staleness.js.map +1 -1
  211. package/dist/src/storage/db.d.ts +13 -1
  212. package/dist/src/storage/db.d.ts.map +1 -1
  213. package/dist/src/storage/db.js +23 -2
  214. package/dist/src/storage/db.js.map +1 -1
  215. package/dist/src/storage/edge-store.d.ts +6 -0
  216. package/dist/src/storage/edge-store.d.ts.map +1 -1
  217. package/dist/src/storage/edge-store.js +8 -1
  218. package/dist/src/storage/edge-store.js.map +1 -1
  219. package/dist/src/storage/fts-store.d.ts.map +1 -1
  220. package/dist/src/storage/fts-store.js +31 -9
  221. package/dist/src/storage/fts-store.js.map +1 -1
  222. package/dist/src/storage/node-store.js.map +1 -1
  223. package/dist/src/storage/schema.d.ts +5 -0
  224. package/dist/src/storage/schema.d.ts.map +1 -1
  225. package/dist/src/storage/schema.js +25 -0
  226. package/dist/src/storage/schema.js.map +1 -1
  227. package/dist/src/storage/unlinked-refs.js.map +1 -1
  228. package/dist/src/types.d.ts +2 -2
  229. package/dist/src/types.d.ts.map +1 -1
  230. package/dist/src/types.js.map +1 -1
  231. package/dist/src/watch/watcher.d.ts.map +1 -1
  232. package/dist/src/watch/watcher.js +12 -2
  233. package/dist/src/watch/watcher.js.map +1 -1
  234. package/dist/src/web/analyze-api.d.ts.map +1 -1
  235. package/dist/src/web/analyze-api.js +3 -1
  236. package/dist/src/web/analyze-api.js.map +1 -1
  237. package/dist/src/web/api.d.ts +3 -0
  238. package/dist/src/web/api.d.ts.map +1 -1
  239. package/dist/src/web/api.js +59 -20
  240. package/dist/src/web/api.js.map +1 -1
  241. package/dist/src/web/async-jobs.d.ts.map +1 -1
  242. package/dist/src/web/async-jobs.js +15 -0
  243. package/dist/src/web/async-jobs.js.map +1 -1
  244. package/dist/src/web/react-ui.js +2 -2
  245. package/dist/src/wiki/providers.js.map +1 -1
  246. package/dist/src/wiki/wiki-generator.d.ts.map +1 -1
  247. package/dist/src/wiki/wiki-generator.js +9 -6
  248. package/dist/src/wiki/wiki-generator.js.map +1 -1
  249. package/dist/tsconfig.tsbuildinfo +1 -1
  250. package/package.json +5 -2
  251. package/src/__tests__/graph/dead-code.test.ts +27 -7
  252. package/src/__tests__/pipeline/phases/bridge-adapters/electron-ipc.test.ts +87 -0
  253. package/src/__tests__/pipeline/phases/bridge-adapters/tauri.test.ts +116 -0
  254. package/src/__tests__/pipeline/phases/bridge-adapters/wails.test.ts +81 -0
  255. package/src/__tests__/pipeline/phases/bridge-resolver.test.ts +110 -0
  256. package/src/analysis/changed-files.ts +14 -2
  257. package/src/analysis/changed-workspaces.ts +13 -4
  258. package/src/analysis/churn.ts +57 -10
  259. package/src/analysis/cluster-quality.ts +25 -26
  260. package/src/analysis/combined.ts +2 -0
  261. package/src/analysis/feature-flags.ts +10 -5
  262. package/src/analysis/targets.ts +4 -5
  263. package/src/cache/extraction-cache.ts +59 -6
  264. package/src/cli/doctor.ts +6 -10
  265. package/src/export/analysis-json.ts +1 -1
  266. package/src/export/sarif.ts +11 -2
  267. package/src/graph/baseline.ts +29 -20
  268. package/src/graph/dead-code.ts +19 -16
  269. package/src/graph/health-score.ts +13 -16
  270. package/src/graph/hotspots.ts +8 -4
  271. package/src/graph/pagerank.ts +10 -1
  272. package/src/graph/statistics.ts +19 -7
  273. package/src/graph/stats.ts +2 -1
  274. package/src/groups/group-search.ts +9 -27
  275. package/src/index.ts +3 -0
  276. package/src/mcp-tools/impact.ts +7 -1
  277. package/src/pipeline/orchestrator.ts +87 -26
  278. package/src/pipeline/phases/bridge-adapters/electron-ipc.ts +91 -0
  279. package/src/pipeline/phases/bridge-adapters/registry.ts +14 -0
  280. package/src/pipeline/phases/bridge-adapters/tauri.ts +103 -0
  281. package/src/pipeline/phases/bridge-adapters/types.ts +31 -0
  282. package/src/pipeline/phases/bridge-adapters/wails.ts +33 -0
  283. package/src/pipeline/phases/bridge-resolver.ts +77 -0
  284. package/src/pipeline/phases/cross-file.ts +75 -27
  285. package/src/pipeline/phases/parse.ts +60 -17
  286. package/src/pipeline/phases/scan.ts +11 -5
  287. package/src/pipeline/phases/scope-resolution.ts +19 -4
  288. package/src/pipeline/types.ts +3 -0
  289. package/src/reporting/graph-report.ts +8 -9
  290. package/src/staleness/git-staleness.ts +5 -2
  291. package/src/storage/db.ts +35 -1
  292. package/src/storage/edge-store.ts +8 -1
  293. package/src/storage/fts-store.ts +31 -9
  294. package/src/storage/schema.ts +30 -0
  295. package/src/watch/watcher.ts +11 -2
  296. package/src/web/analyze-api.ts +3 -1
  297. package/src/web/api.ts +62 -22
  298. package/src/web/async-jobs.ts +15 -0
  299. package/src/web/react-ui.ts +2 -2
  300. package/src/wiki/wiki-generator.ts +9 -6
  301. package/tsconfig.json +2 -1
@@ -8,6 +8,7 @@ import { join } from 'path';
8
8
  import { existsSync } from 'fs';
9
9
  import Database from 'better-sqlite3';
10
10
  import { type RankedResult } from '../search/rrf.js';
11
+ import { ftsSearch } from '../storage/fts-store.js';
11
12
  import type { GroupConfig } from './group-config.js';
12
13
 
13
14
  export interface GroupResult {
@@ -19,13 +20,6 @@ export interface GroupResult {
19
20
  score: number;
20
21
  }
21
22
 
22
- interface RawFtsRow {
23
- id: string;
24
- name: string;
25
- label: string;
26
- file_path: string | null;
27
- }
28
-
29
23
  /**
30
24
  * Determine the monograph DB path for a given repo root.
31
25
  * Mirrors the convention used in monograph-tools.ts: <repoPath>/.monomind/monograph.db
@@ -53,31 +47,19 @@ function searchRepo(
53
47
  try {
54
48
  db = new Database(dbPath, { readonly: true });
55
49
 
56
- // Sanitize and build prefix query
57
- const safeQuery = query.replace(/['"*]/g, ' ').trim();
58
- if (!safeQuery) return [];
59
-
60
- const ftsPrefixQuery = safeQuery
61
- .split(/\s+/)
62
- .map((t) => t + '*')
63
- .join(' ');
64
-
65
- const sql = `
66
- SELECT n.id, n.name, n.label, n.file_path
67
- FROM nodes_fts
68
- JOIN nodes n ON n.rowid = nodes_fts.rowid
69
- WHERE nodes_fts MATCH ?
70
- ORDER BY nodes_fts.rank
71
- LIMIT ?
72
- `;
73
-
74
- const rows = db.prepare(sql).all(ftsPrefixQuery, perRepoLimit) as RawFtsRow[];
50
+ // Reuse the SAME ftsSearch() the single-repo `monograph_query` tool uses —
51
+ // its trigram-aware sanitization and MATCH/LIKE fallback (P2-15) — instead of
52
+ // a divergent inline query that appended `*` as if this were a prefix-match
53
+ // tokenizer. The trigram index needs no prefix wildcard and errors on terms
54
+ // shorter than 3 chars when one is appended, which silently produced empty
55
+ // results here before.
56
+ const rows = ftsSearch(db, query, perRepoLimit);
75
57
 
76
58
  return rows.map((r, idx) => ({
77
59
  id: `${repoName}::${r.id}`,
78
60
  name: r.name,
79
61
  label: r.label,
80
- filePath: r.file_path ?? null,
62
+ filePath: r.filePath,
81
63
  repo: repoName,
82
64
  // Use rank position as initial score so RRF can compute correctly
83
65
  score: 1 / (60 + idx + 1),
package/src/index.ts CHANGED
@@ -16,6 +16,9 @@ export * from './export/html.js';
16
16
  export * from './export/cypher.js';
17
17
  export * from './export/graphml.js';
18
18
  export * from './export/svg.js';
19
+ export * from './export/obsidian.js';
20
+ export * from './export/canvas.js';
21
+ export * from './export/mermaid.js';
19
22
  export * from './mcp-tools/index.js';
20
23
  export * from './staleness/git-staleness.js';
21
24
  export * from './search/rrf.js';
@@ -60,7 +60,13 @@ function reverseBfs(
60
60
  const visited = new Map<string, number>([[startNodeId, 0]]);
61
61
  const queue: Array<{ id: string; depth: number }> = [{ id: startNodeId, depth: 0 }];
62
62
 
63
- const relations = options.relationTypes ?? ['CALLS'];
63
+ // Default to a broad set of relation types, not just CALLS — a class extended
64
+ // in 20 files, or a function only ever referenced via import/re-export (never
65
+ // directly called), should still show up in the blast radius. A narrow default
66
+ // reports "0 symbols affected, risk LOW" for changes that are anything but low
67
+ // risk. Callers that need the old narrow/fast behavior can still pass
68
+ // relationTypes: ['CALLS'] explicitly.
69
+ const relations = options.relationTypes ?? ['CALLS', 'IMPORTS', 'REFERENCES', 'EXTENDS', 'RE_EXPORTS'];
64
70
  const placeholders = relations.map(() => '?').join(',');
65
71
  const baseQuery = `SELECT source_id FROM edges WHERE target_id = ? AND relation IN (${placeholders})`;
66
72
  const query = options.minConfidenceScore !== undefined
@@ -11,7 +11,7 @@ import { routesPhase } from './phases/routes.js';
11
11
  import { toolsPhase } from './phases/tools.js';
12
12
  import { ormPhase } from './phases/orm.js';
13
13
  import { crossFilePhase } from './phases/cross-file.js';
14
- import { scopeResolutionPhase } from './phases/scope-resolution.js';
14
+ import { scopeResolutionPhase, clearWorkspacePackageMapCache } from './phases/scope-resolution.js';
15
15
  import { mroPhase } from './phases/mro.js';
16
16
  import { communitiesPhase } from './phases/communities.js';
17
17
  import { processesPhase } from './phases/processes.js';
@@ -22,10 +22,13 @@ import { variablesPhase } from './phases/variables-phase.js';
22
22
  import { wildcardSynthesisPhase } from './phases/wildcard-phase.js';
23
23
  import { frameworkDetectPhase } from './phases/framework-detect.js';
24
24
  import { importResolverPhase } from './phases/import-resolver.js';
25
+ import { bridgeResolverPhase } from './phases/bridge-resolver.js';
25
26
  import type { PipelineOptions, PipelineContext } from './types.js';
26
27
  import { DEFAULT_OPTIONS } from './types.js';
27
28
  import type { PipelineProgress, SuggestedQuestion } from '../types.js';
28
29
  import { generateGraphReport } from '../reporting/graph-report.js';
30
+ import { analyzeChurn } from '../analysis/churn.js';
31
+ import { ExtractionCache } from '../cache/extraction-cache.js';
29
32
 
30
33
  function getCurrentCommitHash(repoPath: string): string | null {
31
34
  try {
@@ -73,6 +76,7 @@ async function acquireBuildLock(dbPath: string): Promise<(() => void) | null> {
73
76
  export async function buildAsync(repoPath: string, options: BuildOptions = {}): Promise<void> {
74
77
  const dbPath = resolve(join(repoPath, '.monomind', 'monograph.db'));
75
78
  const fullOptions: PipelineOptions = { ...DEFAULT_OPTIONS, ...options };
79
+ clearWorkspacePackageMapCache(repoPath);
76
80
 
77
81
  const releaseLock = await acquireBuildLock(dbPath);
78
82
  if (!releaseLock) {
@@ -112,6 +116,20 @@ async function buildAsyncLocked(
112
116
  }
113
117
  }
114
118
 
119
+ // Parse-cache eviction — runs once at the start of a full (non-incremental)
120
+ // build. The cache only ever grows via writes (parse.ts's ExtractionCache);
121
+ // nothing else prunes entries for files that were deleted/renamed or
122
+ // haven't been touched in a long time, so it accumulates forever otherwise.
123
+ if (!options.incremental) {
124
+ try {
125
+ const parseCache = new ExtractionCache(resolve(join(repoPath, '.monomind', 'parse-cache')));
126
+ const removed = parseCache.prune();
127
+ if (removed > 0) {
128
+ options.onProgress?.({ phase: 'prune', message: `Parse cache: pruned ${removed} stale entries` });
129
+ }
130
+ } catch { /* non-fatal — cache pruning must never block a build */ }
131
+ }
132
+
115
133
  const db = openDb(dbPath);
116
134
 
117
135
  try {
@@ -127,47 +145,90 @@ async function buildAsyncLocked(
127
145
  scanPhase, frameworkDetectPhase, structurePhase, parsePhase, variablesPhase,
128
146
  markdownPhase, routesPhase, toolsPhase, ormPhase,
129
147
  crossFilePhase, wildcardSynthesisPhase, importResolverPhase, scopeResolutionPhase,
148
+ bridgeResolverPhase,
130
149
  mroPhase, communitiesPhase, processesPhase, godNodesPhase, surprisesPhase, suggestPhase,
131
150
  ]);
132
151
 
133
152
  const outputs = await runner.run(ctx);
134
153
 
135
- // Skip post-pipeline work when all files were cached (nothing changed)
136
- if (!ctx.allFilesCached) {
137
- // Sweep orphaned rows for files that were renamed/deleted since the last build.
138
- const scanOut = outputs.get('scan') as { filePaths: string[] } | undefined;
139
- if (scanOut) {
140
- const liveFiles = new Set(scanOut.filePaths.map((f) => resolve(f)));
141
- const staleFiles = (
142
- db.prepare('SELECT DISTINCT file_path FROM nodes WHERE file_path IS NOT NULL').all() as { file_path: string }[]
143
- )
144
- .map((r) => r.file_path)
145
- .filter((f) => !liveFiles.has(resolve(ctx.repoPath, f)));
146
- if (staleFiles.length > 0) {
147
- const deleteStale = db.transaction((files: string[]) => {
148
- const deleteEdges = db.prepare(`
149
- DELETE FROM edges WHERE source_id IN (SELECT id FROM nodes WHERE file_path = ?)
150
- OR target_id IN (SELECT id FROM nodes WHERE file_path = ?)
151
- `);
152
- const deleteNodesStmt = db.prepare('DELETE FROM nodes WHERE file_path = ?');
153
- for (const f of files) {
154
- deleteEdges.run(f, f);
155
- deleteNodesStmt.run(f);
156
- }
157
- });
158
- deleteStale(staleFiles);
159
- }
154
+ // Sweep orphaned rows for files that were renamed/deleted since the last build.
155
+ // This MUST run unconditionally — even when every remaining file cache-hit
156
+ // (ctx.allFilesCached === true), a file may have been deleted from disk between
157
+ // builds, which produces zero cache misses but still leaves ghost rows in the DB
158
+ // unless we compare the DB's known file set against the current on-disk set.
159
+ const scanOut = outputs.get('scan') as { filePaths: string[] } | undefined;
160
+ if (scanOut) {
161
+ const liveFiles = new Set(scanOut.filePaths.map((f) => resolve(f)));
162
+ const staleFiles = (
163
+ db.prepare('SELECT DISTINCT file_path FROM nodes WHERE file_path IS NOT NULL').all() as { file_path: string }[]
164
+ )
165
+ .map((r) => r.file_path)
166
+ .filter((f) => !liveFiles.has(resolve(ctx.repoPath, f)));
167
+ if (staleFiles.length > 0) {
168
+ const deleteStale = db.transaction((files: string[]) => {
169
+ const deleteEdges = db.prepare(`
170
+ DELETE FROM edges WHERE source_id IN (SELECT id FROM nodes WHERE file_path = ?)
171
+ OR target_id IN (SELECT id FROM nodes WHERE file_path = ?)
172
+ `);
173
+ const deleteNodesStmt = db.prepare('DELETE FROM nodes WHERE file_path = ?');
174
+ for (const f of files) {
175
+ deleteEdges.run(f, f);
176
+ deleteNodesStmt.run(f);
177
+ }
178
+ });
179
+ deleteStale(staleFiles);
160
180
  }
181
+ }
161
182
 
183
+ // Skip expensive report regeneration when all files were cached (nothing changed) —
184
+ // this is purely a performance optimization, not correctness-critical, so it stays
185
+ // gated behind allFilesCached.
186
+ if (!ctx.allFilesCached) {
162
187
  const suggestOut = outputs.get('suggest') as { questions: SuggestedQuestion[] } | undefined;
163
188
  const questions = suggestOut?.questions ?? [];
164
189
  await generateGraphReport(resolve(repoPath), undefined, dbPath, questions);
165
190
  }
166
191
 
192
+ // Populate churnScore on File nodes from git history (6-month window)
193
+ try {
194
+ const churnResult = await analyzeChurn(ctx.repoPath, '6m');
195
+ if (churnResult.files.length > 0) {
196
+ // Only consider files that exist as graph nodes for normalization —
197
+ // build artifacts and config files inflate the denominator otherwise
198
+ const graphFiles = new Set(
199
+ (db.prepare("SELECT file_path FROM nodes WHERE label = 'File' AND file_path IS NOT NULL").all() as { file_path: string }[])
200
+ .map(r => r.file_path),
201
+ );
202
+ const graphChurn = churnResult.files.filter(f => graphFiles.has(f.path));
203
+ const maxWeighted = graphChurn.reduce((m, f) => f.weightedCommits > m ? f.weightedCommits : m, 0);
204
+ if (maxWeighted > 0) {
205
+ const updateProps = db.prepare(`
206
+ UPDATE nodes SET properties = json_set(COALESCE(properties, '{}'), '$.churnScore', ?)
207
+ WHERE file_path = ? AND label = 'File'
208
+ `);
209
+ db.transaction(() => {
210
+ for (const f of graphChurn) {
211
+ updateProps.run(f.weightedCommits / maxWeighted, f.path);
212
+ }
213
+ })();
214
+ }
215
+ }
216
+ } catch {
217
+ // churn analysis is non-fatal (e.g. no git history)
218
+ }
219
+
167
220
  const hash = getCurrentCommitHash(resolve(repoPath));
168
221
  if (hash) {
169
222
  db.prepare("INSERT OR REPLACE INTO index_meta VALUES ('last_commit_hash', ?)").run(hash);
223
+ } else {
224
+ const msg = 'Could not determine git HEAD — staleness tracking will be unavailable';
225
+ if (options.onProgress) {
226
+ options.onProgress({ phase: 'warning', message: msg } as PipelineProgress);
227
+ } else {
228
+ process.stderr.write(`[monograph] ${msg}\n`);
229
+ }
170
230
  }
231
+ db.prepare("INSERT OR REPLACE INTO index_meta VALUES ('indexed_at', ?)").run(new Date().toISOString());
171
232
  } finally {
172
233
  closeDb(db);
173
234
  }
@@ -0,0 +1,91 @@
1
+ import { statSync, readFileSync } from 'fs';
2
+ import { join, extname } from 'path';
3
+ import type { PipelineContext } from '../../types.js';
4
+ import type { BridgeAdapter, BridgeEndpoint } from './types.js';
5
+
6
+ const JS_TS_EXT = new Set(['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs']);
7
+
8
+ const IPC_MAIN_RE = /\bipcMain\.(?:handle|on)\(\s*['"]([^'"]+)['"]/g;
9
+ const IPC_RENDERER_RE = /\bipcRenderer\.(?:invoke|send)\(\s*['"]([^'"]+)['"]/g;
10
+
11
+ function safeReadSource(absPath: string, maxBytes: number): string | undefined {
12
+ try {
13
+ const stat = statSync(absPath);
14
+ if (stat.size > maxBytes) return undefined;
15
+ return readFileSync(absPath, 'utf-8');
16
+ } catch {
17
+ return undefined;
18
+ }
19
+ }
20
+
21
+ function extractChannels(re: RegExp, source: string): string[] {
22
+ re.lastIndex = 0;
23
+ const names: string[] = [];
24
+ let m: RegExpExecArray | null;
25
+ while ((m = re.exec(source)) !== null) names.push(m[1]!);
26
+ return names;
27
+ }
28
+
29
+ /**
30
+ * Electron IPC (main process JS <-> renderer/preload JS): both sides are the
31
+ * same language, so nothing in the existing same-file import resolution
32
+ * connects them — the only link is the shared channel-name string literal
33
+ * passed to `ipcMain.handle/on` (definition) and `ipcRenderer.invoke/send`
34
+ * (call site). Neither side has call-expression-level node granularity from
35
+ * a plain regex scan, so both attach to their containing File node.
36
+ */
37
+ export const electronIpcAdapter: BridgeAdapter = {
38
+ name: 'electron-ipc',
39
+
40
+ detect(ctx, filePaths) {
41
+ let hasMain = false;
42
+ let hasRenderer = false;
43
+ for (const relPath of filePaths) {
44
+ if (!JS_TS_EXT.has(extname(relPath))) continue;
45
+ const source = safeReadSource(join(ctx.repoPath, relPath), ctx.options.maxFileSizeBytes);
46
+ if (!source) continue;
47
+ if (!hasMain && /\bipcMain\.(?:handle|on)\(/.test(source)) hasMain = true;
48
+ if (!hasRenderer && /\bipcRenderer\.(?:invoke|send)\(/.test(source)) hasRenderer = true;
49
+ if (hasMain && hasRenderer) return true;
50
+ }
51
+ return false;
52
+ },
53
+
54
+ findDefinitions(ctx, filePaths) {
55
+ const endpoints: BridgeEndpoint[] = [];
56
+ for (const relPath of filePaths) {
57
+ if (!JS_TS_EXT.has(extname(relPath))) continue;
58
+ const source = safeReadSource(join(ctx.repoPath, relPath), ctx.options.maxFileSizeBytes);
59
+ if (!source) continue;
60
+ const channels = extractChannels(IPC_MAIN_RE, source);
61
+ if (channels.length === 0) continue;
62
+
63
+ const fileRow = ctx.db
64
+ .prepare(`SELECT id FROM nodes WHERE label = 'File' AND file_path = ?`)
65
+ .get(relPath) as { id: string } | undefined;
66
+ if (!fileRow) continue;
67
+
68
+ for (const channel of channels) endpoints.push({ key: channel, nodeId: fileRow.id, language: 'javascript' });
69
+ }
70
+ return endpoints;
71
+ },
72
+
73
+ findCallSites(ctx, filePaths) {
74
+ const endpoints: BridgeEndpoint[] = [];
75
+ for (const relPath of filePaths) {
76
+ if (!JS_TS_EXT.has(extname(relPath))) continue;
77
+ const source = safeReadSource(join(ctx.repoPath, relPath), ctx.options.maxFileSizeBytes);
78
+ if (!source) continue;
79
+ const channels = extractChannels(IPC_RENDERER_RE, source);
80
+ if (channels.length === 0) continue;
81
+
82
+ const fileRow = ctx.db
83
+ .prepare(`SELECT id FROM nodes WHERE label = 'File' AND file_path = ?`)
84
+ .get(relPath) as { id: string } | undefined;
85
+ if (!fileRow) continue;
86
+
87
+ for (const channel of channels) endpoints.push({ key: channel, nodeId: fileRow.id, language: 'javascript' });
88
+ }
89
+ return endpoints;
90
+ },
91
+ };
@@ -0,0 +1,14 @@
1
+ import type { BridgeAdapter } from './types.js';
2
+ import { wailsAdapter } from './wails.js';
3
+ import { tauriAdapter } from './tauri.js';
4
+ import { electronIpcAdapter } from './electron-ipc.js';
5
+
6
+ // Every adapter here has an unambiguous detect() signal (a generated binding
7
+ // path, or a framework-specific call shape that only appears when its
8
+ // framework is actually in use) — so all run unconditionally; detect() is
9
+ // what keeps the no-op cost near zero for repos that don't use any of them.
10
+ export const BUILTIN_BRIDGE_ADAPTERS: BridgeAdapter[] = [
11
+ wailsAdapter,
12
+ tauriAdapter,
13
+ electronIpcAdapter,
14
+ ];
@@ -0,0 +1,103 @@
1
+ import { statSync, readFileSync } from 'fs';
2
+ import { join, extname } from 'path';
3
+ import type { PipelineContext } from '../../types.js';
4
+ import type { BridgeAdapter, BridgeEndpoint } from './types.js';
5
+
6
+ const RUST_EXT = new Set(['.rs']);
7
+ const JS_TS_EXT = new Set(['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs']);
8
+
9
+ /** `#[tauri::command]` (with or without args) directly above an fn declaration. */
10
+ const TAURI_COMMAND_RE = /#\[tauri::command(?:\([^)]*\))?\]\s*(?:pub(?:\([^)]*\))?\s+)?(?:async\s+)?fn\s+(\w+)/g;
11
+
12
+ /**
13
+ * Tauri's `invoke(...)` call from the JS/TS side, e.g.
14
+ * `import { invoke } from '@tauri-apps/api/core'; invoke('my_command', {...})`.
15
+ * We don't verify the import — matching the call shape is enough signal here,
16
+ * same tradeoff extractor.ts already makes for plain call-site regexes.
17
+ */
18
+ const TAURI_INVOKE_RE = /\binvoke\(\s*['"]([^'"]+)['"]/g;
19
+
20
+ function safeReadSource(absPath: string, maxBytes: number): string | undefined {
21
+ try {
22
+ const stat = statSync(absPath);
23
+ if (stat.size > maxBytes) return undefined;
24
+ return readFileSync(absPath, 'utf-8');
25
+ } catch {
26
+ return undefined;
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Tauri (Rust <-> JS/TS): a `#[tauri::command]`-annotated Rust fn is invoked
32
+ * from the frontend by name via `invoke("name", ...)` — a string-literal
33
+ * match, not a generated file. The Rust side already has a real Function
34
+ * node (from the Rust extractor); the JS/TS call site does not, so it's
35
+ * attached to its containing File node.
36
+ */
37
+ export const tauriAdapter: BridgeAdapter = {
38
+ name: 'tauri',
39
+
40
+ // A bare .rs file isn't a Tauri signal by itself (a repo can have unrelated
41
+ // Rust code alongside a JS/TS frontend) — require an actual
42
+ // #[tauri::command] annotation before this adapter runs at all.
43
+ detect(ctx, filePaths) {
44
+ for (const relPath of filePaths) {
45
+ if (!RUST_EXT.has(extname(relPath))) continue;
46
+ const source = safeReadSource(join(ctx.repoPath, relPath), ctx.options.maxFileSizeBytes);
47
+ if (!source) continue;
48
+ TAURI_COMMAND_RE.lastIndex = 0;
49
+ if (TAURI_COMMAND_RE.test(source)) return true;
50
+ }
51
+ return false;
52
+ },
53
+
54
+ findDefinitions(ctx, filePaths) {
55
+ const endpoints: BridgeEndpoint[] = [];
56
+ for (const relPath of filePaths) {
57
+ if (!RUST_EXT.has(extname(relPath))) continue;
58
+ const source = safeReadSource(join(ctx.repoPath, relPath), ctx.options.maxFileSizeBytes);
59
+ if (!source) continue;
60
+
61
+ TAURI_COMMAND_RE.lastIndex = 0;
62
+ let m: RegExpExecArray | null;
63
+ const names: string[] = [];
64
+ while ((m = TAURI_COMMAND_RE.exec(source)) !== null) names.push(m[1]!);
65
+ if (names.length === 0) continue;
66
+
67
+ const rows = ctx.db
68
+ .prepare(`SELECT id, name FROM nodes WHERE label = 'Function' AND language = 'rust' AND file_path = ?`)
69
+ .all(relPath) as { id: string; name: string }[];
70
+ const byName = new Map(rows.map((r) => [r.name, r.id]));
71
+ for (const name of names) {
72
+ const nodeId = byName.get(name);
73
+ if (nodeId) endpoints.push({ key: name, nodeId, language: 'rust' });
74
+ }
75
+ }
76
+ return endpoints;
77
+ },
78
+
79
+ findCallSites(ctx, filePaths) {
80
+ const endpoints: BridgeEndpoint[] = [];
81
+ for (const relPath of filePaths) {
82
+ if (!JS_TS_EXT.has(extname(relPath))) continue;
83
+ const source = safeReadSource(join(ctx.repoPath, relPath), ctx.options.maxFileSizeBytes);
84
+ if (!source) continue;
85
+
86
+ TAURI_INVOKE_RE.lastIndex = 0;
87
+ let m: RegExpExecArray | null;
88
+ const commandNames: string[] = [];
89
+ while ((m = TAURI_INVOKE_RE.exec(source)) !== null) commandNames.push(m[1]!);
90
+ if (commandNames.length === 0) continue;
91
+
92
+ const fileRow = ctx.db
93
+ .prepare(`SELECT id FROM nodes WHERE label = 'File' AND file_path = ?`)
94
+ .get(relPath) as { id: string } | undefined;
95
+ if (!fileRow) continue;
96
+
97
+ for (const name of commandNames) {
98
+ endpoints.push({ key: name, nodeId: fileRow.id, language: 'javascript' });
99
+ }
100
+ }
101
+ return endpoints;
102
+ },
103
+ };
@@ -0,0 +1,31 @@
1
+ import type { PipelineContext } from '../../types.js';
2
+
3
+ /**
4
+ * One side of a cross-language bridge boundary — a definition (the thing being
5
+ * exposed across the boundary) or a call site (the thing invoking across it).
6
+ * `key` is the string both sides are matched on: an exact symbol name for
7
+ * codegen-based bridges (Wails, wasm-bindgen), or a string-literal channel/
8
+ * command name for registration-based bridges (Tauri, Electron IPC).
9
+ */
10
+ export interface BridgeEndpoint {
11
+ key: string;
12
+ nodeId: string;
13
+ language: string;
14
+ }
15
+
16
+ /**
17
+ * A cross-language bridge adapter. Each adapter independently extracts
18
+ * (key, nodeId) pairs from both sides of one specific FFI/IPC/RPC boundary;
19
+ * the bridge-resolver phase matches them by key and emits CALLS edges.
20
+ *
21
+ * `detect` must be cheap — it runs for every adapter on every build, so an
22
+ * adapter whose framework isn't present in the repo should bail out fast
23
+ * (e.g. checking file paths already collected by the scan phase) rather than
24
+ * re-reading the filesystem.
25
+ */
26
+ export interface BridgeAdapter {
27
+ name: string;
28
+ detect(ctx: PipelineContext, filePaths: string[]): boolean;
29
+ findDefinitions(ctx: PipelineContext, filePaths: string[]): BridgeEndpoint[];
30
+ findCallSites(ctx: PipelineContext, filePaths: string[]): BridgeEndpoint[];
31
+ }
@@ -0,0 +1,33 @@
1
+ import type { PipelineContext } from '../../types.js';
2
+ import type { BridgeAdapter, BridgeEndpoint } from './types.js';
3
+
4
+ const WAILS_BINDING_RE = /wailsjs\/go\//i;
5
+
6
+ /**
7
+ * Wails (Go <-> JS/TS): `wails` generates a JS/TS binding file per bound Go
8
+ * struct at `frontend/**\/wailsjs/go/<package>/<Struct>.js`, exporting one
9
+ * function per Go method with the exact same name. Both sides are already
10
+ * parsed into real Function/Method nodes by the Go and TS/JS extractors —
11
+ * this adapter just links them by name across the language boundary.
12
+ */
13
+ export const wailsAdapter: BridgeAdapter = {
14
+ name: 'wails',
15
+
16
+ detect(_ctx, filePaths) {
17
+ return filePaths.some((p) => WAILS_BINDING_RE.test(p));
18
+ },
19
+
20
+ findDefinitions(ctx) {
21
+ const rows = ctx.db
22
+ .prepare(`SELECT id, name, language FROM nodes WHERE label = 'Method' AND language = 'go' AND file_path IS NOT NULL`)
23
+ .all() as { id: string; name: string; language: string }[];
24
+ return rows.map((r): BridgeEndpoint => ({ key: r.name, nodeId: r.id, language: r.language }));
25
+ },
26
+
27
+ findCallSites(ctx) {
28
+ const rows = ctx.db
29
+ .prepare(`SELECT id, name, language, file_path FROM nodes WHERE label = 'Function' AND file_path LIKE '%wailsjs/go/%'`)
30
+ .all() as { id: string; name: string; language: string; file_path: string }[];
31
+ return rows.map((r): BridgeEndpoint => ({ key: r.name, nodeId: r.id, language: r.language ?? 'javascript' }));
32
+ },
33
+ };
@@ -0,0 +1,77 @@
1
+ import type { PipelinePhase } from '../types.js';
2
+ import type { MonographEdge } from '../../types.js';
3
+ import { makeId, CONFIDENCE_SCORE } from '../../types.js';
4
+ import { insertEdges } from '../../storage/edge-store.js';
5
+ import type { ScanOutput } from './scan.js';
6
+ import { BUILTIN_BRIDGE_ADAPTERS } from './bridge-adapters/registry.js';
7
+ import type { BridgeEndpoint } from './bridge-adapters/types.js';
8
+
9
+ export interface BridgeResolverOutput {
10
+ edgesCreated: number;
11
+ }
12
+
13
+ /**
14
+ * Cross-language bridge resolution — links calls across an FFI/IPC boundary
15
+ * that no single language's own import/call resolution can see (Wails'
16
+ * generated Go<->JS bindings, Tauri's invoke() commands, Electron's IPC
17
+ * channels, ...). Each adapter in bridge-adapters/ extracts (key, nodeId)
18
+ * pairs from both sides; here they're matched by key and turned into CALLS
19
+ * edges — reusing the existing relation so every existing consumer
20
+ * (monograph_impact, monograph_neighbors, community detection) picks them up
21
+ * with no changes on their end.
22
+ *
23
+ * Confidence is always INFERRED: a bridge edge is a name/key match, not an
24
+ * AST-verified call. A key with more than one matching definition is
25
+ * dropped rather than guessed at — the call site can't know which one was
26
+ * meant, and a wrong edge is worse than a missing one. Multiple call sites
27
+ * sharing one definition (the common case: several UI files calling the
28
+ * same bound method) is normal and always kept.
29
+ */
30
+ export const bridgeResolverPhase: PipelinePhase<BridgeResolverOutput> = {
31
+ name: 'bridge-resolver',
32
+ deps: ['scan', 'structure', 'parse'],
33
+ async execute(ctx, deps) {
34
+ if (ctx.allFilesCached) return { edgesCreated: 0 };
35
+
36
+ const { filePaths } = deps.get('scan') as ScanOutput;
37
+ const edges: MonographEdge[] = [];
38
+
39
+ for (const adapter of BUILTIN_BRIDGE_ADAPTERS) {
40
+ if (!adapter.detect(ctx, filePaths)) continue;
41
+
42
+ const definitions = adapter.findDefinitions(ctx, filePaths);
43
+ const callSites = adapter.findCallSites(ctx, filePaths);
44
+ if (definitions.length === 0 || callSites.length === 0) continue;
45
+
46
+ const definitionsByKey = new Map<string, BridgeEndpoint[]>();
47
+ for (const def of definitions) {
48
+ const arr = definitionsByKey.get(def.key);
49
+ if (arr) arr.push(def);
50
+ else definitionsByKey.set(def.key, [def]);
51
+ }
52
+
53
+ for (const callSite of callSites) {
54
+ const matches = definitionsByKey.get(callSite.key);
55
+ if (!matches || matches.length !== 1) continue; // 0 or ambiguous — drop, don't guess
56
+ const target = matches[0]!;
57
+ if (target.nodeId === callSite.nodeId) continue; // same node on both sides — nothing to link
58
+
59
+ const id = makeId('bridge', adapter.name, callSite.nodeId, target.nodeId);
60
+ const languagePair = `${callSite.language} -> ${target.language}`;
61
+ edges.push({
62
+ id,
63
+ sourceId: callSite.nodeId,
64
+ targetId: target.nodeId,
65
+ relation: 'CALLS',
66
+ confidence: 'INFERRED',
67
+ confidenceScore: CONFIDENCE_SCORE.INFERRED,
68
+ reason: `${adapter.name} bridge (${languagePair}): "${callSite.key}"`,
69
+ evidence: [{ kind: 'bridge', weight: CONFIDENCE_SCORE.INFERRED, note: `${adapter.name}: ${languagePair}` }],
70
+ });
71
+ }
72
+ }
73
+
74
+ if (edges.length > 0) insertEdges(ctx.db, edges);
75
+ return { edgesCreated: edges.length };
76
+ },
77
+ };