okstra 0.108.0 → 0.109.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (642) hide show
  1. package/package.json +1 -1
  2. package/runtime/BUILD.json +2 -2
  3. package/runtime/prompts/profiles/_common-contract.md +1 -1
  4. package/runtime/python/okstra_ctl/graphify_cmd.py +225 -0
  5. package/runtime/python/okstra_ctl/resolve_task_key.py +15 -9
  6. package/runtime/python/okstra_project/__init__.py +2 -0
  7. package/runtime/python/okstra_project/state.py +36 -0
  8. package/runtime/python/okstra_vendor/__init__.py +41 -0
  9. package/runtime/python/okstra_vendor/graphify/.vendored-version +1 -0
  10. package/runtime/python/okstra_vendor/graphify/__init__.py +28 -0
  11. package/runtime/python/okstra_vendor/graphify/__main__.py +1371 -0
  12. package/runtime/python/okstra_vendor/graphify/analyze.py +540 -0
  13. package/runtime/python/okstra_vendor/graphify/benchmark.py +129 -0
  14. package/runtime/python/okstra_vendor/graphify/build.py +107 -0
  15. package/runtime/python/okstra_vendor/graphify/cache.py +169 -0
  16. package/runtime/python/okstra_vendor/graphify/cluster.py +137 -0
  17. package/runtime/python/okstra_vendor/graphify/detect.py +510 -0
  18. package/runtime/python/okstra_vendor/graphify/export.py +1014 -0
  19. package/runtime/python/okstra_vendor/graphify/extract.py +3277 -0
  20. package/runtime/python/okstra_vendor/graphify/hooks.py +220 -0
  21. package/runtime/python/okstra_vendor/graphify/ingest.py +297 -0
  22. package/runtime/python/okstra_vendor/graphify/manifest.py +4 -0
  23. package/runtime/python/okstra_vendor/graphify/report.py +175 -0
  24. package/runtime/python/okstra_vendor/graphify/security.py +203 -0
  25. package/runtime/python/okstra_vendor/graphify/serve.py +373 -0
  26. package/runtime/python/okstra_vendor/graphify/skill-aider.md +1184 -0
  27. package/runtime/python/okstra_vendor/graphify/skill-claw.md +1184 -0
  28. package/runtime/python/okstra_vendor/graphify/skill-codex.md +1242 -0
  29. package/runtime/python/okstra_vendor/graphify/skill-copilot.md +1268 -0
  30. package/runtime/python/okstra_vendor/graphify/skill-droid.md +1239 -0
  31. package/runtime/python/okstra_vendor/graphify/skill-kiro.md +1183 -0
  32. package/runtime/python/okstra_vendor/graphify/skill-opencode.md +1238 -0
  33. package/runtime/python/okstra_vendor/graphify/skill-trae.md +1208 -0
  34. package/runtime/python/okstra_vendor/graphify/skill-vscode.md +253 -0
  35. package/runtime/python/okstra_vendor/graphify/skill-windows.md +1245 -0
  36. package/runtime/python/okstra_vendor/graphify/skill.md +1319 -0
  37. package/runtime/python/okstra_vendor/graphify/transcribe.py +182 -0
  38. package/runtime/python/okstra_vendor/graphify/validate.py +72 -0
  39. package/runtime/python/okstra_vendor/graphify/watch.py +188 -0
  40. package/runtime/python/okstra_vendor/graphify/wiki.py +214 -0
  41. package/runtime/python/okstra_vendor/networkx/__init__.py +62 -0
  42. package/runtime/python/okstra_vendor/networkx/algorithms/__init__.py +134 -0
  43. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/__init__.py +26 -0
  44. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clique.py +259 -0
  45. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clustering_coefficient.py +71 -0
  46. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/connectivity.py +412 -0
  47. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/density.py +396 -0
  48. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/distance_measures.py +150 -0
  49. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/dominating_set.py +149 -0
  50. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/kcomponents.py +369 -0
  51. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/matching.py +44 -0
  52. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/maxcut.py +143 -0
  53. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/ramsey.py +53 -0
  54. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/steinertree.py +265 -0
  55. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/__init__.py +0 -0
  56. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py +41 -0
  57. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_clique.py +112 -0
  58. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_connectivity.py +199 -0
  59. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_density.py +146 -0
  60. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_distance_measures.py +59 -0
  61. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_dominating_set.py +78 -0
  62. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_kcomponents.py +303 -0
  63. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_matching.py +8 -0
  64. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_maxcut.py +94 -0
  65. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_ramsey.py +31 -0
  66. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_steinertree.py +306 -0
  67. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_traveling_salesman.py +1014 -0
  68. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_treewidth.py +274 -0
  69. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_vertex_cover.py +68 -0
  70. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/traveling_salesman.py +1508 -0
  71. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/treewidth.py +255 -0
  72. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/vertex_cover.py +83 -0
  73. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/__init__.py +5 -0
  74. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/connectivity.py +122 -0
  75. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/correlation.py +302 -0
  76. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/mixing.py +255 -0
  77. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/neighbor_degree.py +160 -0
  78. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/pairs.py +127 -0
  79. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/__init__.py +0 -0
  80. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/base_test.py +81 -0
  81. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_connectivity.py +143 -0
  82. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_correlation.py +122 -0
  83. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_mixing.py +174 -0
  84. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_neighbor_degree.py +107 -0
  85. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_pairs.py +87 -0
  86. package/runtime/python/okstra_vendor/networkx/algorithms/asteroidal.py +164 -0
  87. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/__init__.py +88 -0
  88. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/basic.py +322 -0
  89. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/centrality.py +290 -0
  90. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/cluster.py +289 -0
  91. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/covering.py +57 -0
  92. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/edgelist.py +360 -0
  93. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/extendability.py +105 -0
  94. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/generators.py +603 -0
  95. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/link_analysis.py +316 -0
  96. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matching.py +590 -0
  97. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matrix.py +232 -0
  98. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/projection.py +526 -0
  99. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/redundancy.py +112 -0
  100. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/spectral.py +69 -0
  101. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/__init__.py +0 -0
  102. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_basic.py +125 -0
  103. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_centrality.py +192 -0
  104. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_cluster.py +84 -0
  105. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_covering.py +33 -0
  106. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_edgelist.py +240 -0
  107. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_extendability.py +334 -0
  108. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_generators.py +407 -0
  109. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_link_analysis.py +218 -0
  110. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matching.py +327 -0
  111. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matrix.py +138 -0
  112. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_project.py +409 -0
  113. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_redundancy.py +35 -0
  114. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py +80 -0
  115. package/runtime/python/okstra_vendor/networkx/algorithms/boundary.py +168 -0
  116. package/runtime/python/okstra_vendor/networkx/algorithms/bridges.py +205 -0
  117. package/runtime/python/okstra_vendor/networkx/algorithms/broadcasting.py +164 -0
  118. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/__init__.py +20 -0
  119. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness.py +591 -0
  120. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness_subset.py +236 -0
  121. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/closeness.py +282 -0
  122. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness.py +364 -0
  123. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness_subset.py +227 -0
  124. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_closeness.py +96 -0
  125. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/degree_alg.py +150 -0
  126. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/dispersion.py +107 -0
  127. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/eigenvector.py +357 -0
  128. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/flow_matrix.py +130 -0
  129. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/group.py +787 -0
  130. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/harmonic.py +88 -0
  131. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/katz.py +331 -0
  132. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/laplacian.py +150 -0
  133. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/load.py +200 -0
  134. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/percolation.py +128 -0
  135. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/reaching.py +209 -0
  136. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/second_order.py +141 -0
  137. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/subgraph_alg.py +361 -0
  138. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/__init__.py +0 -0
  139. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality.py +923 -0
  140. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality_subset.py +354 -0
  141. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_closeness_centrality.py +274 -0
  142. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py +259 -0
  143. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality_subset.py +147 -0
  144. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_closeness.py +43 -0
  145. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_degree_centrality.py +144 -0
  146. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_dispersion.py +73 -0
  147. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py +186 -0
  148. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_group.py +277 -0
  149. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_harmonic_centrality.py +122 -0
  150. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_katz_centrality.py +345 -0
  151. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_laplacian_centrality.py +220 -0
  152. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_load_centrality.py +344 -0
  153. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_percolation_centrality.py +87 -0
  154. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_reaching.py +140 -0
  155. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_second_order_centrality.py +82 -0
  156. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_subgraph.py +110 -0
  157. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_trophic.py +302 -0
  158. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_voterank.py +64 -0
  159. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/trophic.py +181 -0
  160. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/voterank_alg.py +95 -0
  161. package/runtime/python/okstra_vendor/networkx/algorithms/chains.py +172 -0
  162. package/runtime/python/okstra_vendor/networkx/algorithms/chordal.py +443 -0
  163. package/runtime/python/okstra_vendor/networkx/algorithms/clique.py +818 -0
  164. package/runtime/python/okstra_vendor/networkx/algorithms/cluster.py +732 -0
  165. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/__init__.py +4 -0
  166. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/equitable_coloring.py +505 -0
  167. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/greedy_coloring.py +565 -0
  168. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/__init__.py +0 -0
  169. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/test_coloring.py +863 -0
  170. package/runtime/python/okstra_vendor/networkx/algorithms/communicability_alg.py +163 -0
  171. package/runtime/python/okstra_vendor/networkx/algorithms/community/__init__.py +28 -0
  172. package/runtime/python/okstra_vendor/networkx/algorithms/community/asyn_fluid.py +153 -0
  173. package/runtime/python/okstra_vendor/networkx/algorithms/community/bipartitions.py +354 -0
  174. package/runtime/python/okstra_vendor/networkx/algorithms/community/centrality.py +171 -0
  175. package/runtime/python/okstra_vendor/networkx/algorithms/community/community_utils.py +30 -0
  176. package/runtime/python/okstra_vendor/networkx/algorithms/community/divisive.py +216 -0
  177. package/runtime/python/okstra_vendor/networkx/algorithms/community/kclique.py +79 -0
  178. package/runtime/python/okstra_vendor/networkx/algorithms/community/label_propagation.py +338 -0
  179. package/runtime/python/okstra_vendor/networkx/algorithms/community/leiden.py +162 -0
  180. package/runtime/python/okstra_vendor/networkx/algorithms/community/local.py +220 -0
  181. package/runtime/python/okstra_vendor/networkx/algorithms/community/louvain.py +384 -0
  182. package/runtime/python/okstra_vendor/networkx/algorithms/community/lukes.py +227 -0
  183. package/runtime/python/okstra_vendor/networkx/algorithms/community/modularity_max.py +452 -0
  184. package/runtime/python/okstra_vendor/networkx/algorithms/community/quality.py +347 -0
  185. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/__init__.py +0 -0
  186. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_asyn_fluid.py +147 -0
  187. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_bipartitions.py +157 -0
  188. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_centrality.py +85 -0
  189. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_divisive.py +106 -0
  190. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_kclique.py +91 -0
  191. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_label_propagation.py +241 -0
  192. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_leiden.py +138 -0
  193. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_local.py +76 -0
  194. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_louvain.py +264 -0
  195. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_lukes.py +152 -0
  196. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_modularity_max.py +340 -0
  197. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_quality.py +139 -0
  198. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_utils.py +26 -0
  199. package/runtime/python/okstra_vendor/networkx/algorithms/components/__init__.py +6 -0
  200. package/runtime/python/okstra_vendor/networkx/algorithms/components/attracting.py +115 -0
  201. package/runtime/python/okstra_vendor/networkx/algorithms/components/biconnected.py +394 -0
  202. package/runtime/python/okstra_vendor/networkx/algorithms/components/connected.py +282 -0
  203. package/runtime/python/okstra_vendor/networkx/algorithms/components/semiconnected.py +71 -0
  204. package/runtime/python/okstra_vendor/networkx/algorithms/components/strongly_connected.py +359 -0
  205. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/__init__.py +0 -0
  206. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_attracting.py +70 -0
  207. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_biconnected.py +248 -0
  208. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_connected.py +138 -0
  209. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_semiconnected.py +55 -0
  210. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_strongly_connected.py +193 -0
  211. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_weakly_connected.py +96 -0
  212. package/runtime/python/okstra_vendor/networkx/algorithms/components/weakly_connected.py +196 -0
  213. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/__init__.py +11 -0
  214. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/connectivity.py +811 -0
  215. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/cuts.py +616 -0
  216. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/disjoint_paths.py +408 -0
  217. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_augmentation.py +1270 -0
  218. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_kcomponents.py +592 -0
  219. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcomponents.py +220 -0
  220. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcutsets.py +235 -0
  221. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/stoerwagner.py +152 -0
  222. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/__init__.py +0 -0
  223. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_connectivity.py +421 -0
  224. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_cuts.py +309 -0
  225. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_disjoint_paths.py +249 -0
  226. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_augmentation.py +502 -0
  227. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py +488 -0
  228. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcomponents.py +323 -0
  229. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcutsets.py +280 -0
  230. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_stoer_wagner.py +102 -0
  231. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/utils.py +88 -0
  232. package/runtime/python/okstra_vendor/networkx/algorithms/core.py +588 -0
  233. package/runtime/python/okstra_vendor/networkx/algorithms/covering.py +142 -0
  234. package/runtime/python/okstra_vendor/networkx/algorithms/cuts.py +416 -0
  235. package/runtime/python/okstra_vendor/networkx/algorithms/cycles.py +1234 -0
  236. package/runtime/python/okstra_vendor/networkx/algorithms/d_separation.py +677 -0
  237. package/runtime/python/okstra_vendor/networkx/algorithms/dag.py +1392 -0
  238. package/runtime/python/okstra_vendor/networkx/algorithms/distance_measures.py +1095 -0
  239. package/runtime/python/okstra_vendor/networkx/algorithms/distance_regular.py +272 -0
  240. package/runtime/python/okstra_vendor/networkx/algorithms/dominance.py +142 -0
  241. package/runtime/python/okstra_vendor/networkx/algorithms/dominating.py +268 -0
  242. package/runtime/python/okstra_vendor/networkx/algorithms/efficiency_measures.py +167 -0
  243. package/runtime/python/okstra_vendor/networkx/algorithms/euler.py +470 -0
  244. package/runtime/python/okstra_vendor/networkx/algorithms/flow/__init__.py +11 -0
  245. package/runtime/python/okstra_vendor/networkx/algorithms/flow/boykovkolmogorov.py +370 -0
  246. package/runtime/python/okstra_vendor/networkx/algorithms/flow/capacityscaling.py +407 -0
  247. package/runtime/python/okstra_vendor/networkx/algorithms/flow/dinitz_alg.py +238 -0
  248. package/runtime/python/okstra_vendor/networkx/algorithms/flow/edmondskarp.py +241 -0
  249. package/runtime/python/okstra_vendor/networkx/algorithms/flow/gomory_hu.py +178 -0
  250. package/runtime/python/okstra_vendor/networkx/algorithms/flow/maxflow.py +611 -0
  251. package/runtime/python/okstra_vendor/networkx/algorithms/flow/mincost.py +356 -0
  252. package/runtime/python/okstra_vendor/networkx/algorithms/flow/networksimplex.py +662 -0
  253. package/runtime/python/okstra_vendor/networkx/algorithms/flow/preflowpush.py +425 -0
  254. package/runtime/python/okstra_vendor/networkx/algorithms/flow/shortestaugmentingpath.py +300 -0
  255. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/__init__.py +0 -0
  256. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gl1.gpickle.bz2 +0 -0
  257. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gw1.gpickle.bz2 +0 -0
  258. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/netgen-2.gpickle.bz2 +0 -0
  259. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_gomory_hu.py +128 -0
  260. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow.py +573 -0
  261. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow_large_graph.py +155 -0
  262. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_mincost.py +475 -0
  263. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_networksimplex.py +481 -0
  264. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/wlm3.gpickle.bz2 +0 -0
  265. package/runtime/python/okstra_vendor/networkx/algorithms/flow/utils.py +194 -0
  266. package/runtime/python/okstra_vendor/networkx/algorithms/graph_hashing.py +435 -0
  267. package/runtime/python/okstra_vendor/networkx/algorithms/graphical.py +483 -0
  268. package/runtime/python/okstra_vendor/networkx/algorithms/hierarchy.py +57 -0
  269. package/runtime/python/okstra_vendor/networkx/algorithms/hybrid.py +196 -0
  270. package/runtime/python/okstra_vendor/networkx/algorithms/isolate.py +107 -0
  271. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/__init__.py +7 -0
  272. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/ismags.py +1306 -0
  273. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorph.py +336 -0
  274. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorphvf2.py +1262 -0
  275. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/matchhelpers.py +352 -0
  276. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/temporalisomorphvf2.py +308 -0
  277. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/__init__.py +0 -0
  278. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.A99 +0 -0
  279. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.B99 +0 -0
  280. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.A99 +0 -0
  281. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.B99 +0 -0
  282. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_ismags.py +719 -0
  283. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphism.py +103 -0
  284. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py +490 -0
  285. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_match_helpers.py +64 -0
  286. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py +212 -0
  287. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py +202 -0
  288. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp.py +1655 -0
  289. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp_helpers.py +3118 -0
  290. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py +196 -0
  291. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tree_isomorphism.py +264 -0
  292. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2pp.py +1102 -0
  293. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2userfunc.py +192 -0
  294. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/__init__.py +2 -0
  295. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/hits_alg.py +337 -0
  296. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/pagerank_alg.py +498 -0
  297. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/__init__.py +0 -0
  298. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_hits.py +77 -0
  299. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_pagerank.py +213 -0
  300. package/runtime/python/okstra_vendor/networkx/algorithms/link_prediction.py +687 -0
  301. package/runtime/python/okstra_vendor/networkx/algorithms/lowest_common_ancestors.py +280 -0
  302. package/runtime/python/okstra_vendor/networkx/algorithms/matching.py +1148 -0
  303. package/runtime/python/okstra_vendor/networkx/algorithms/minors/__init__.py +27 -0
  304. package/runtime/python/okstra_vendor/networkx/algorithms/minors/contraction.py +738 -0
  305. package/runtime/python/okstra_vendor/networkx/algorithms/minors/tests/test_contraction.py +544 -0
  306. package/runtime/python/okstra_vendor/networkx/algorithms/mis.py +78 -0
  307. package/runtime/python/okstra_vendor/networkx/algorithms/moral.py +59 -0
  308. package/runtime/python/okstra_vendor/networkx/algorithms/node_classification.py +219 -0
  309. package/runtime/python/okstra_vendor/networkx/algorithms/non_randomness.py +155 -0
  310. package/runtime/python/okstra_vendor/networkx/algorithms/operators/__init__.py +4 -0
  311. package/runtime/python/okstra_vendor/networkx/algorithms/operators/all.py +324 -0
  312. package/runtime/python/okstra_vendor/networkx/algorithms/operators/binary.py +468 -0
  313. package/runtime/python/okstra_vendor/networkx/algorithms/operators/product.py +633 -0
  314. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/__init__.py +0 -0
  315. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_all.py +328 -0
  316. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_binary.py +451 -0
  317. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_product.py +491 -0
  318. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_unary.py +55 -0
  319. package/runtime/python/okstra_vendor/networkx/algorithms/operators/unary.py +77 -0
  320. package/runtime/python/okstra_vendor/networkx/algorithms/perfect_graph.py +73 -0
  321. package/runtime/python/okstra_vendor/networkx/algorithms/planar_drawing.py +464 -0
  322. package/runtime/python/okstra_vendor/networkx/algorithms/planarity.py +1463 -0
  323. package/runtime/python/okstra_vendor/networkx/algorithms/polynomials.py +306 -0
  324. package/runtime/python/okstra_vendor/networkx/algorithms/reciprocity.py +98 -0
  325. package/runtime/python/okstra_vendor/networkx/algorithms/regular.py +167 -0
  326. package/runtime/python/okstra_vendor/networkx/algorithms/richclub.py +138 -0
  327. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/__init__.py +5 -0
  328. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/astar.py +239 -0
  329. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/dense.py +264 -0
  330. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/generic.py +716 -0
  331. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/__init__.py +0 -0
  332. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_astar.py +254 -0
  333. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense.py +212 -0
  334. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py +88 -0
  335. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_generic.py +511 -0
  336. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_unweighted.py +149 -0
  337. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_weighted.py +983 -0
  338. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/unweighted.py +625 -0
  339. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/weighted.py +2542 -0
  340. package/runtime/python/okstra_vendor/networkx/algorithms/similarity.py +2107 -0
  341. package/runtime/python/okstra_vendor/networkx/algorithms/simple_paths.py +966 -0
  342. package/runtime/python/okstra_vendor/networkx/algorithms/smallworld.py +404 -0
  343. package/runtime/python/okstra_vendor/networkx/algorithms/smetric.py +30 -0
  344. package/runtime/python/okstra_vendor/networkx/algorithms/sparsifiers.py +296 -0
  345. package/runtime/python/okstra_vendor/networkx/algorithms/structuralholes.py +374 -0
  346. package/runtime/python/okstra_vendor/networkx/algorithms/summarization.py +564 -0
  347. package/runtime/python/okstra_vendor/networkx/algorithms/swap.py +406 -0
  348. package/runtime/python/okstra_vendor/networkx/algorithms/tests/__init__.py +0 -0
  349. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_asteroidal.py +23 -0
  350. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_boundary.py +154 -0
  351. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_bridges.py +144 -0
  352. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_broadcasting.py +109 -0
  353. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chains.py +136 -0
  354. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chordal.py +129 -0
  355. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_clique.py +300 -0
  356. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cluster.py +678 -0
  357. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_communicability.py +80 -0
  358. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_core.py +266 -0
  359. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_covering.py +85 -0
  360. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cuts.py +171 -0
  361. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cycles.py +984 -0
  362. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_d_separation.py +340 -0
  363. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dag.py +835 -0
  364. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_measures.py +831 -0
  365. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_regular.py +85 -0
  366. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominance.py +299 -0
  367. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominating.py +115 -0
  368. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_efficiency.py +58 -0
  369. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_euler.py +314 -0
  370. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graph_hashing.py +872 -0
  371. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graphical.py +163 -0
  372. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hierarchy.py +46 -0
  373. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hybrid.py +24 -0
  374. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_isolate.py +26 -0
  375. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_link_prediction.py +615 -0
  376. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_lowest_common_ancestors.py +459 -0
  377. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_matching.py +556 -0
  378. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_max_weight_clique.py +179 -0
  379. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_mis.py +62 -0
  380. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_moral.py +15 -0
  381. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_node_classification.py +140 -0
  382. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_non_randomness.py +60 -0
  383. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_perfect_graph.py +27 -0
  384. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planar_drawing.py +274 -0
  385. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planarity.py +556 -0
  386. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_polynomials.py +57 -0
  387. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_reciprocity.py +37 -0
  388. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_regular.py +88 -0
  389. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_richclub.py +149 -0
  390. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_similarity.py +1158 -0
  391. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_simple_paths.py +803 -0
  392. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smallworld.py +76 -0
  393. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smetric.py +8 -0
  394. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_sparsifiers.py +138 -0
  395. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_structuralholes.py +191 -0
  396. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_summarization.py +642 -0
  397. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_swap.py +179 -0
  398. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_threshold.py +270 -0
  399. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_time_dependent.py +431 -0
  400. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_tournament.py +161 -0
  401. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_triads.py +248 -0
  402. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_vitality.py +41 -0
  403. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_voronoi.py +103 -0
  404. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_walks.py +54 -0
  405. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_wiener.py +157 -0
  406. package/runtime/python/okstra_vendor/networkx/algorithms/threshold.py +981 -0
  407. package/runtime/python/okstra_vendor/networkx/algorithms/time_dependent.py +142 -0
  408. package/runtime/python/okstra_vendor/networkx/algorithms/tournament.py +406 -0
  409. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/__init__.py +5 -0
  410. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/beamsearch.py +90 -0
  411. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/breadth_first_search.py +576 -0
  412. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/depth_first_search.py +529 -0
  413. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgebfs.py +185 -0
  414. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgedfs.py +182 -0
  415. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/__init__.py +0 -0
  416. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_beamsearch.py +25 -0
  417. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_bfs.py +203 -0
  418. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_dfs.py +307 -0
  419. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgebfs.py +147 -0
  420. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgedfs.py +131 -0
  421. package/runtime/python/okstra_vendor/networkx/algorithms/tree/__init__.py +7 -0
  422. package/runtime/python/okstra_vendor/networkx/algorithms/tree/branchings.py +1042 -0
  423. package/runtime/python/okstra_vendor/networkx/algorithms/tree/coding.py +413 -0
  424. package/runtime/python/okstra_vendor/networkx/algorithms/tree/decomposition.py +88 -0
  425. package/runtime/python/okstra_vendor/networkx/algorithms/tree/distance_measures.py +219 -0
  426. package/runtime/python/okstra_vendor/networkx/algorithms/tree/mst.py +1281 -0
  427. package/runtime/python/okstra_vendor/networkx/algorithms/tree/operations.py +106 -0
  428. package/runtime/python/okstra_vendor/networkx/algorithms/tree/recognition.py +273 -0
  429. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/__init__.py +0 -0
  430. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_branchings.py +624 -0
  431. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_coding.py +114 -0
  432. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_decomposition.py +79 -0
  433. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_distance_measures.py +99 -0
  434. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_mst.py +934 -0
  435. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_operations.py +53 -0
  436. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_recognition.py +174 -0
  437. package/runtime/python/okstra_vendor/networkx/algorithms/triads.py +500 -0
  438. package/runtime/python/okstra_vendor/networkx/algorithms/vitality.py +76 -0
  439. package/runtime/python/okstra_vendor/networkx/algorithms/voronoi.py +86 -0
  440. package/runtime/python/okstra_vendor/networkx/algorithms/walks.py +77 -0
  441. package/runtime/python/okstra_vendor/networkx/algorithms/wiener.py +278 -0
  442. package/runtime/python/okstra_vendor/networkx/classes/__init__.py +13 -0
  443. package/runtime/python/okstra_vendor/networkx/classes/coreviews.py +435 -0
  444. package/runtime/python/okstra_vendor/networkx/classes/digraph.py +1363 -0
  445. package/runtime/python/okstra_vendor/networkx/classes/filters.py +95 -0
  446. package/runtime/python/okstra_vendor/networkx/classes/function.py +1549 -0
  447. package/runtime/python/okstra_vendor/networkx/classes/graph.py +2082 -0
  448. package/runtime/python/okstra_vendor/networkx/classes/graphviews.py +269 -0
  449. package/runtime/python/okstra_vendor/networkx/classes/multidigraph.py +977 -0
  450. package/runtime/python/okstra_vendor/networkx/classes/multigraph.py +1294 -0
  451. package/runtime/python/okstra_vendor/networkx/classes/reportviews.py +1447 -0
  452. package/runtime/python/okstra_vendor/networkx/classes/tests/__init__.py +0 -0
  453. package/runtime/python/okstra_vendor/networkx/classes/tests/dispatch_interface.py +192 -0
  454. package/runtime/python/okstra_vendor/networkx/classes/tests/historical_tests.py +476 -0
  455. package/runtime/python/okstra_vendor/networkx/classes/tests/test_coreviews.py +362 -0
  456. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph.py +331 -0
  457. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph_historical.py +110 -0
  458. package/runtime/python/okstra_vendor/networkx/classes/tests/test_filters.py +177 -0
  459. package/runtime/python/okstra_vendor/networkx/classes/tests/test_function.py +1045 -0
  460. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph.py +950 -0
  461. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph_historical.py +12 -0
  462. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graphviews.py +349 -0
  463. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multidigraph.py +459 -0
  464. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multigraph.py +528 -0
  465. package/runtime/python/okstra_vendor/networkx/classes/tests/test_reportviews.py +1421 -0
  466. package/runtime/python/okstra_vendor/networkx/classes/tests/test_special.py +131 -0
  467. package/runtime/python/okstra_vendor/networkx/classes/tests/test_subgraphviews.py +371 -0
  468. package/runtime/python/okstra_vendor/networkx/conftest.py +261 -0
  469. package/runtime/python/okstra_vendor/networkx/convert.py +502 -0
  470. package/runtime/python/okstra_vendor/networkx/convert_matrix.py +1314 -0
  471. package/runtime/python/okstra_vendor/networkx/drawing/__init__.py +7 -0
  472. package/runtime/python/okstra_vendor/networkx/drawing/layout.py +2036 -0
  473. package/runtime/python/okstra_vendor/networkx/drawing/nx_agraph.py +470 -0
  474. package/runtime/python/okstra_vendor/networkx/drawing/nx_latex.py +570 -0
  475. package/runtime/python/okstra_vendor/networkx/drawing/nx_pydot.py +361 -0
  476. package/runtime/python/okstra_vendor/networkx/drawing/nx_pylab.py +2978 -0
  477. package/runtime/python/okstra_vendor/networkx/drawing/tests/__init__.py +0 -0
  478. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_complex.png +0 -0
  479. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_empty_graph.png +0 -0
  480. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_house_with_colors.png +0 -0
  481. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_labels_and_colors.png +0 -0
  482. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_shortest_path.png +0 -0
  483. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_house_with_colors.png +0 -0
  484. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_agraph.py +237 -0
  485. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_image_comparison_pylab_mpl.py +229 -0
  486. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_latex.py +285 -0
  487. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_layout.py +631 -0
  488. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pydot.py +146 -0
  489. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pylab.py +1582 -0
  490. package/runtime/python/okstra_vendor/networkx/exception.py +131 -0
  491. package/runtime/python/okstra_vendor/networkx/generators/__init__.py +34 -0
  492. package/runtime/python/okstra_vendor/networkx/generators/atlas.dat.gz +0 -0
  493. package/runtime/python/okstra_vendor/networkx/generators/atlas.py +227 -0
  494. package/runtime/python/okstra_vendor/networkx/generators/classic.py +1091 -0
  495. package/runtime/python/okstra_vendor/networkx/generators/cographs.py +68 -0
  496. package/runtime/python/okstra_vendor/networkx/generators/community.py +1070 -0
  497. package/runtime/python/okstra_vendor/networkx/generators/degree_seq.py +886 -0
  498. package/runtime/python/okstra_vendor/networkx/generators/directed.py +572 -0
  499. package/runtime/python/okstra_vendor/networkx/generators/duplication.py +174 -0
  500. package/runtime/python/okstra_vendor/networkx/generators/ego.py +66 -0
  501. package/runtime/python/okstra_vendor/networkx/generators/expanders.py +499 -0
  502. package/runtime/python/okstra_vendor/networkx/generators/geometric.py +1037 -0
  503. package/runtime/python/okstra_vendor/networkx/generators/harary_graph.py +163 -0
  504. package/runtime/python/okstra_vendor/networkx/generators/internet_as_graphs.py +443 -0
  505. package/runtime/python/okstra_vendor/networkx/generators/intersection.py +125 -0
  506. package/runtime/python/okstra_vendor/networkx/generators/interval_graph.py +70 -0
  507. package/runtime/python/okstra_vendor/networkx/generators/joint_degree_seq.py +664 -0
  508. package/runtime/python/okstra_vendor/networkx/generators/lattice.py +405 -0
  509. package/runtime/python/okstra_vendor/networkx/generators/line.py +501 -0
  510. package/runtime/python/okstra_vendor/networkx/generators/mycielski.py +110 -0
  511. package/runtime/python/okstra_vendor/networkx/generators/nonisomorphic_trees.py +259 -0
  512. package/runtime/python/okstra_vendor/networkx/generators/random_clustered.py +117 -0
  513. package/runtime/python/okstra_vendor/networkx/generators/random_graphs.py +1416 -0
  514. package/runtime/python/okstra_vendor/networkx/generators/small.py +1070 -0
  515. package/runtime/python/okstra_vendor/networkx/generators/social.py +554 -0
  516. package/runtime/python/okstra_vendor/networkx/generators/spectral_graph_forge.py +120 -0
  517. package/runtime/python/okstra_vendor/networkx/generators/stochastic.py +54 -0
  518. package/runtime/python/okstra_vendor/networkx/generators/sudoku.py +131 -0
  519. package/runtime/python/okstra_vendor/networkx/generators/tests/__init__.py +0 -0
  520. package/runtime/python/okstra_vendor/networkx/generators/tests/test_atlas.py +75 -0
  521. package/runtime/python/okstra_vendor/networkx/generators/tests/test_classic.py +642 -0
  522. package/runtime/python/okstra_vendor/networkx/generators/tests/test_cographs.py +20 -0
  523. package/runtime/python/okstra_vendor/networkx/generators/tests/test_community.py +362 -0
  524. package/runtime/python/okstra_vendor/networkx/generators/tests/test_degree_seq.py +224 -0
  525. package/runtime/python/okstra_vendor/networkx/generators/tests/test_directed.py +189 -0
  526. package/runtime/python/okstra_vendor/networkx/generators/tests/test_duplication.py +103 -0
  527. package/runtime/python/okstra_vendor/networkx/generators/tests/test_ego.py +39 -0
  528. package/runtime/python/okstra_vendor/networkx/generators/tests/test_expanders.py +182 -0
  529. package/runtime/python/okstra_vendor/networkx/generators/tests/test_geometric.py +488 -0
  530. package/runtime/python/okstra_vendor/networkx/generators/tests/test_harary_graph.py +133 -0
  531. package/runtime/python/okstra_vendor/networkx/generators/tests/test_internet_as_graphs.py +221 -0
  532. package/runtime/python/okstra_vendor/networkx/generators/tests/test_intersection.py +28 -0
  533. package/runtime/python/okstra_vendor/networkx/generators/tests/test_interval_graph.py +144 -0
  534. package/runtime/python/okstra_vendor/networkx/generators/tests/test_joint_degree_seq.py +125 -0
  535. package/runtime/python/okstra_vendor/networkx/generators/tests/test_lattice.py +264 -0
  536. package/runtime/python/okstra_vendor/networkx/generators/tests/test_line.py +316 -0
  537. package/runtime/python/okstra_vendor/networkx/generators/tests/test_mycielski.py +30 -0
  538. package/runtime/python/okstra_vendor/networkx/generators/tests/test_nonisomorphic_trees.py +82 -0
  539. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_clustered.py +33 -0
  540. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_graphs.py +495 -0
  541. package/runtime/python/okstra_vendor/networkx/generators/tests/test_small.py +220 -0
  542. package/runtime/python/okstra_vendor/networkx/generators/tests/test_spectral_graph_forge.py +49 -0
  543. package/runtime/python/okstra_vendor/networkx/generators/tests/test_stochastic.py +72 -0
  544. package/runtime/python/okstra_vendor/networkx/generators/tests/test_sudoku.py +92 -0
  545. package/runtime/python/okstra_vendor/networkx/generators/tests/test_time_series.py +64 -0
  546. package/runtime/python/okstra_vendor/networkx/generators/tests/test_trees.py +195 -0
  547. package/runtime/python/okstra_vendor/networkx/generators/tests/test_triads.py +15 -0
  548. package/runtime/python/okstra_vendor/networkx/generators/time_series.py +74 -0
  549. package/runtime/python/okstra_vendor/networkx/generators/trees.py +1070 -0
  550. package/runtime/python/okstra_vendor/networkx/generators/triads.py +94 -0
  551. package/runtime/python/okstra_vendor/networkx/lazy_imports.py +188 -0
  552. package/runtime/python/okstra_vendor/networkx/linalg/__init__.py +13 -0
  553. package/runtime/python/okstra_vendor/networkx/linalg/algebraicconnectivity.py +650 -0
  554. package/runtime/python/okstra_vendor/networkx/linalg/attrmatrix.py +466 -0
  555. package/runtime/python/okstra_vendor/networkx/linalg/bethehessianmatrix.py +77 -0
  556. package/runtime/python/okstra_vendor/networkx/linalg/graphmatrix.py +168 -0
  557. package/runtime/python/okstra_vendor/networkx/linalg/laplacianmatrix.py +512 -0
  558. package/runtime/python/okstra_vendor/networkx/linalg/modularitymatrix.py +166 -0
  559. package/runtime/python/okstra_vendor/networkx/linalg/spectrum.py +186 -0
  560. package/runtime/python/okstra_vendor/networkx/linalg/tests/__init__.py +0 -0
  561. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_algebraic_connectivity.py +400 -0
  562. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_attrmatrix.py +108 -0
  563. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_bethehessian.py +40 -0
  564. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_graphmatrix.py +275 -0
  565. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_laplacian.py +334 -0
  566. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_modularity.py +86 -0
  567. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_spectrum.py +70 -0
  568. package/runtime/python/okstra_vendor/networkx/readwrite/__init__.py +17 -0
  569. package/runtime/python/okstra_vendor/networkx/readwrite/adjlist.py +330 -0
  570. package/runtime/python/okstra_vendor/networkx/readwrite/edgelist.py +489 -0
  571. package/runtime/python/okstra_vendor/networkx/readwrite/gexf.py +1084 -0
  572. package/runtime/python/okstra_vendor/networkx/readwrite/gml.py +879 -0
  573. package/runtime/python/okstra_vendor/networkx/readwrite/graph6.py +427 -0
  574. package/runtime/python/okstra_vendor/networkx/readwrite/graphml.py +1053 -0
  575. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/__init__.py +19 -0
  576. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/adjacency.py +156 -0
  577. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/cytoscape.py +190 -0
  578. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/node_link.py +261 -0
  579. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/__init__.py +0 -0
  580. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_adjacency.py +78 -0
  581. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_cytoscape.py +78 -0
  582. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_node_link.py +109 -0
  583. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_tree.py +48 -0
  584. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tree.py +137 -0
  585. package/runtime/python/okstra_vendor/networkx/readwrite/leda.py +108 -0
  586. package/runtime/python/okstra_vendor/networkx/readwrite/multiline_adjlist.py +393 -0
  587. package/runtime/python/okstra_vendor/networkx/readwrite/p2g.py +113 -0
  588. package/runtime/python/okstra_vendor/networkx/readwrite/pajek.py +286 -0
  589. package/runtime/python/okstra_vendor/networkx/readwrite/sparse6.py +379 -0
  590. package/runtime/python/okstra_vendor/networkx/readwrite/tests/__init__.py +0 -0
  591. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_adjlist.py +354 -0
  592. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_edgelist.py +318 -0
  593. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gexf.py +612 -0
  594. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gml.py +744 -0
  595. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graph6.py +181 -0
  596. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graphml.py +1531 -0
  597. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_leda.py +30 -0
  598. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_p2g.py +63 -0
  599. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_pajek.py +128 -0
  600. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_sparse6.py +166 -0
  601. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_text.py +1742 -0
  602. package/runtime/python/okstra_vendor/networkx/readwrite/text.py +851 -0
  603. package/runtime/python/okstra_vendor/networkx/relabel.py +285 -0
  604. package/runtime/python/okstra_vendor/networkx/tests/__init__.py +0 -0
  605. package/runtime/python/okstra_vendor/networkx/tests/test_all_random_functions.py +248 -0
  606. package/runtime/python/okstra_vendor/networkx/tests/test_convert.py +321 -0
  607. package/runtime/python/okstra_vendor/networkx/tests/test_convert_numpy.py +531 -0
  608. package/runtime/python/okstra_vendor/networkx/tests/test_convert_pandas.py +349 -0
  609. package/runtime/python/okstra_vendor/networkx/tests/test_convert_scipy.py +281 -0
  610. package/runtime/python/okstra_vendor/networkx/tests/test_exceptions.py +40 -0
  611. package/runtime/python/okstra_vendor/networkx/tests/test_import.py +11 -0
  612. package/runtime/python/okstra_vendor/networkx/tests/test_lazy_imports.py +96 -0
  613. package/runtime/python/okstra_vendor/networkx/tests/test_relabel.py +349 -0
  614. package/runtime/python/okstra_vendor/networkx/tests/test_removed_functions_exception_messages.py +8 -0
  615. package/runtime/python/okstra_vendor/networkx/utils/__init__.py +8 -0
  616. package/runtime/python/okstra_vendor/networkx/utils/backends.py +2171 -0
  617. package/runtime/python/okstra_vendor/networkx/utils/configs.py +396 -0
  618. package/runtime/python/okstra_vendor/networkx/utils/decorators.py +1233 -0
  619. package/runtime/python/okstra_vendor/networkx/utils/heaps.py +338 -0
  620. package/runtime/python/okstra_vendor/networkx/utils/mapped_queue.py +297 -0
  621. package/runtime/python/okstra_vendor/networkx/utils/misc.py +703 -0
  622. package/runtime/python/okstra_vendor/networkx/utils/random_sequence.py +198 -0
  623. package/runtime/python/okstra_vendor/networkx/utils/rcm.py +159 -0
  624. package/runtime/python/okstra_vendor/networkx/utils/tests/__init__.py +0 -0
  625. package/runtime/python/okstra_vendor/networkx/utils/tests/test__init.py +11 -0
  626. package/runtime/python/okstra_vendor/networkx/utils/tests/test_backends.py +225 -0
  627. package/runtime/python/okstra_vendor/networkx/utils/tests/test_config.py +263 -0
  628. package/runtime/python/okstra_vendor/networkx/utils/tests/test_decorators.py +510 -0
  629. package/runtime/python/okstra_vendor/networkx/utils/tests/test_heaps.py +131 -0
  630. package/runtime/python/okstra_vendor/networkx/utils/tests/test_mapped_queue.py +268 -0
  631. package/runtime/python/okstra_vendor/networkx/utils/tests/test_misc.py +393 -0
  632. package/runtime/python/okstra_vendor/networkx/utils/tests/test_random_sequence.py +53 -0
  633. package/runtime/python/okstra_vendor/networkx/utils/tests/test_rcm.py +63 -0
  634. package/runtime/python/okstra_vendor/networkx/utils/tests/test_unionfind.py +55 -0
  635. package/runtime/python/okstra_vendor/networkx/utils/union_find.py +106 -0
  636. package/runtime/skills/okstra-graphify/SKILL.md +161 -0
  637. package/runtime/skills/okstra-inspect/SKILL.md +17 -9
  638. package/runtime/templates/reports/settings.template.json +4 -0
  639. package/src/cli-registry.mjs +7 -0
  640. package/src/commands/graphify.mjs +32 -0
  641. package/src/commands/lifecycle/doctor.mjs +9 -0
  642. package/src/lib/skill-catalog.mjs +1 -0
@@ -0,0 +1,1014 @@
1
+ # write graph to HTML, JSON, SVG, GraphML, Obsidian vault, and Neo4j Cypher
2
+ from __future__ import annotations
3
+ import html as _html
4
+ import json
5
+ import math
6
+ import re
7
+ from collections import Counter
8
+ from pathlib import Path
9
+ import networkx as nx
10
+ from networkx.readwrite import json_graph
11
+ from graphify.security import sanitize_label
12
+ from graphify.analyze import _node_community_map
13
+
14
+ def _strip_diacritics(text: str) -> str:
15
+ import unicodedata
16
+ nfkd = unicodedata.normalize("NFKD", text)
17
+ return "".join(c for c in nfkd if not unicodedata.combining(c))
18
+
19
+
20
+ COMMUNITY_COLORS = [
21
+ "#4E79A7", "#F28E2B", "#E15759", "#76B7B2", "#59A14F",
22
+ "#EDC948", "#B07AA1", "#FF9DA7", "#9C755F", "#BAB0AC",
23
+ ]
24
+
25
+ MAX_NODES_FOR_VIZ = 5_000
26
+
27
+
28
+ def _html_styles() -> str:
29
+ return """<style>
30
+ * { box-sizing: border-box; margin: 0; padding: 0; }
31
+ body { background: #0f0f1a; color: #e0e0e0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; display: flex; height: 100vh; overflow: hidden; }
32
+ #graph { flex: 1; }
33
+ #sidebar { width: 280px; background: #1a1a2e; border-left: 1px solid #2a2a4e; display: flex; flex-direction: column; overflow: hidden; }
34
+ #search-wrap { padding: 12px; border-bottom: 1px solid #2a2a4e; }
35
+ #search { width: 100%; background: #0f0f1a; border: 1px solid #3a3a5e; color: #e0e0e0; padding: 7px 10px; border-radius: 6px; font-size: 13px; outline: none; }
36
+ #search:focus { border-color: #4E79A7; }
37
+ #search-results { max-height: 140px; overflow-y: auto; padding: 4px 12px; border-bottom: 1px solid #2a2a4e; display: none; }
38
+ .search-item { padding: 4px 6px; cursor: pointer; border-radius: 4px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
39
+ .search-item:hover { background: #2a2a4e; }
40
+ #info-panel { padding: 14px; border-bottom: 1px solid #2a2a4e; min-height: 140px; }
41
+ #info-panel h3 { font-size: 13px; color: #aaa; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
42
+ #info-content { font-size: 13px; color: #ccc; line-height: 1.6; }
43
+ #info-content .field { margin-bottom: 5px; }
44
+ #info-content .field b { color: #e0e0e0; }
45
+ #info-content .empty { color: #555; font-style: italic; }
46
+ .neighbor-link { display: block; padding: 2px 6px; margin: 2px 0; border-radius: 3px; cursor: pointer; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid #333; }
47
+ .neighbor-link:hover { background: #2a2a4e; }
48
+ #neighbors-list { max-height: 160px; overflow-y: auto; margin-top: 4px; }
49
+ #legend-wrap { flex: 1; overflow-y: auto; padding: 12px; }
50
+ #legend-wrap h3 { font-size: 13px; color: #aaa; margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
51
+ .legend-item { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; border-radius: 4px; font-size: 12px; }
52
+ .legend-item:hover { background: #2a2a4e; padding-left: 4px; }
53
+ .legend-item.dimmed { opacity: 0.35; }
54
+ .legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
55
+ .legend-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
56
+ .legend-count { color: #666; font-size: 11px; }
57
+ #stats { padding: 10px 14px; border-top: 1px solid #2a2a4e; font-size: 11px; color: #555; }
58
+ </style>"""
59
+
60
+
61
+ def _hyperedge_script(hyperedges_json: str) -> str:
62
+ return f"""<script>
63
+ // Render hyperedges as shaded regions
64
+ const hyperedges = {hyperedges_json};
65
+ // afterDrawing passes ctx already transformed to network coordinate space.
66
+ // Draw node positions raw — no manual pan/zoom/DPR math needed.
67
+ network.on('afterDrawing', function(ctx) {{
68
+ hyperedges.forEach(h => {{
69
+ const positions = h.nodes
70
+ .map(nid => network.getPositions([nid])[nid])
71
+ .filter(p => p !== undefined);
72
+ if (positions.length < 2) return;
73
+ ctx.save();
74
+ ctx.globalAlpha = 0.12;
75
+ ctx.fillStyle = '#6366f1';
76
+ ctx.strokeStyle = '#6366f1';
77
+ ctx.lineWidth = 2;
78
+ ctx.beginPath();
79
+ // Centroid and expanded hull in network coordinates
80
+ const cx = positions.reduce((s, p) => s + p.x, 0) / positions.length;
81
+ const cy = positions.reduce((s, p) => s + p.y, 0) / positions.length;
82
+ const expanded = positions.map(p => ({{
83
+ x: cx + (p.x - cx) * 1.15,
84
+ y: cy + (p.y - cy) * 1.15
85
+ }}));
86
+ ctx.moveTo(expanded[0].x, expanded[0].y);
87
+ expanded.slice(1).forEach(p => ctx.lineTo(p.x, p.y));
88
+ ctx.closePath();
89
+ ctx.fill();
90
+ ctx.globalAlpha = 0.4;
91
+ ctx.stroke();
92
+ // Label
93
+ ctx.globalAlpha = 0.8;
94
+ ctx.fillStyle = '#4f46e5';
95
+ ctx.font = 'bold 11px sans-serif';
96
+ ctx.textAlign = 'center';
97
+ ctx.fillText(h.label, cx, cy - 5);
98
+ ctx.restore();
99
+ }});
100
+ }});
101
+ </script>"""
102
+
103
+
104
+ def _html_script(nodes_json: str, edges_json: str, legend_json: str) -> str:
105
+ return f"""<script>
106
+ const RAW_NODES = {nodes_json};
107
+ const RAW_EDGES = {edges_json};
108
+ const LEGEND = {legend_json};
109
+
110
+ // HTML-escape helper — prevents XSS when injecting graph data into innerHTML
111
+ function esc(s) {{
112
+ return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;');
113
+ }}
114
+
115
+ // Build vis datasets
116
+ const nodesDS = new vis.DataSet(RAW_NODES.map(n => ({{
117
+ id: n.id, label: n.label, color: n.color, size: n.size,
118
+ font: n.font, title: n.title,
119
+ _community: n.community, _community_name: n.community_name,
120
+ _source_file: n.source_file, _file_type: n.file_type, _degree: n.degree,
121
+ }})));
122
+
123
+ const edgesDS = new vis.DataSet(RAW_EDGES.map((e, i) => ({{
124
+ id: i, from: e.from, to: e.to,
125
+ label: '',
126
+ title: e.title,
127
+ dashes: e.dashes,
128
+ width: e.width,
129
+ color: e.color,
130
+ arrows: {{ to: {{ enabled: true, scaleFactor: 0.5 }} }},
131
+ }})));
132
+
133
+ const container = document.getElementById('graph');
134
+ const network = new vis.Network(container, {{ nodes: nodesDS, edges: edgesDS }}, {{
135
+ physics: {{
136
+ enabled: true,
137
+ solver: 'forceAtlas2Based',
138
+ forceAtlas2Based: {{
139
+ gravitationalConstant: -60,
140
+ centralGravity: 0.005,
141
+ springLength: 120,
142
+ springConstant: 0.08,
143
+ damping: 0.4,
144
+ avoidOverlap: 0.8,
145
+ }},
146
+ stabilization: {{ iterations: 200, fit: true }},
147
+ }},
148
+ interaction: {{
149
+ hover: true,
150
+ tooltipDelay: 100,
151
+ hideEdgesOnDrag: true,
152
+ navigationButtons: false,
153
+ keyboard: false,
154
+ }},
155
+ nodes: {{ shape: 'dot', borderWidth: 1.5 }},
156
+ edges: {{ smooth: {{ type: 'continuous', roundness: 0.2 }}, selectionWidth: 3 }},
157
+ }});
158
+
159
+ network.once('stabilizationIterationsDone', () => {{
160
+ network.setOptions({{ physics: {{ enabled: false }} }});
161
+ }});
162
+
163
+ function showInfo(nodeId) {{
164
+ const n = nodesDS.get(nodeId);
165
+ if (!n) return;
166
+ const neighborIds = network.getConnectedNodes(nodeId);
167
+ const neighborItems = neighborIds.map(nid => {{
168
+ const nb = nodesDS.get(nid);
169
+ const color = nb ? nb.color.background : '#555';
170
+ return `<span class="neighbor-link" style="border-left-color:${{esc(color)}}" onclick="focusNode(${{JSON.stringify(nid)}})">${{esc(nb ? nb.label : nid)}}</span>`;
171
+ }}).join('');
172
+ document.getElementById('info-content').innerHTML = `
173
+ <div class="field"><b>${{esc(n.label)}}</b></div>
174
+ <div class="field">Type: ${{esc(n._file_type || 'unknown')}}</div>
175
+ <div class="field">Community: ${{esc(n._community_name)}}</div>
176
+ <div class="field">Source: ${{esc(n._source_file || '-')}}</div>
177
+ <div class="field">Degree: ${{n._degree}}</div>
178
+ ${{neighborIds.length ? `<div class="field" style="margin-top:8px;color:#aaa;font-size:11px">Neighbors (${{neighborIds.length}})</div><div id="neighbors-list">${{neighborItems}}</div>` : ''}}
179
+ `;
180
+ }}
181
+
182
+ function focusNode(nodeId) {{
183
+ network.focus(nodeId, {{ scale: 1.4, animation: true }});
184
+ network.selectNodes([nodeId]);
185
+ showInfo(nodeId);
186
+ }}
187
+
188
+ // Track hovered node — hover detection is more reliable than click params
189
+ let hoveredNodeId = null;
190
+ network.on('hoverNode', params => {{
191
+ hoveredNodeId = params.node;
192
+ container.style.cursor = 'pointer';
193
+ }});
194
+ network.on('blurNode', () => {{
195
+ hoveredNodeId = null;
196
+ container.style.cursor = 'default';
197
+ }});
198
+ container.addEventListener('click', () => {{
199
+ if (hoveredNodeId !== null) {{
200
+ showInfo(hoveredNodeId);
201
+ network.selectNodes([hoveredNodeId]);
202
+ }}
203
+ }});
204
+ network.on('click', params => {{
205
+ if (params.nodes.length > 0) {{
206
+ showInfo(params.nodes[0]);
207
+ }} else if (hoveredNodeId === null) {{
208
+ document.getElementById('info-content').innerHTML = '<span class="empty">Click a node to inspect it</span>';
209
+ }}
210
+ }});
211
+
212
+ const searchInput = document.getElementById('search');
213
+ const searchResults = document.getElementById('search-results');
214
+ searchInput.addEventListener('input', () => {{
215
+ const q = searchInput.value.toLowerCase().trim();
216
+ searchResults.innerHTML = '';
217
+ if (!q) {{ searchResults.style.display = 'none'; return; }}
218
+ const matches = RAW_NODES.filter(n => n.label.toLowerCase().includes(q)).slice(0, 20);
219
+ if (!matches.length) {{ searchResults.style.display = 'none'; return; }}
220
+ searchResults.style.display = 'block';
221
+ matches.forEach(n => {{
222
+ const el = document.createElement('div');
223
+ el.className = 'search-item';
224
+ el.textContent = n.label;
225
+ el.style.borderLeft = `3px solid ${{n.color.background}}`;
226
+ el.style.paddingLeft = '8px';
227
+ el.onclick = () => {{
228
+ network.focus(n.id, {{ scale: 1.5, animation: true }});
229
+ network.selectNodes([n.id]);
230
+ showInfo(n.id);
231
+ searchResults.style.display = 'none';
232
+ searchInput.value = '';
233
+ }};
234
+ searchResults.appendChild(el);
235
+ }});
236
+ }});
237
+ document.addEventListener('click', e => {{
238
+ if (!searchResults.contains(e.target) && e.target !== searchInput)
239
+ searchResults.style.display = 'none';
240
+ }});
241
+
242
+ const hiddenCommunities = new Set();
243
+ const legendEl = document.getElementById('legend');
244
+ LEGEND.forEach(c => {{
245
+ const item = document.createElement('div');
246
+ item.className = 'legend-item';
247
+ item.innerHTML = `<div class="legend-dot" style="background:${{c.color}}"></div>
248
+ <span class="legend-label">${{c.label}}</span>
249
+ <span class="legend-count">${{c.count}}</span>`;
250
+ item.onclick = () => {{
251
+ if (hiddenCommunities.has(c.cid)) {{
252
+ hiddenCommunities.delete(c.cid);
253
+ item.classList.remove('dimmed');
254
+ }} else {{
255
+ hiddenCommunities.add(c.cid);
256
+ item.classList.add('dimmed');
257
+ }}
258
+ const updates = RAW_NODES
259
+ .filter(n => n.community === c.cid)
260
+ .map(n => ({{ id: n.id, hidden: hiddenCommunities.has(c.cid) }}));
261
+ nodesDS.update(updates);
262
+ }};
263
+ legendEl.appendChild(item);
264
+ }});
265
+ </script>"""
266
+
267
+
268
+ _CONFIDENCE_SCORE_DEFAULTS = {"EXTRACTED": 1.0, "INFERRED": 0.5, "AMBIGUOUS": 0.2}
269
+
270
+
271
+ def attach_hyperedges(G: nx.Graph, hyperedges: list) -> None:
272
+ """Store hyperedges in the graph's metadata dict."""
273
+ existing = G.graph.get("hyperedges", [])
274
+ seen_ids = {h["id"] for h in existing}
275
+ for h in hyperedges:
276
+ if h.get("id") and h["id"] not in seen_ids:
277
+ existing.append(h)
278
+ seen_ids.add(h["id"])
279
+ G.graph["hyperedges"] = existing
280
+
281
+
282
+ def to_json(G: nx.Graph, communities: dict[int, list[str]], output_path: str) -> None:
283
+ node_community = _node_community_map(communities)
284
+ try:
285
+ data = json_graph.node_link_data(G, edges="links")
286
+ except TypeError:
287
+ data = json_graph.node_link_data(G)
288
+ for node in data["nodes"]:
289
+ node["community"] = node_community.get(node["id"])
290
+ node["norm_label"] = _strip_diacritics(node.get("label", "")).lower()
291
+ for link in data["links"]:
292
+ if "confidence_score" not in link:
293
+ conf = link.get("confidence", "EXTRACTED")
294
+ link["confidence_score"] = _CONFIDENCE_SCORE_DEFAULTS.get(conf, 1.0)
295
+ data["hyperedges"] = getattr(G, "graph", {}).get("hyperedges", [])
296
+ with open(output_path, "w", encoding="utf-8") as f:
297
+ json.dump(data, f, indent=2)
298
+
299
+
300
+ def prune_dangling_edges(graph_data: dict) -> tuple[dict, int]:
301
+ """Remove edges whose source or target node is not in the node set.
302
+
303
+ Returns the cleaned graph_data dict and the number of pruned edges.
304
+ """
305
+ node_ids = {n["id"] for n in graph_data["nodes"]}
306
+ links_key = "links" if "links" in graph_data else "edges"
307
+ before = len(graph_data[links_key])
308
+ graph_data[links_key] = [
309
+ e for e in graph_data[links_key]
310
+ if e["source"] in node_ids and e["target"] in node_ids
311
+ ]
312
+ return graph_data, before - len(graph_data[links_key])
313
+
314
+
315
+ def _cypher_escape(s: str) -> str:
316
+ """Escape a string for safe embedding in a Cypher single-quoted literal."""
317
+ return s.replace("\\", "\\\\").replace("'", "\\'")
318
+
319
+
320
+ def to_cypher(G: nx.Graph, output_path: str) -> None:
321
+ lines = ["// Neo4j Cypher import - generated by /graphify", ""]
322
+ for node_id, data in G.nodes(data=True):
323
+ label = _cypher_escape(data.get("label", node_id))
324
+ node_id_esc = _cypher_escape(node_id)
325
+ _ft = re.sub(r"[^A-Za-z0-9_]", "", data.get("file_type", "unknown").capitalize())
326
+ ftype = (_ft if _ft and _ft[0].isalpha() else "Entity")
327
+ lines.append(f"MERGE (n:{ftype} {{id: '{node_id_esc}', label: '{label}'}});")
328
+ lines.append("")
329
+ for u, v, data in G.edges(data=True):
330
+ rel = re.sub(r"[^A-Za-z0-9_]", "_", data.get("relation", "RELATES_TO").upper())
331
+ conf = _cypher_escape(data.get("confidence", "EXTRACTED"))
332
+ u_esc = _cypher_escape(u)
333
+ v_esc = _cypher_escape(v)
334
+ lines.append(
335
+ f"MATCH (a {{id: '{u_esc}'}}), (b {{id: '{v_esc}'}}) "
336
+ f"MERGE (a)-[:{rel} {{confidence: '{conf}'}}]->(b);"
337
+ )
338
+ with open(output_path, "w", encoding="utf-8") as f:
339
+ f.write("\n".join(lines))
340
+
341
+
342
+ def to_html(
343
+ G: nx.Graph,
344
+ communities: dict[int, list[str]],
345
+ output_path: str,
346
+ community_labels: dict[int, str] | None = None,
347
+ ) -> None:
348
+ """Generate an interactive vis.js HTML visualization of the graph.
349
+
350
+ Features: node size by degree, click-to-inspect panel, search box,
351
+ community filter, physics clustering by community, confidence-styled edges.
352
+ Raises ValueError if graph exceeds MAX_NODES_FOR_VIZ.
353
+ """
354
+ if G.number_of_nodes() > MAX_NODES_FOR_VIZ:
355
+ raise ValueError(
356
+ f"Graph has {G.number_of_nodes()} nodes - too large for HTML viz. "
357
+ f"Use --no-viz or reduce input size."
358
+ )
359
+
360
+ node_community = _node_community_map(communities)
361
+ degree = dict(G.degree())
362
+ max_deg = max(degree.values(), default=1) or 1
363
+
364
+ # Build nodes list for vis.js
365
+ vis_nodes = []
366
+ for node_id, data in G.nodes(data=True):
367
+ cid = node_community.get(node_id, 0)
368
+ color = COMMUNITY_COLORS[cid % len(COMMUNITY_COLORS)]
369
+ label = sanitize_label(data.get("label", node_id))
370
+ deg = degree.get(node_id, 1)
371
+ size = 10 + 30 * (deg / max_deg)
372
+ # Only show label for high-degree nodes by default; others show on hover
373
+ font_size = 12 if deg >= max_deg * 0.15 else 0
374
+ vis_nodes.append({
375
+ "id": node_id,
376
+ "label": label,
377
+ "color": {"background": color, "border": color, "highlight": {"background": "#ffffff", "border": color}},
378
+ "size": round(size, 1),
379
+ "font": {"size": font_size, "color": "#ffffff"},
380
+ "title": _html.escape(label),
381
+ "community": cid,
382
+ "community_name": sanitize_label((community_labels or {}).get(cid, f"Community {cid}")),
383
+ "source_file": sanitize_label(data.get("source_file", "")),
384
+ "file_type": data.get("file_type", ""),
385
+ "degree": deg,
386
+ })
387
+
388
+ # Build edges list
389
+ vis_edges = []
390
+ for u, v, data in G.edges(data=True):
391
+ confidence = data.get("confidence", "EXTRACTED")
392
+ relation = data.get("relation", "")
393
+ vis_edges.append({
394
+ "from": u,
395
+ "to": v,
396
+ "label": relation,
397
+ "title": _html.escape(f"{relation} [{confidence}]"),
398
+ "dashes": confidence != "EXTRACTED",
399
+ "width": 2 if confidence == "EXTRACTED" else 1,
400
+ "color": {"opacity": 0.7 if confidence == "EXTRACTED" else 0.35},
401
+ "confidence": confidence,
402
+ })
403
+
404
+ # Build community legend data
405
+ legend_data = []
406
+ for cid in sorted((community_labels or {}).keys()):
407
+ color = COMMUNITY_COLORS[cid % len(COMMUNITY_COLORS)]
408
+ lbl = _html.escape(sanitize_label((community_labels or {}).get(cid, f"Community {cid}")))
409
+ n = len(communities.get(cid, []))
410
+ legend_data.append({"cid": cid, "color": color, "label": lbl, "count": n})
411
+
412
+ # Escape </script> sequences so embedded JSON cannot break out of the script tag
413
+ def _js_safe(obj) -> str:
414
+ return json.dumps(obj).replace("</", "<\\/")
415
+
416
+ nodes_json = _js_safe(vis_nodes)
417
+ edges_json = _js_safe(vis_edges)
418
+ legend_json = _js_safe(legend_data)
419
+ hyperedges_json = _js_safe(getattr(G, "graph", {}).get("hyperedges", []))
420
+ title = _html.escape(sanitize_label(str(output_path)))
421
+ stats = f"{G.number_of_nodes()} nodes &middot; {G.number_of_edges()} edges &middot; {len(communities)} communities"
422
+
423
+ html = f"""<!DOCTYPE html>
424
+ <html lang="en">
425
+ <head>
426
+ <meta charset="UTF-8">
427
+ <title>graphify - {title}</title>
428
+ <script src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
429
+ {_html_styles()}
430
+ </head>
431
+ <body>
432
+ <div id="graph"></div>
433
+ <div id="sidebar">
434
+ <div id="search-wrap">
435
+ <input id="search" type="text" placeholder="Search nodes..." autocomplete="off">
436
+ <div id="search-results"></div>
437
+ </div>
438
+ <div id="info-panel">
439
+ <h3>Node Info</h3>
440
+ <div id="info-content"><span class="empty">Click a node to inspect it</span></div>
441
+ </div>
442
+ <div id="legend-wrap">
443
+ <h3>Communities</h3>
444
+ <div id="legend"></div>
445
+ </div>
446
+ <div id="stats">{stats}</div>
447
+ </div>
448
+ {_html_script(nodes_json, edges_json, legend_json)}
449
+ {_hyperedge_script(hyperedges_json)}
450
+ </body>
451
+ </html>"""
452
+
453
+ Path(output_path).write_text(html, encoding="utf-8")
454
+
455
+
456
+ # Keep backward-compatible alias - skill.md calls generate_html
457
+ generate_html = to_html
458
+
459
+
460
+ def to_obsidian(
461
+ G: nx.Graph,
462
+ communities: dict[int, list[str]],
463
+ output_dir: str,
464
+ community_labels: dict[int, str] | None = None,
465
+ cohesion: dict[int, float] | None = None,
466
+ ) -> int:
467
+ """Export graph as an Obsidian vault - one .md file per node with [[wikilinks]],
468
+ plus one _COMMUNITY_name.md overview note per community (sorted to top by underscore prefix).
469
+
470
+ Open the output directory as a vault in Obsidian to get an interactive
471
+ graph view with community colors and full-text search over node metadata.
472
+
473
+ Returns the number of node notes + community notes written.
474
+ """
475
+ out = Path(output_dir)
476
+ out.mkdir(parents=True, exist_ok=True)
477
+
478
+ node_community = _node_community_map(communities)
479
+
480
+ # Map node_id → safe filename so wikilinks stay consistent.
481
+ # Deduplicate: if two nodes produce the same filename, append a numeric suffix.
482
+ def safe_name(label: str) -> str:
483
+ cleaned = re.sub(r'[\\/*?:"<>|#^[\]]', "", label.replace("\r\n", " ").replace("\r", " ").replace("\n", " ")).strip()
484
+ # Strip trailing .md/.mdx/.markdown so "CLAUDE.md" doesn't become "CLAUDE.md.md"
485
+ cleaned = re.sub(r"\.(md|mdx|markdown)$", "", cleaned, flags=re.IGNORECASE)
486
+ return cleaned or "unnamed"
487
+
488
+ node_filename: dict[str, str] = {}
489
+ seen_names: dict[str, int] = {}
490
+ for node_id, data in G.nodes(data=True):
491
+ base = safe_name(data.get("label", node_id))
492
+ if base in seen_names:
493
+ seen_names[base] += 1
494
+ node_filename[node_id] = f"{base}_{seen_names[base]}"
495
+ else:
496
+ seen_names[base] = 0
497
+ node_filename[node_id] = base
498
+
499
+ # Helper: compute dominant confidence for a node across all its edges
500
+ def _dominant_confidence(node_id: str) -> str:
501
+ confs = []
502
+ for u, v, edata in G.edges(node_id, data=True):
503
+ confs.append(edata.get("confidence", "EXTRACTED"))
504
+ if not confs:
505
+ return "EXTRACTED"
506
+ return Counter(confs).most_common(1)[0][0]
507
+
508
+ # Map file_type → graphify tag
509
+ _FTYPE_TAG = {
510
+ "code": "graphify/code",
511
+ "document": "graphify/document",
512
+ "paper": "graphify/paper",
513
+ "image": "graphify/image",
514
+ }
515
+
516
+ # Write one .md file per node
517
+ for node_id, data in G.nodes(data=True):
518
+ label = data.get("label", node_id)
519
+ cid = node_community.get(node_id)
520
+ community_name = (
521
+ community_labels.get(cid, f"Community {cid}")
522
+ if community_labels and cid is not None
523
+ else f"Community {cid}"
524
+ )
525
+
526
+ # Build tags for this node
527
+ ftype = data.get("file_type", "")
528
+ ftype_tag = _FTYPE_TAG.get(ftype, f"graphify/{ftype}" if ftype else "graphify/document")
529
+ dom_conf = _dominant_confidence(node_id)
530
+ conf_tag = f"graphify/{dom_conf}"
531
+ comm_tag = f"community/{community_name.replace(' ', '_')}"
532
+ node_tags = [ftype_tag, conf_tag, comm_tag]
533
+
534
+ lines: list[str] = []
535
+
536
+ # YAML frontmatter - readable in Obsidian's properties panel
537
+ lines += [
538
+ "---",
539
+ f'source_file: "{data.get("source_file", "")}"',
540
+ f'type: "{ftype}"',
541
+ f'community: "{community_name}"',
542
+ ]
543
+ if data.get("source_location"):
544
+ lines.append(f'location: "{data["source_location"]}"')
545
+ # Add tags list to frontmatter
546
+ lines.append("tags:")
547
+ for tag in node_tags:
548
+ lines.append(f" - {tag}")
549
+ lines += ["---", "", f"# {label}", ""]
550
+
551
+ # Outgoing edges as wikilinks
552
+ neighbors = list(G.neighbors(node_id))
553
+ if neighbors:
554
+ lines.append("## Connections")
555
+ for neighbor in sorted(neighbors, key=lambda n: G.nodes[n].get("label", n)):
556
+ edge_data = G.edges[node_id, neighbor]
557
+ neighbor_label = node_filename[neighbor]
558
+ relation = edge_data.get("relation", "")
559
+ confidence = edge_data.get("confidence", "EXTRACTED")
560
+ lines.append(f"- [[{neighbor_label}]] - `{relation}` [{confidence}]")
561
+ lines.append("")
562
+
563
+ # Inline tags at bottom of note body (for Obsidian tag panel)
564
+ inline_tags = " ".join(f"#{t}" for t in node_tags)
565
+ lines.append(inline_tags)
566
+
567
+ fname = node_filename[node_id] + ".md"
568
+ (out / fname).write_text("\n".join(lines), encoding="utf-8")
569
+
570
+ # Write one _COMMUNITY_name.md overview note per community
571
+ # Build inter-community edge counts for "Connections to other communities"
572
+ inter_community_edges: dict[int, dict[int, int]] = {}
573
+ for cid in communities:
574
+ inter_community_edges[cid] = {}
575
+ for u, v in G.edges():
576
+ cu = node_community.get(u)
577
+ cv = node_community.get(v)
578
+ if cu is not None and cv is not None and cu != cv:
579
+ inter_community_edges.setdefault(cu, {})
580
+ inter_community_edges.setdefault(cv, {})
581
+ inter_community_edges[cu][cv] = inter_community_edges[cu].get(cv, 0) + 1
582
+ inter_community_edges[cv][cu] = inter_community_edges[cv].get(cu, 0) + 1
583
+
584
+ # Precompute per-node community reach (number of distinct communities a node connects to)
585
+ def _community_reach(node_id: str) -> int:
586
+ neighbor_cids = {
587
+ node_community[nb]
588
+ for nb in G.neighbors(node_id)
589
+ if nb in node_community and node_community[nb] != node_community.get(node_id)
590
+ }
591
+ return len(neighbor_cids)
592
+
593
+ community_notes_written = 0
594
+ for cid, members in communities.items():
595
+ community_name = (
596
+ community_labels.get(cid, f"Community {cid}")
597
+ if community_labels and cid is not None
598
+ else f"Community {cid}"
599
+ )
600
+ n_members = len(members)
601
+ coh_value = cohesion.get(cid) if cohesion else None
602
+
603
+ lines: list[str] = []
604
+
605
+ # YAML frontmatter
606
+ lines.append("---")
607
+ lines.append("type: community")
608
+ if coh_value is not None:
609
+ lines.append(f"cohesion: {coh_value:.2f}")
610
+ lines.append(f"members: {n_members}")
611
+ lines.append("---")
612
+ lines.append("")
613
+ lines.append(f"# {community_name}")
614
+ lines.append("")
615
+
616
+ # Cohesion + member count summary
617
+ if coh_value is not None:
618
+ cohesion_desc = (
619
+ "tightly connected" if coh_value >= 0.7
620
+ else "moderately connected" if coh_value >= 0.4
621
+ else "loosely connected"
622
+ )
623
+ lines.append(f"**Cohesion:** {coh_value:.2f} - {cohesion_desc}")
624
+ lines.append(f"**Members:** {n_members} nodes")
625
+ lines.append("")
626
+
627
+ # Members section
628
+ lines.append("## Members")
629
+ for node_id in sorted(members, key=lambda n: G.nodes[n].get("label", n)):
630
+ data = G.nodes[node_id]
631
+ node_label = node_filename[node_id]
632
+ ftype = data.get("file_type", "")
633
+ source = data.get("source_file", "")
634
+ entry = f"- [[{node_label}]]"
635
+ if ftype:
636
+ entry += f" - {ftype}"
637
+ if source:
638
+ entry += f" - {source}"
639
+ lines.append(entry)
640
+ lines.append("")
641
+
642
+ # Dataview live query (improvement 2)
643
+ comm_tag_name = community_name.replace(" ", "_")
644
+ lines.append("## Live Query (requires Dataview plugin)")
645
+ lines.append("")
646
+ lines.append("```dataview")
647
+ lines.append(f"TABLE source_file, type FROM #community/{comm_tag_name}")
648
+ lines.append("SORT file.name ASC")
649
+ lines.append("```")
650
+ lines.append("")
651
+
652
+ # Connections to other communities
653
+ cross = inter_community_edges.get(cid, {})
654
+ if cross:
655
+ lines.append("## Connections to other communities")
656
+ for other_cid, edge_count in sorted(cross.items(), key=lambda x: -x[1]):
657
+ other_name = (
658
+ community_labels.get(other_cid, f"Community {other_cid}")
659
+ if community_labels and other_cid is not None
660
+ else f"Community {other_cid}"
661
+ )
662
+ other_safe = safe_name(other_name)
663
+ lines.append(f"- {edge_count} edge{'s' if edge_count != 1 else ''} to [[_COMMUNITY_{other_safe}]]")
664
+ lines.append("")
665
+
666
+ # Top bridge nodes - highest degree nodes that connect to other communities
667
+ bridge_nodes = [
668
+ (node_id, G.degree(node_id), _community_reach(node_id))
669
+ for node_id in members
670
+ if _community_reach(node_id) > 0
671
+ ]
672
+ bridge_nodes.sort(key=lambda x: (-x[2], -x[1]))
673
+ top_bridges = bridge_nodes[:5]
674
+ if top_bridges:
675
+ lines.append("## Top bridge nodes")
676
+ for node_id, degree, reach in top_bridges:
677
+ node_label = node_filename[node_id]
678
+ lines.append(
679
+ f"- [[{node_label}]] - degree {degree}, connects to {reach} "
680
+ f"{'community' if reach == 1 else 'communities'}"
681
+ )
682
+
683
+ community_safe = safe_name(community_name)
684
+ fname = f"_COMMUNITY_{community_safe}.md"
685
+ (out / fname).write_text("\n".join(lines), encoding="utf-8")
686
+ community_notes_written += 1
687
+
688
+ # Improvement 4: write .obsidian/graph.json to color nodes by community in graph view
689
+ obsidian_dir = out / ".obsidian"
690
+ obsidian_dir.mkdir(exist_ok=True)
691
+ graph_config = {
692
+ "colorGroups": [
693
+ {
694
+ "query": f"tag:#community/{label.replace(' ', '_')}",
695
+ "color": {"a": 1, "rgb": int(COMMUNITY_COLORS[cid % len(COMMUNITY_COLORS)].lstrip('#'), 16)}
696
+ }
697
+ for cid, label in sorted((community_labels or {}).items())
698
+ ]
699
+ }
700
+ (obsidian_dir / "graph.json").write_text(json.dumps(graph_config, indent=2), encoding="utf-8")
701
+
702
+ return G.number_of_nodes() + community_notes_written
703
+
704
+
705
+ def to_canvas(
706
+ G: nx.Graph,
707
+ communities: dict[int, list[str]],
708
+ output_path: str,
709
+ community_labels: dict[int, str] | None = None,
710
+ node_filenames: dict[str, str] | None = None,
711
+ ) -> None:
712
+ """Export graph as an Obsidian Canvas file - communities as groups, nodes as cards.
713
+
714
+ Generates a structured layout: communities arranged in a grid, nodes within
715
+ each community arranged in rows. Edges shown between connected nodes.
716
+ Opens in Obsidian as an infinite canvas with community groupings visible.
717
+ """
718
+ # Obsidian canvas color codes (cycle through for communities)
719
+ CANVAS_COLORS = ["1", "2", "3", "4", "5", "6"] # red, orange, yellow, green, cyan, purple
720
+
721
+ def safe_name(label: str) -> str:
722
+ cleaned = re.sub(r'[\\/*?:"<>|#^[\]]', "", label.replace("\r\n", " ").replace("\r", " ").replace("\n", " ")).strip()
723
+ cleaned = re.sub(r"\.(md|mdx|markdown)$", "", cleaned, flags=re.IGNORECASE)
724
+ return cleaned or "unnamed"
725
+
726
+ # Build node_filenames if not provided (same dedup logic as to_obsidian)
727
+ if node_filenames is None:
728
+ node_filenames = {}
729
+ seen_names: dict[str, int] = {}
730
+ for node_id, data in G.nodes(data=True):
731
+ base = safe_name(data.get("label", node_id))
732
+ if base in seen_names:
733
+ seen_names[base] += 1
734
+ node_filenames[node_id] = f"{base}_{seen_names[base]}"
735
+ else:
736
+ seen_names[base] = 0
737
+ node_filenames[node_id] = base
738
+
739
+ num_communities = len(communities)
740
+ cols = math.ceil(math.sqrt(num_communities)) if num_communities > 0 else 1
741
+ rows = math.ceil(num_communities / cols) if num_communities > 0 else 1
742
+
743
+ canvas_nodes: list[dict] = []
744
+ canvas_edges: list[dict] = []
745
+
746
+ # Lay out communities in a grid
747
+ gap = 80
748
+ group_x_offsets: list[int] = []
749
+ group_y_offsets: list[int] = []
750
+
751
+ # Precompute group sizes so we can calculate offsets
752
+ sorted_cids = sorted(communities.keys())
753
+ group_sizes: dict[int, tuple[int, int]] = {}
754
+ for cid in sorted_cids:
755
+ members = communities[cid]
756
+ n = len(members)
757
+ w = max(600, 220 * math.ceil(math.sqrt(n)) if n > 0 else 600)
758
+ h = max(400, 100 * math.ceil(n / 3) + 120 if n > 0 else 400)
759
+ group_sizes[cid] = (w, h)
760
+
761
+ # Compute cumulative row heights and col widths for grid placement
762
+ # Each grid cell uses the max width/height in its col/row
763
+ col_widths: list[int] = []
764
+ row_heights: list[int] = []
765
+ for col_idx in range(cols):
766
+ max_w = 0
767
+ for row_idx in range(rows):
768
+ linear = row_idx * cols + col_idx
769
+ if linear < len(sorted_cids):
770
+ cid = sorted_cids[linear]
771
+ w, _ = group_sizes[cid]
772
+ max_w = max(max_w, w)
773
+ col_widths.append(max_w)
774
+
775
+ for row_idx in range(rows):
776
+ max_h = 0
777
+ for col_idx in range(cols):
778
+ linear = row_idx * cols + col_idx
779
+ if linear < len(sorted_cids):
780
+ cid = sorted_cids[linear]
781
+ _, h = group_sizes[cid]
782
+ max_h = max(max_h, h)
783
+ row_heights.append(max_h)
784
+
785
+ # Map from cid → (group_x, group_y, group_w, group_h)
786
+ group_layout: dict[int, tuple[int, int, int, int]] = {}
787
+ for idx, cid in enumerate(sorted_cids):
788
+ col_idx = idx % cols
789
+ row_idx = idx // cols
790
+ gx = sum(col_widths[:col_idx]) + col_idx * gap
791
+ gy = sum(row_heights[:row_idx]) + row_idx * gap
792
+ gw, gh = group_sizes[cid]
793
+ group_layout[cid] = (gx, gy, gw, gh)
794
+
795
+ # Build set of all node_ids in canvas for edge filtering
796
+ all_canvas_nodes: set[str] = set()
797
+ for members in communities.values():
798
+ all_canvas_nodes.update(members)
799
+
800
+ # Generate group and node canvas entries
801
+ for idx, cid in enumerate(sorted_cids):
802
+ members = communities[cid]
803
+ community_name = (
804
+ community_labels.get(cid, f"Community {cid}")
805
+ if community_labels and cid is not None
806
+ else f"Community {cid}"
807
+ )
808
+ gx, gy, gw, gh = group_layout[cid]
809
+ canvas_color = CANVAS_COLORS[idx % len(CANVAS_COLORS)]
810
+
811
+ # Group node
812
+ canvas_nodes.append({
813
+ "id": f"g{cid}",
814
+ "type": "group",
815
+ "label": community_name,
816
+ "x": gx,
817
+ "y": gy,
818
+ "width": gw,
819
+ "height": gh,
820
+ "color": canvas_color,
821
+ })
822
+
823
+ # Node cards inside the group - rows of 3
824
+ sorted_members = sorted(members, key=lambda n: G.nodes[n].get("label", n))
825
+ for m_idx, node_id in enumerate(sorted_members):
826
+ col = m_idx % 3
827
+ row = m_idx // 3
828
+ nx_x = gx + 20 + col * (180 + 20)
829
+ nx_y = gy + 80 + row * (60 + 20)
830
+ fname = node_filenames.get(node_id, safe_name(G.nodes[node_id].get("label", node_id)))
831
+ canvas_nodes.append({
832
+ "id": f"n_{node_id}",
833
+ "type": "file",
834
+ "file": f"graphify/obsidian/{fname}.md",
835
+ "x": nx_x,
836
+ "y": nx_y,
837
+ "width": 180,
838
+ "height": 60,
839
+ })
840
+
841
+ # Generate edges - only between nodes both in canvas, cap at 200 highest-weight
842
+ all_edges_weighted: list[tuple[float, str, str, str]] = []
843
+ for u, v, edata in G.edges(data=True):
844
+ if u in all_canvas_nodes and v in all_canvas_nodes:
845
+ weight = edata.get("weight", 1.0)
846
+ relation = edata.get("relation", "")
847
+ conf = edata.get("confidence", "EXTRACTED")
848
+ label = f"{relation} [{conf}]" if relation else f"[{conf}]"
849
+ all_edges_weighted.append((weight, u, v, label))
850
+
851
+ all_edges_weighted.sort(key=lambda x: -x[0])
852
+ for weight, u, v, label in all_edges_weighted[:200]:
853
+ canvas_edges.append({
854
+ "id": f"e_{u}_{v}",
855
+ "fromNode": f"n_{u}",
856
+ "toNode": f"n_{v}",
857
+ "label": label,
858
+ })
859
+
860
+ canvas_data = {"nodes": canvas_nodes, "edges": canvas_edges}
861
+ Path(output_path).write_text(json.dumps(canvas_data, indent=2), encoding="utf-8")
862
+
863
+
864
+ def push_to_neo4j(
865
+ G: nx.Graph,
866
+ uri: str,
867
+ user: str,
868
+ password: str,
869
+ communities: dict[int, list[str]] | None = None,
870
+ ) -> dict[str, int]:
871
+ """Push graph directly to a running Neo4j instance via the Python driver.
872
+
873
+ Requires: pip install neo4j
874
+
875
+ Uses MERGE so re-running is safe - nodes and edges are upserted, not duplicated.
876
+ Returns a dict with counts of nodes and edges pushed.
877
+ """
878
+ try:
879
+ from neo4j import GraphDatabase
880
+ except ImportError as e:
881
+ raise ImportError(
882
+ "neo4j driver not installed. Run: pip install neo4j"
883
+ ) from e
884
+
885
+ node_community = _node_community_map(communities) if communities else {}
886
+
887
+ def _safe_rel(relation: str) -> str:
888
+ return re.sub(r"[^A-Z0-9_]", "_", relation.upper().replace(" ", "_").replace("-", "_")) or "RELATED_TO"
889
+
890
+ def _safe_label(label: str) -> str:
891
+ """Sanitize a Neo4j node label to prevent Cypher injection."""
892
+ sanitized = re.sub(r"[^A-Za-z0-9_]", "", label)
893
+ return sanitized if sanitized else "Entity"
894
+
895
+ driver = GraphDatabase.driver(uri, auth=(user, password))
896
+ nodes_pushed = 0
897
+ edges_pushed = 0
898
+
899
+ with driver.session() as session:
900
+ for node_id, data in G.nodes(data=True):
901
+ props = {k: v for k, v in data.items() if isinstance(v, (str, int, float, bool))}
902
+ props["id"] = node_id
903
+ cid = node_community.get(node_id)
904
+ if cid is not None:
905
+ props["community"] = cid
906
+ ftype = _safe_label(data.get("file_type", "Entity").capitalize())
907
+ session.run(
908
+ f"MERGE (n:{ftype} {{id: $id}}) SET n += $props",
909
+ id=node_id,
910
+ props=props,
911
+ )
912
+ nodes_pushed += 1
913
+
914
+ for u, v, data in G.edges(data=True):
915
+ rel = _safe_rel(data.get("relation", "RELATED_TO"))
916
+ props = {k: v for k, v in data.items() if isinstance(v, (str, int, float, bool))}
917
+ session.run(
918
+ f"MATCH (a {{id: $src}}), (b {{id: $tgt}}) "
919
+ f"MERGE (a)-[r:{rel}]->(b) SET r += $props",
920
+ src=u,
921
+ tgt=v,
922
+ props=props,
923
+ )
924
+ edges_pushed += 1
925
+
926
+ driver.close()
927
+ return {"nodes": nodes_pushed, "edges": edges_pushed}
928
+
929
+
930
+ def to_graphml(
931
+ G: nx.Graph,
932
+ communities: dict[int, list[str]],
933
+ output_path: str,
934
+ ) -> None:
935
+ """Export graph as GraphML - opens in Gephi, yEd, and any GraphML-compatible tool.
936
+
937
+ Community IDs are written as a node attribute so Gephi can colour by community.
938
+ Edge confidence (EXTRACTED/INFERRED/AMBIGUOUS) is preserved as an edge attribute.
939
+ """
940
+ H = G.copy()
941
+ node_community = _node_community_map(communities)
942
+ for node_id in H.nodes():
943
+ H.nodes[node_id]["community"] = node_community.get(node_id, -1)
944
+ nx.write_graphml(H, output_path)
945
+
946
+
947
+ def to_svg(
948
+ G: nx.Graph,
949
+ communities: dict[int, list[str]],
950
+ output_path: str,
951
+ community_labels: dict[int, str] | None = None,
952
+ figsize: tuple[int, int] = (20, 14),
953
+ ) -> None:
954
+ """Export graph as an SVG file using matplotlib + spring layout.
955
+
956
+ Lightweight and embeddable - works in Obsidian notes, Notion, GitHub READMEs,
957
+ and any markdown renderer. No JavaScript required.
958
+
959
+ Node size scales with degree. Community colors match the HTML output.
960
+ """
961
+ try:
962
+ import matplotlib
963
+ matplotlib.use("Agg")
964
+ import matplotlib.pyplot as plt
965
+ import matplotlib.patches as mpatches
966
+ except ImportError as e:
967
+ raise ImportError("matplotlib not installed. Run: pip install matplotlib") from e
968
+
969
+ node_community = _node_community_map(communities)
970
+
971
+ fig, ax = plt.subplots(figsize=figsize, facecolor="#1a1a2e")
972
+ ax.set_facecolor("#1a1a2e")
973
+ ax.axis("off")
974
+
975
+ pos = nx.spring_layout(G, seed=42, k=2.0 / (G.number_of_nodes() ** 0.5 + 1))
976
+
977
+ degree = dict(G.degree())
978
+ max_deg = max(degree.values(), default=1) or 1
979
+
980
+ node_colors = [COMMUNITY_COLORS[node_community.get(n, 0) % len(COMMUNITY_COLORS)] for n in G.nodes()]
981
+ node_sizes = [300 + 1200 * (degree.get(n, 1) / max_deg) for n in G.nodes()]
982
+
983
+ # Draw edges - dashed for non-EXTRACTED
984
+ for u, v, data in G.edges(data=True):
985
+ conf = data.get("confidence", "EXTRACTED")
986
+ style = "solid" if conf == "EXTRACTED" else "dashed"
987
+ alpha = 0.6 if conf == "EXTRACTED" else 0.3
988
+ x0, y0 = pos[u]
989
+ x1, y1 = pos[v]
990
+ ax.plot([x0, x1], [y0, y1], color="#aaaaaa", linewidth=0.8,
991
+ linestyle=style, alpha=alpha, zorder=1)
992
+
993
+ nx.draw_networkx_nodes(G, pos, ax=ax, node_color=node_colors,
994
+ node_size=node_sizes, alpha=0.9)
995
+ nx.draw_networkx_labels(G, pos, ax=ax,
996
+ labels={n: G.nodes[n].get("label", n) for n in G.nodes()},
997
+ font_size=7, font_color="white")
998
+
999
+ # Legend
1000
+ if community_labels:
1001
+ patches = [
1002
+ mpatches.Patch(
1003
+ color=COMMUNITY_COLORS[cid % len(COMMUNITY_COLORS)],
1004
+ label=f"{label} ({len(communities.get(cid, []))})",
1005
+ )
1006
+ for cid, label in sorted(community_labels.items())
1007
+ ]
1008
+ ax.legend(handles=patches, loc="upper left", framealpha=0.7,
1009
+ facecolor="#2a2a4e", labelcolor="white", fontsize=8)
1010
+
1011
+ plt.tight_layout()
1012
+ plt.savefig(output_path, format="svg", bbox_inches="tight",
1013
+ facecolor=fig.get_facecolor())
1014
+ plt.close(fig)