okstra 0.130.4 → 0.131.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 (365) hide show
  1. package/README.md +0 -1
  2. package/docs/architecture.md +2 -2
  3. package/docs/cli.md +1 -1
  4. package/docs/for-ai/README.md +0 -2
  5. package/docs/for-ai/skills/okstra-run.md +13 -2
  6. package/docs/for-ai/skills/okstra-setup.md +4 -1
  7. package/docs/project-structure-overview.md +5 -4
  8. package/docs/task-process/implementation-planning.md +13 -0
  9. package/docs/task-process/implementation.md +17 -2
  10. package/package.json +1 -1
  11. package/runtime/BUILD.json +2 -2
  12. package/runtime/agents/workers/report-writer-worker.md +7 -0
  13. package/runtime/bin/lib/okstra/usage.sh +4 -4
  14. package/runtime/prompts/lead/okstra-lead-contract.md +2 -2
  15. package/runtime/prompts/lead/plan-body-verification.md +26 -5
  16. package/runtime/prompts/lead/report-writer.md +6 -2
  17. package/runtime/prompts/profiles/_common-contract.md +2 -1
  18. package/runtime/prompts/profiles/_implementation-deliverable.md +6 -1
  19. package/runtime/prompts/profiles/_implementation-executor.md +2 -2
  20. package/runtime/prompts/profiles/_implementation-verifier.md +33 -10
  21. package/runtime/prompts/profiles/final-verification.md +21 -6
  22. package/runtime/prompts/profiles/implementation-planning.md +16 -4
  23. package/runtime/python/okstra_ctl/codex_dispatch.py +31 -0
  24. package/runtime/python/okstra_ctl/conformance.py +49 -11
  25. package/runtime/python/okstra_ctl/report_finalize.py +52 -1
  26. package/runtime/python/okstra_ctl/run.py +15 -3
  27. package/runtime/python/okstra_ctl/worker_prompt_contract.py +14 -6
  28. package/runtime/python/okstra_ctl/worker_prompt_policy.py +19 -1
  29. package/runtime/python/okstra_vendor/__init__.py +0 -44
  30. package/runtime/schemas/final-report-v1.0.schema.json +99 -5
  31. package/runtime/skills/okstra-run/SKILL.md +11 -4
  32. package/runtime/skills/okstra-setup/SKILL.md +3 -2
  33. package/runtime/skills/okstra-setup/references/project-config.md +16 -7
  34. package/runtime/templates/reports/final-report.template.md +15 -9
  35. package/runtime/templates/reports/i18n/en.json +1 -0
  36. package/runtime/templates/reports/i18n/ko.json +1 -0
  37. package/runtime/validators/lib/fixtures.sh +6 -0
  38. package/runtime/validators/validate-run.py +1722 -98
  39. package/src/cli-registry.mjs +0 -7
  40. package/src/commands/lifecycle/doctor.mjs +0 -9
  41. package/src/lib/skill-catalog.mjs +0 -1
  42. package/docs/for-ai/skills/okstra-graphify.md +0 -64
  43. package/runtime/python/okstra_ctl/graphify_cmd.py +0 -225
  44. package/runtime/python/okstra_vendor/graphify/.vendored-version +0 -1
  45. package/runtime/python/okstra_vendor/graphify/__init__.py +0 -28
  46. package/runtime/python/okstra_vendor/graphify/__main__.py +0 -1371
  47. package/runtime/python/okstra_vendor/graphify/analyze.py +0 -540
  48. package/runtime/python/okstra_vendor/graphify/benchmark.py +0 -129
  49. package/runtime/python/okstra_vendor/graphify/build.py +0 -107
  50. package/runtime/python/okstra_vendor/graphify/cache.py +0 -169
  51. package/runtime/python/okstra_vendor/graphify/cluster.py +0 -137
  52. package/runtime/python/okstra_vendor/graphify/detect.py +0 -510
  53. package/runtime/python/okstra_vendor/graphify/export.py +0 -1014
  54. package/runtime/python/okstra_vendor/graphify/extract.py +0 -3277
  55. package/runtime/python/okstra_vendor/graphify/hooks.py +0 -220
  56. package/runtime/python/okstra_vendor/graphify/ingest.py +0 -297
  57. package/runtime/python/okstra_vendor/graphify/manifest.py +0 -4
  58. package/runtime/python/okstra_vendor/graphify/report.py +0 -175
  59. package/runtime/python/okstra_vendor/graphify/security.py +0 -203
  60. package/runtime/python/okstra_vendor/graphify/serve.py +0 -373
  61. package/runtime/python/okstra_vendor/graphify/skill-aider.md +0 -1184
  62. package/runtime/python/okstra_vendor/graphify/skill-claw.md +0 -1184
  63. package/runtime/python/okstra_vendor/graphify/skill-codex.md +0 -1242
  64. package/runtime/python/okstra_vendor/graphify/skill-copilot.md +0 -1268
  65. package/runtime/python/okstra_vendor/graphify/skill-droid.md +0 -1239
  66. package/runtime/python/okstra_vendor/graphify/skill-kiro.md +0 -1183
  67. package/runtime/python/okstra_vendor/graphify/skill-opencode.md +0 -1238
  68. package/runtime/python/okstra_vendor/graphify/skill-trae.md +0 -1208
  69. package/runtime/python/okstra_vendor/graphify/skill-vscode.md +0 -253
  70. package/runtime/python/okstra_vendor/graphify/skill-windows.md +0 -1245
  71. package/runtime/python/okstra_vendor/graphify/skill.md +0 -1319
  72. package/runtime/python/okstra_vendor/graphify/transcribe.py +0 -182
  73. package/runtime/python/okstra_vendor/graphify/validate.py +0 -72
  74. package/runtime/python/okstra_vendor/graphify/watch.py +0 -188
  75. package/runtime/python/okstra_vendor/graphify/wiki.py +0 -214
  76. package/runtime/python/okstra_vendor/networkx/__init__.py +0 -62
  77. package/runtime/python/okstra_vendor/networkx/algorithms/__init__.py +0 -134
  78. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/__init__.py +0 -26
  79. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clique.py +0 -259
  80. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clustering_coefficient.py +0 -71
  81. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/connectivity.py +0 -412
  82. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/density.py +0 -396
  83. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/distance_measures.py +0 -150
  84. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/dominating_set.py +0 -149
  85. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/kcomponents.py +0 -369
  86. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/matching.py +0 -44
  87. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/maxcut.py +0 -143
  88. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/ramsey.py +0 -53
  89. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/steinertree.py +0 -265
  90. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/traveling_salesman.py +0 -1508
  91. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/treewidth.py +0 -255
  92. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/vertex_cover.py +0 -83
  93. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/__init__.py +0 -5
  94. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/connectivity.py +0 -122
  95. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/correlation.py +0 -302
  96. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/mixing.py +0 -255
  97. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/neighbor_degree.py +0 -160
  98. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/pairs.py +0 -127
  99. package/runtime/python/okstra_vendor/networkx/algorithms/asteroidal.py +0 -164
  100. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/__init__.py +0 -88
  101. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/basic.py +0 -322
  102. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/centrality.py +0 -290
  103. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/cluster.py +0 -289
  104. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/covering.py +0 -57
  105. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/edgelist.py +0 -360
  106. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/extendability.py +0 -105
  107. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/generators.py +0 -603
  108. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/link_analysis.py +0 -316
  109. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matching.py +0 -590
  110. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matrix.py +0 -232
  111. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/projection.py +0 -526
  112. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/redundancy.py +0 -112
  113. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/spectral.py +0 -69
  114. package/runtime/python/okstra_vendor/networkx/algorithms/boundary.py +0 -168
  115. package/runtime/python/okstra_vendor/networkx/algorithms/bridges.py +0 -205
  116. package/runtime/python/okstra_vendor/networkx/algorithms/broadcasting.py +0 -164
  117. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/__init__.py +0 -20
  118. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness.py +0 -591
  119. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness_subset.py +0 -236
  120. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/closeness.py +0 -282
  121. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness.py +0 -364
  122. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness_subset.py +0 -227
  123. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_closeness.py +0 -96
  124. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/degree_alg.py +0 -150
  125. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/dispersion.py +0 -107
  126. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/eigenvector.py +0 -357
  127. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/flow_matrix.py +0 -130
  128. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/group.py +0 -787
  129. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/harmonic.py +0 -88
  130. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/katz.py +0 -331
  131. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/laplacian.py +0 -150
  132. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/load.py +0 -200
  133. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/percolation.py +0 -128
  134. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/reaching.py +0 -209
  135. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/second_order.py +0 -141
  136. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/subgraph_alg.py +0 -361
  137. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/trophic.py +0 -181
  138. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/voterank_alg.py +0 -95
  139. package/runtime/python/okstra_vendor/networkx/algorithms/chains.py +0 -172
  140. package/runtime/python/okstra_vendor/networkx/algorithms/chordal.py +0 -443
  141. package/runtime/python/okstra_vendor/networkx/algorithms/clique.py +0 -818
  142. package/runtime/python/okstra_vendor/networkx/algorithms/cluster.py +0 -732
  143. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/__init__.py +0 -4
  144. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/equitable_coloring.py +0 -505
  145. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/greedy_coloring.py +0 -565
  146. package/runtime/python/okstra_vendor/networkx/algorithms/communicability_alg.py +0 -163
  147. package/runtime/python/okstra_vendor/networkx/algorithms/community/__init__.py +0 -28
  148. package/runtime/python/okstra_vendor/networkx/algorithms/community/asyn_fluid.py +0 -153
  149. package/runtime/python/okstra_vendor/networkx/algorithms/community/bipartitions.py +0 -354
  150. package/runtime/python/okstra_vendor/networkx/algorithms/community/centrality.py +0 -171
  151. package/runtime/python/okstra_vendor/networkx/algorithms/community/community_utils.py +0 -30
  152. package/runtime/python/okstra_vendor/networkx/algorithms/community/divisive.py +0 -216
  153. package/runtime/python/okstra_vendor/networkx/algorithms/community/kclique.py +0 -79
  154. package/runtime/python/okstra_vendor/networkx/algorithms/community/label_propagation.py +0 -338
  155. package/runtime/python/okstra_vendor/networkx/algorithms/community/leiden.py +0 -162
  156. package/runtime/python/okstra_vendor/networkx/algorithms/community/local.py +0 -220
  157. package/runtime/python/okstra_vendor/networkx/algorithms/community/louvain.py +0 -384
  158. package/runtime/python/okstra_vendor/networkx/algorithms/community/lukes.py +0 -227
  159. package/runtime/python/okstra_vendor/networkx/algorithms/community/modularity_max.py +0 -452
  160. package/runtime/python/okstra_vendor/networkx/algorithms/community/quality.py +0 -347
  161. package/runtime/python/okstra_vendor/networkx/algorithms/components/__init__.py +0 -6
  162. package/runtime/python/okstra_vendor/networkx/algorithms/components/attracting.py +0 -115
  163. package/runtime/python/okstra_vendor/networkx/algorithms/components/biconnected.py +0 -394
  164. package/runtime/python/okstra_vendor/networkx/algorithms/components/connected.py +0 -282
  165. package/runtime/python/okstra_vendor/networkx/algorithms/components/semiconnected.py +0 -71
  166. package/runtime/python/okstra_vendor/networkx/algorithms/components/strongly_connected.py +0 -359
  167. package/runtime/python/okstra_vendor/networkx/algorithms/components/weakly_connected.py +0 -196
  168. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/__init__.py +0 -11
  169. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/connectivity.py +0 -811
  170. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/cuts.py +0 -616
  171. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/disjoint_paths.py +0 -408
  172. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_augmentation.py +0 -1270
  173. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_kcomponents.py +0 -592
  174. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcomponents.py +0 -220
  175. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcutsets.py +0 -235
  176. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/stoerwagner.py +0 -152
  177. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/utils.py +0 -88
  178. package/runtime/python/okstra_vendor/networkx/algorithms/core.py +0 -588
  179. package/runtime/python/okstra_vendor/networkx/algorithms/covering.py +0 -142
  180. package/runtime/python/okstra_vendor/networkx/algorithms/cuts.py +0 -416
  181. package/runtime/python/okstra_vendor/networkx/algorithms/cycles.py +0 -1234
  182. package/runtime/python/okstra_vendor/networkx/algorithms/d_separation.py +0 -677
  183. package/runtime/python/okstra_vendor/networkx/algorithms/dag.py +0 -1392
  184. package/runtime/python/okstra_vendor/networkx/algorithms/distance_measures.py +0 -1095
  185. package/runtime/python/okstra_vendor/networkx/algorithms/distance_regular.py +0 -272
  186. package/runtime/python/okstra_vendor/networkx/algorithms/dominance.py +0 -142
  187. package/runtime/python/okstra_vendor/networkx/algorithms/dominating.py +0 -268
  188. package/runtime/python/okstra_vendor/networkx/algorithms/efficiency_measures.py +0 -167
  189. package/runtime/python/okstra_vendor/networkx/algorithms/euler.py +0 -470
  190. package/runtime/python/okstra_vendor/networkx/algorithms/flow/__init__.py +0 -11
  191. package/runtime/python/okstra_vendor/networkx/algorithms/flow/boykovkolmogorov.py +0 -370
  192. package/runtime/python/okstra_vendor/networkx/algorithms/flow/capacityscaling.py +0 -407
  193. package/runtime/python/okstra_vendor/networkx/algorithms/flow/dinitz_alg.py +0 -238
  194. package/runtime/python/okstra_vendor/networkx/algorithms/flow/edmondskarp.py +0 -241
  195. package/runtime/python/okstra_vendor/networkx/algorithms/flow/gomory_hu.py +0 -178
  196. package/runtime/python/okstra_vendor/networkx/algorithms/flow/maxflow.py +0 -611
  197. package/runtime/python/okstra_vendor/networkx/algorithms/flow/mincost.py +0 -356
  198. package/runtime/python/okstra_vendor/networkx/algorithms/flow/networksimplex.py +0 -662
  199. package/runtime/python/okstra_vendor/networkx/algorithms/flow/preflowpush.py +0 -425
  200. package/runtime/python/okstra_vendor/networkx/algorithms/flow/shortestaugmentingpath.py +0 -300
  201. package/runtime/python/okstra_vendor/networkx/algorithms/flow/utils.py +0 -194
  202. package/runtime/python/okstra_vendor/networkx/algorithms/graph_hashing.py +0 -435
  203. package/runtime/python/okstra_vendor/networkx/algorithms/graphical.py +0 -483
  204. package/runtime/python/okstra_vendor/networkx/algorithms/hierarchy.py +0 -57
  205. package/runtime/python/okstra_vendor/networkx/algorithms/hybrid.py +0 -196
  206. package/runtime/python/okstra_vendor/networkx/algorithms/isolate.py +0 -107
  207. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/__init__.py +0 -7
  208. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/ismags.py +0 -1306
  209. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorph.py +0 -336
  210. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorphvf2.py +0 -1262
  211. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/matchhelpers.py +0 -352
  212. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/temporalisomorphvf2.py +0 -308
  213. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tree_isomorphism.py +0 -264
  214. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2pp.py +0 -1102
  215. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2userfunc.py +0 -192
  216. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/__init__.py +0 -2
  217. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/hits_alg.py +0 -337
  218. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/pagerank_alg.py +0 -498
  219. package/runtime/python/okstra_vendor/networkx/algorithms/link_prediction.py +0 -687
  220. package/runtime/python/okstra_vendor/networkx/algorithms/lowest_common_ancestors.py +0 -280
  221. package/runtime/python/okstra_vendor/networkx/algorithms/matching.py +0 -1148
  222. package/runtime/python/okstra_vendor/networkx/algorithms/minors/__init__.py +0 -27
  223. package/runtime/python/okstra_vendor/networkx/algorithms/minors/contraction.py +0 -738
  224. package/runtime/python/okstra_vendor/networkx/algorithms/mis.py +0 -78
  225. package/runtime/python/okstra_vendor/networkx/algorithms/moral.py +0 -59
  226. package/runtime/python/okstra_vendor/networkx/algorithms/node_classification.py +0 -219
  227. package/runtime/python/okstra_vendor/networkx/algorithms/non_randomness.py +0 -155
  228. package/runtime/python/okstra_vendor/networkx/algorithms/operators/__init__.py +0 -4
  229. package/runtime/python/okstra_vendor/networkx/algorithms/operators/all.py +0 -324
  230. package/runtime/python/okstra_vendor/networkx/algorithms/operators/binary.py +0 -468
  231. package/runtime/python/okstra_vendor/networkx/algorithms/operators/product.py +0 -633
  232. package/runtime/python/okstra_vendor/networkx/algorithms/operators/unary.py +0 -77
  233. package/runtime/python/okstra_vendor/networkx/algorithms/perfect_graph.py +0 -73
  234. package/runtime/python/okstra_vendor/networkx/algorithms/planar_drawing.py +0 -464
  235. package/runtime/python/okstra_vendor/networkx/algorithms/planarity.py +0 -1463
  236. package/runtime/python/okstra_vendor/networkx/algorithms/polynomials.py +0 -306
  237. package/runtime/python/okstra_vendor/networkx/algorithms/reciprocity.py +0 -98
  238. package/runtime/python/okstra_vendor/networkx/algorithms/regular.py +0 -167
  239. package/runtime/python/okstra_vendor/networkx/algorithms/richclub.py +0 -138
  240. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/__init__.py +0 -5
  241. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/astar.py +0 -239
  242. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/dense.py +0 -264
  243. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/generic.py +0 -716
  244. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/unweighted.py +0 -625
  245. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/weighted.py +0 -2542
  246. package/runtime/python/okstra_vendor/networkx/algorithms/similarity.py +0 -2107
  247. package/runtime/python/okstra_vendor/networkx/algorithms/simple_paths.py +0 -966
  248. package/runtime/python/okstra_vendor/networkx/algorithms/smallworld.py +0 -404
  249. package/runtime/python/okstra_vendor/networkx/algorithms/smetric.py +0 -30
  250. package/runtime/python/okstra_vendor/networkx/algorithms/sparsifiers.py +0 -296
  251. package/runtime/python/okstra_vendor/networkx/algorithms/structuralholes.py +0 -374
  252. package/runtime/python/okstra_vendor/networkx/algorithms/summarization.py +0 -564
  253. package/runtime/python/okstra_vendor/networkx/algorithms/swap.py +0 -406
  254. package/runtime/python/okstra_vendor/networkx/algorithms/threshold.py +0 -981
  255. package/runtime/python/okstra_vendor/networkx/algorithms/time_dependent.py +0 -142
  256. package/runtime/python/okstra_vendor/networkx/algorithms/tournament.py +0 -406
  257. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/__init__.py +0 -5
  258. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/beamsearch.py +0 -90
  259. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/breadth_first_search.py +0 -576
  260. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/depth_first_search.py +0 -529
  261. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgebfs.py +0 -185
  262. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgedfs.py +0 -182
  263. package/runtime/python/okstra_vendor/networkx/algorithms/tree/__init__.py +0 -7
  264. package/runtime/python/okstra_vendor/networkx/algorithms/tree/branchings.py +0 -1042
  265. package/runtime/python/okstra_vendor/networkx/algorithms/tree/coding.py +0 -413
  266. package/runtime/python/okstra_vendor/networkx/algorithms/tree/decomposition.py +0 -88
  267. package/runtime/python/okstra_vendor/networkx/algorithms/tree/distance_measures.py +0 -219
  268. package/runtime/python/okstra_vendor/networkx/algorithms/tree/mst.py +0 -1281
  269. package/runtime/python/okstra_vendor/networkx/algorithms/tree/operations.py +0 -106
  270. package/runtime/python/okstra_vendor/networkx/algorithms/tree/recognition.py +0 -273
  271. package/runtime/python/okstra_vendor/networkx/algorithms/triads.py +0 -500
  272. package/runtime/python/okstra_vendor/networkx/algorithms/vitality.py +0 -76
  273. package/runtime/python/okstra_vendor/networkx/algorithms/voronoi.py +0 -86
  274. package/runtime/python/okstra_vendor/networkx/algorithms/walks.py +0 -77
  275. package/runtime/python/okstra_vendor/networkx/algorithms/wiener.py +0 -278
  276. package/runtime/python/okstra_vendor/networkx/classes/__init__.py +0 -13
  277. package/runtime/python/okstra_vendor/networkx/classes/coreviews.py +0 -435
  278. package/runtime/python/okstra_vendor/networkx/classes/digraph.py +0 -1363
  279. package/runtime/python/okstra_vendor/networkx/classes/filters.py +0 -95
  280. package/runtime/python/okstra_vendor/networkx/classes/function.py +0 -1549
  281. package/runtime/python/okstra_vendor/networkx/classes/graph.py +0 -2082
  282. package/runtime/python/okstra_vendor/networkx/classes/graphviews.py +0 -269
  283. package/runtime/python/okstra_vendor/networkx/classes/multidigraph.py +0 -977
  284. package/runtime/python/okstra_vendor/networkx/classes/multigraph.py +0 -1294
  285. package/runtime/python/okstra_vendor/networkx/classes/reportviews.py +0 -1447
  286. package/runtime/python/okstra_vendor/networkx/convert.py +0 -502
  287. package/runtime/python/okstra_vendor/networkx/convert_matrix.py +0 -1314
  288. package/runtime/python/okstra_vendor/networkx/drawing/__init__.py +0 -7
  289. package/runtime/python/okstra_vendor/networkx/drawing/layout.py +0 -2036
  290. package/runtime/python/okstra_vendor/networkx/drawing/nx_agraph.py +0 -470
  291. package/runtime/python/okstra_vendor/networkx/drawing/nx_latex.py +0 -570
  292. package/runtime/python/okstra_vendor/networkx/drawing/nx_pydot.py +0 -361
  293. package/runtime/python/okstra_vendor/networkx/drawing/nx_pylab.py +0 -2978
  294. package/runtime/python/okstra_vendor/networkx/exception.py +0 -131
  295. package/runtime/python/okstra_vendor/networkx/generators/__init__.py +0 -34
  296. package/runtime/python/okstra_vendor/networkx/generators/atlas.dat.gz +0 -0
  297. package/runtime/python/okstra_vendor/networkx/generators/atlas.py +0 -227
  298. package/runtime/python/okstra_vendor/networkx/generators/classic.py +0 -1091
  299. package/runtime/python/okstra_vendor/networkx/generators/cographs.py +0 -68
  300. package/runtime/python/okstra_vendor/networkx/generators/community.py +0 -1070
  301. package/runtime/python/okstra_vendor/networkx/generators/degree_seq.py +0 -886
  302. package/runtime/python/okstra_vendor/networkx/generators/directed.py +0 -572
  303. package/runtime/python/okstra_vendor/networkx/generators/duplication.py +0 -174
  304. package/runtime/python/okstra_vendor/networkx/generators/ego.py +0 -66
  305. package/runtime/python/okstra_vendor/networkx/generators/expanders.py +0 -499
  306. package/runtime/python/okstra_vendor/networkx/generators/geometric.py +0 -1037
  307. package/runtime/python/okstra_vendor/networkx/generators/harary_graph.py +0 -163
  308. package/runtime/python/okstra_vendor/networkx/generators/internet_as_graphs.py +0 -443
  309. package/runtime/python/okstra_vendor/networkx/generators/intersection.py +0 -125
  310. package/runtime/python/okstra_vendor/networkx/generators/interval_graph.py +0 -70
  311. package/runtime/python/okstra_vendor/networkx/generators/joint_degree_seq.py +0 -664
  312. package/runtime/python/okstra_vendor/networkx/generators/lattice.py +0 -405
  313. package/runtime/python/okstra_vendor/networkx/generators/line.py +0 -501
  314. package/runtime/python/okstra_vendor/networkx/generators/mycielski.py +0 -110
  315. package/runtime/python/okstra_vendor/networkx/generators/nonisomorphic_trees.py +0 -259
  316. package/runtime/python/okstra_vendor/networkx/generators/random_clustered.py +0 -117
  317. package/runtime/python/okstra_vendor/networkx/generators/random_graphs.py +0 -1416
  318. package/runtime/python/okstra_vendor/networkx/generators/small.py +0 -1070
  319. package/runtime/python/okstra_vendor/networkx/generators/social.py +0 -554
  320. package/runtime/python/okstra_vendor/networkx/generators/spectral_graph_forge.py +0 -120
  321. package/runtime/python/okstra_vendor/networkx/generators/stochastic.py +0 -54
  322. package/runtime/python/okstra_vendor/networkx/generators/sudoku.py +0 -131
  323. package/runtime/python/okstra_vendor/networkx/generators/time_series.py +0 -74
  324. package/runtime/python/okstra_vendor/networkx/generators/trees.py +0 -1070
  325. package/runtime/python/okstra_vendor/networkx/generators/triads.py +0 -94
  326. package/runtime/python/okstra_vendor/networkx/lazy_imports.py +0 -188
  327. package/runtime/python/okstra_vendor/networkx/linalg/__init__.py +0 -13
  328. package/runtime/python/okstra_vendor/networkx/linalg/algebraicconnectivity.py +0 -650
  329. package/runtime/python/okstra_vendor/networkx/linalg/attrmatrix.py +0 -466
  330. package/runtime/python/okstra_vendor/networkx/linalg/bethehessianmatrix.py +0 -77
  331. package/runtime/python/okstra_vendor/networkx/linalg/graphmatrix.py +0 -168
  332. package/runtime/python/okstra_vendor/networkx/linalg/laplacianmatrix.py +0 -512
  333. package/runtime/python/okstra_vendor/networkx/linalg/modularitymatrix.py +0 -166
  334. package/runtime/python/okstra_vendor/networkx/linalg/spectrum.py +0 -186
  335. package/runtime/python/okstra_vendor/networkx/readwrite/__init__.py +0 -17
  336. package/runtime/python/okstra_vendor/networkx/readwrite/adjlist.py +0 -330
  337. package/runtime/python/okstra_vendor/networkx/readwrite/edgelist.py +0 -489
  338. package/runtime/python/okstra_vendor/networkx/readwrite/gexf.py +0 -1084
  339. package/runtime/python/okstra_vendor/networkx/readwrite/gml.py +0 -879
  340. package/runtime/python/okstra_vendor/networkx/readwrite/graph6.py +0 -427
  341. package/runtime/python/okstra_vendor/networkx/readwrite/graphml.py +0 -1053
  342. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/__init__.py +0 -19
  343. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/adjacency.py +0 -156
  344. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/cytoscape.py +0 -190
  345. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/node_link.py +0 -261
  346. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tree.py +0 -137
  347. package/runtime/python/okstra_vendor/networkx/readwrite/leda.py +0 -108
  348. package/runtime/python/okstra_vendor/networkx/readwrite/multiline_adjlist.py +0 -393
  349. package/runtime/python/okstra_vendor/networkx/readwrite/p2g.py +0 -113
  350. package/runtime/python/okstra_vendor/networkx/readwrite/pajek.py +0 -286
  351. package/runtime/python/okstra_vendor/networkx/readwrite/sparse6.py +0 -379
  352. package/runtime/python/okstra_vendor/networkx/readwrite/text.py +0 -851
  353. package/runtime/python/okstra_vendor/networkx/relabel.py +0 -285
  354. package/runtime/python/okstra_vendor/networkx/utils/__init__.py +0 -8
  355. package/runtime/python/okstra_vendor/networkx/utils/backends.py +0 -2171
  356. package/runtime/python/okstra_vendor/networkx/utils/configs.py +0 -396
  357. package/runtime/python/okstra_vendor/networkx/utils/decorators.py +0 -1233
  358. package/runtime/python/okstra_vendor/networkx/utils/heaps.py +0 -338
  359. package/runtime/python/okstra_vendor/networkx/utils/mapped_queue.py +0 -297
  360. package/runtime/python/okstra_vendor/networkx/utils/misc.py +0 -703
  361. package/runtime/python/okstra_vendor/networkx/utils/random_sequence.py +0 -198
  362. package/runtime/python/okstra_vendor/networkx/utils/rcm.py +0 -159
  363. package/runtime/python/okstra_vendor/networkx/utils/union_find.py +0 -106
  364. package/runtime/skills/okstra-graphify/SKILL.md +0 -169
  365. package/src/commands/graphify.mjs +0 -32
@@ -1,540 +0,0 @@
1
- """Graph analysis: god nodes (most connected), surprising connections (cross-community), suggested questions."""
2
- from __future__ import annotations
3
- import networkx as nx
4
-
5
-
6
- def _node_community_map(communities: dict[int, list[str]]) -> dict[str, int]:
7
- """Invert communities dict: node_id -> community_id."""
8
- return {n: cid for cid, nodes in communities.items() for n in nodes}
9
-
10
-
11
- def _is_file_node(G: nx.Graph, node_id: str) -> bool:
12
- """
13
- Return True if this node is a file-level hub node (e.g. 'client', 'models')
14
- or an AST method stub (e.g. '.auth_flow()', '.__init__()').
15
-
16
- These are synthetic nodes created by the AST extractor and should be excluded
17
- from god nodes, surprising connections, and knowledge gap reporting.
18
- """
19
- attrs = G.nodes[node_id]
20
- label = attrs.get("label", "")
21
- if not label:
22
- return False
23
- # File-level hub: label matches the actual source filename (not just any label ending in .py)
24
- source_file = attrs.get("source_file", "")
25
- if source_file:
26
- from pathlib import Path as _Path
27
- if label == _Path(source_file).name:
28
- return True
29
- # Method stub: AST extractor labels methods as '.method_name()'
30
- if label.startswith(".") and label.endswith("()"):
31
- return True
32
- # Module-level function stub: labeled 'function_name()' - only has a contains edge
33
- # These are real functions but structurally isolated by definition; not a gap worth flagging
34
- if label.endswith("()") and G.degree(node_id) <= 1:
35
- return True
36
- return False
37
-
38
-
39
- def god_nodes(G: nx.Graph, top_n: int = 10) -> list[dict]:
40
- """Return the top_n most-connected real entities - the core abstractions.
41
-
42
- File-level hub nodes are excluded: they accumulate import/contains edges
43
- mechanically and don't represent meaningful architectural abstractions.
44
- """
45
- degree = dict(G.degree())
46
- sorted_nodes = sorted(degree.items(), key=lambda x: x[1], reverse=True)
47
- result = []
48
- for node_id, deg in sorted_nodes:
49
- if _is_file_node(G, node_id) or _is_concept_node(G, node_id):
50
- continue
51
- result.append({
52
- "id": node_id,
53
- "label": G.nodes[node_id].get("label", node_id),
54
- "degree": deg,
55
- })
56
- if len(result) >= top_n:
57
- break
58
- return result
59
-
60
-
61
- def surprising_connections(
62
- G: nx.Graph,
63
- communities: dict[int, list[str]] | None = None,
64
- top_n: int = 5,
65
- ) -> list[dict]:
66
- """
67
- Find connections that are genuinely surprising - not obvious from file structure.
68
-
69
- Strategy:
70
- - Multi-file corpora: cross-file edges between real entities (not concept nodes).
71
- Sorted AMBIGUOUS → INFERRED → EXTRACTED.
72
- - Single-file / single-source corpora: cross-community edges that bridge
73
- distant parts of the graph (betweenness centrality on edges).
74
- These reveal non-obvious structural couplings.
75
-
76
- Concept nodes (empty source_file, or injected semantic annotations) are excluded
77
- from surprising connections because they are intentional, not discovered.
78
- """
79
- # Identify unique source files (ignore empty/null source_file)
80
- source_files = {
81
- data.get("source_file", "")
82
- for _, data in G.nodes(data=True)
83
- if data.get("source_file", "")
84
- }
85
- is_multi_source = len(source_files) > 1
86
-
87
- if is_multi_source:
88
- return _cross_file_surprises(G, communities or {}, top_n)
89
- else:
90
- return _cross_community_surprises(G, communities or {}, top_n)
91
-
92
-
93
- def _is_concept_node(G: nx.Graph, node_id: str) -> bool:
94
- """
95
- Return True if this node is a manually-injected semantic concept node
96
- rather than a real entity found in source code.
97
-
98
- Signals:
99
- - Empty source_file
100
- - source_file doesn't look like a real file path (no extension)
101
- """
102
- data = G.nodes[node_id]
103
- source = data.get("source_file", "")
104
- if not source:
105
- return True
106
- # Has no file extension → probably a concept label, not a real file
107
- if "." not in source.split("/")[-1]:
108
- return True
109
- return False
110
-
111
-
112
- from graphify.detect import CODE_EXTENSIONS, DOC_EXTENSIONS, PAPER_EXTENSIONS, IMAGE_EXTENSIONS
113
-
114
-
115
- def _file_category(path: str) -> str:
116
- ext = ("." + path.rsplit(".", 1)[-1].lower()) if "." in path else ""
117
- if ext in CODE_EXTENSIONS:
118
- return "code"
119
- if ext in PAPER_EXTENSIONS:
120
- return "paper"
121
- if ext in IMAGE_EXTENSIONS:
122
- return "image"
123
- return "doc"
124
-
125
-
126
- def _top_level_dir(path: str) -> str:
127
- """Return the first path component - used to detect cross-repo edges."""
128
- return path.split("/")[0] if "/" in path else path
129
-
130
-
131
- def _surprise_score(
132
- G: nx.Graph,
133
- u: str,
134
- v: str,
135
- data: dict,
136
- node_community: dict[str, int],
137
- u_source: str,
138
- v_source: str,
139
- ) -> tuple[int, list[str]]:
140
- """Score how surprising a cross-file edge is. Returns (score, reasons)."""
141
- score = 0
142
- reasons: list[str] = []
143
-
144
- # 1. Confidence weight - uncertain connections are more noteworthy
145
- conf = data.get("confidence", "EXTRACTED")
146
- conf_bonus = {"AMBIGUOUS": 3, "INFERRED": 2, "EXTRACTED": 1}.get(conf, 1)
147
- score += conf_bonus
148
- if conf in ("AMBIGUOUS", "INFERRED"):
149
- reasons.append(f"{conf.lower()} connection - not explicitly stated in source")
150
-
151
- # 2. Cross file-type bonus - code↔paper or code↔image is non-obvious
152
- cat_u = _file_category(u_source)
153
- cat_v = _file_category(v_source)
154
- if cat_u != cat_v:
155
- score += 2
156
- reasons.append(f"crosses file types ({cat_u} ↔ {cat_v})")
157
-
158
- # 3. Cross-repo bonus - different top-level directory
159
- if _top_level_dir(u_source) != _top_level_dir(v_source):
160
- score += 2
161
- reasons.append("connects across different repos/directories")
162
-
163
- # 4. Cross-community bonus - Leiden says these are structurally distant
164
- cid_u = node_community.get(u)
165
- cid_v = node_community.get(v)
166
- if cid_u is not None and cid_v is not None and cid_u != cid_v:
167
- score += 1
168
- reasons.append("bridges separate communities")
169
-
170
- # 4b. Semantic similarity bonus - non-obvious conceptual links score higher
171
- if data.get("relation") == "semantically_similar_to":
172
- score = int(score * 1.5)
173
- reasons.append("semantically similar concepts with no structural link")
174
-
175
- # 5. Peripheral→hub: a low-degree node connecting to a high-degree one
176
- deg_u = G.degree(u)
177
- deg_v = G.degree(v)
178
- if min(deg_u, deg_v) <= 2 and max(deg_u, deg_v) >= 5:
179
- score += 1
180
- peripheral = G.nodes[u].get("label", u) if deg_u <= 2 else G.nodes[v].get("label", v)
181
- hub = G.nodes[v].get("label", v) if deg_u <= 2 else G.nodes[u].get("label", u)
182
- reasons.append(f"peripheral node `{peripheral}` unexpectedly reaches hub `{hub}`")
183
-
184
- return score, reasons
185
-
186
-
187
- def _cross_file_surprises(G: nx.Graph, communities: dict[int, list[str]], top_n: int) -> list[dict]:
188
- """
189
- Cross-file edges between real code/doc entities, ranked by a composite
190
- surprise score rather than confidence alone.
191
-
192
- Surprise score accounts for:
193
- - Confidence (AMBIGUOUS > INFERRED > EXTRACTED)
194
- - Cross file-type (code↔paper is more surprising than code↔code)
195
- - Cross-repo (different top-level directory)
196
- - Cross-community (Leiden says structurally distant)
197
- - Peripheral→hub (low-degree node reaching a god node)
198
-
199
- Each result includes a 'why' field explaining what makes it non-obvious.
200
- """
201
- node_community = _node_community_map(communities)
202
- candidates = []
203
-
204
- for u, v, data in G.edges(data=True):
205
- relation = data.get("relation", "")
206
- if relation in ("imports", "imports_from", "contains", "method"):
207
- continue
208
- if _is_concept_node(G, u) or _is_concept_node(G, v):
209
- continue
210
- if _is_file_node(G, u) or _is_file_node(G, v):
211
- continue
212
-
213
- u_source = G.nodes[u].get("source_file", "")
214
- v_source = G.nodes[v].get("source_file", "")
215
-
216
- if not u_source or not v_source or u_source == v_source:
217
- continue
218
-
219
- score, reasons = _surprise_score(G, u, v, data, node_community, u_source, v_source)
220
- src_id = data.get("_src", u)
221
- if src_id not in G.nodes:
222
- src_id = u
223
- tgt_id = data.get("_tgt", v)
224
- if tgt_id not in G.nodes:
225
- tgt_id = v
226
- candidates.append({
227
- "_score": score,
228
- "source": G.nodes[src_id].get("label", src_id),
229
- "target": G.nodes[tgt_id].get("label", tgt_id),
230
- "source_files": [
231
- G.nodes[src_id].get("source_file", ""),
232
- G.nodes[tgt_id].get("source_file", ""),
233
- ],
234
- "confidence": data.get("confidence", "EXTRACTED"),
235
- "relation": relation,
236
- "why": "; ".join(reasons) if reasons else "cross-file semantic connection",
237
- })
238
-
239
- candidates.sort(key=lambda x: x["_score"], reverse=True)
240
- for c in candidates:
241
- c.pop("_score")
242
-
243
- if candidates:
244
- return candidates[:top_n]
245
-
246
- return _cross_community_surprises(G, communities, top_n)
247
-
248
-
249
- def _cross_community_surprises(
250
- G: nx.Graph,
251
- communities: dict[int, list[str]],
252
- top_n: int,
253
- ) -> list[dict]:
254
- """
255
- For single-source corpora: find edges that bridge different communities.
256
- These are surprising because Leiden grouped everything else tightly -
257
- these edges cut across the natural structure.
258
-
259
- Falls back to high-betweenness edges if no community info is provided.
260
- """
261
- if not communities:
262
- # No community info - use edge betweenness centrality
263
- if G.number_of_edges() == 0:
264
- return []
265
- if G.number_of_nodes() > 5000:
266
- return []
267
- betweenness = nx.edge_betweenness_centrality(G)
268
- top_edges = sorted(betweenness.items(), key=lambda x: x[1], reverse=True)[:top_n]
269
- result = []
270
- for (u, v), score in top_edges:
271
- data = G.edges[u, v]
272
- result.append({
273
- "source": G.nodes[u].get("label", u),
274
- "target": G.nodes[v].get("label", v),
275
- "source_files": [
276
- G.nodes[u].get("source_file", ""),
277
- G.nodes[v].get("source_file", ""),
278
- ],
279
- "confidence": data.get("confidence", "EXTRACTED"),
280
- "relation": data.get("relation", ""),
281
- "note": f"Bridges graph structure (betweenness={score:.3f})",
282
- })
283
- return result
284
-
285
- # Build node → community map
286
- node_community = _node_community_map(communities)
287
-
288
- surprises = []
289
- for u, v, data in G.edges(data=True):
290
- cid_u = node_community.get(u)
291
- cid_v = node_community.get(v)
292
- if cid_u is None or cid_v is None or cid_u == cid_v:
293
- continue
294
- # Skip file hub nodes and plain structural edges
295
- if _is_file_node(G, u) or _is_file_node(G, v):
296
- continue
297
- relation = data.get("relation", "")
298
- if relation in ("imports", "imports_from", "contains", "method"):
299
- continue
300
- # This edge crosses community boundaries - interesting
301
- confidence = data.get("confidence", "EXTRACTED")
302
- src_id = data.get("_src", u)
303
- if src_id not in G.nodes:
304
- src_id = u
305
- tgt_id = data.get("_tgt", v)
306
- if tgt_id not in G.nodes:
307
- tgt_id = v
308
- surprises.append({
309
- "source": G.nodes[src_id].get("label", src_id),
310
- "target": G.nodes[tgt_id].get("label", tgt_id),
311
- "source_files": [
312
- G.nodes[src_id].get("source_file", ""),
313
- G.nodes[tgt_id].get("source_file", ""),
314
- ],
315
- "confidence": confidence,
316
- "relation": relation,
317
- "note": f"Bridges community {cid_u} → community {cid_v}",
318
- "_pair": tuple(sorted([cid_u, cid_v])),
319
- })
320
-
321
- # Sort: AMBIGUOUS first, then INFERRED, then EXTRACTED
322
- order = {"AMBIGUOUS": 0, "INFERRED": 1, "EXTRACTED": 2}
323
- surprises.sort(key=lambda x: order.get(x["confidence"], 3))
324
-
325
- # Deduplicate by community pair - one representative edge per (A→B) boundary.
326
- # Without this, a single high-betweenness god node dominates all results.
327
- seen_pairs: set[tuple] = set()
328
- deduped = []
329
- for s in surprises:
330
- pair = s.pop("_pair")
331
- if pair not in seen_pairs:
332
- seen_pairs.add(pair)
333
- deduped.append(s)
334
- return deduped[:top_n]
335
-
336
-
337
- def suggest_questions(
338
- G: nx.Graph,
339
- communities: dict[int, list[str]],
340
- community_labels: dict[int, str],
341
- top_n: int = 7,
342
- ) -> list[dict]:
343
- """
344
- Generate questions the graph is uniquely positioned to answer.
345
- Based on: AMBIGUOUS edges, bridge nodes, underexplored god nodes, isolated nodes.
346
- Each question has a 'type', 'question', and 'why' field.
347
- """
348
- questions = []
349
- node_community = _node_community_map(communities)
350
-
351
- # 1. AMBIGUOUS edges → unresolved relationship questions
352
- for u, v, data in G.edges(data=True):
353
- if data.get("confidence") == "AMBIGUOUS":
354
- ul = G.nodes[u].get("label", u)
355
- vl = G.nodes[v].get("label", v)
356
- relation = data.get("relation", "related to")
357
- questions.append({
358
- "type": "ambiguous_edge",
359
- "question": f"What is the exact relationship between `{ul}` and `{vl}`?",
360
- "why": f"Edge tagged AMBIGUOUS (relation: {relation}) - confidence is low.",
361
- })
362
-
363
- # 2. Bridge nodes (high betweenness) → cross-cutting concern questions
364
- if G.number_of_edges() > 0:
365
- k = min(100, G.number_of_nodes()) if G.number_of_nodes() > 1000 else None
366
- betweenness = nx.betweenness_centrality(G, k=k)
367
- # Top bridge nodes that are NOT file-level hubs
368
- bridges = sorted(
369
- [(n, s) for n, s in betweenness.items()
370
- if not _is_file_node(G, n) and not _is_concept_node(G, n) and s > 0],
371
- key=lambda x: x[1],
372
- reverse=True,
373
- )[:3]
374
- for node_id, score in bridges:
375
- label = G.nodes[node_id].get("label", node_id)
376
- cid = node_community.get(node_id)
377
- comm_label = community_labels.get(cid, f"Community {cid}") if cid is not None else "unknown"
378
- neighbors = list(G.neighbors(node_id))
379
- neighbor_comms = {node_community.get(n) for n in neighbors if node_community.get(n) != cid}
380
- if neighbor_comms:
381
- other_labels = [community_labels.get(c, f"Community {c}") for c in neighbor_comms]
382
- questions.append({
383
- "type": "bridge_node",
384
- "question": f"Why does `{label}` connect `{comm_label}` to {', '.join(f'`{l}`' for l in other_labels)}?",
385
- "why": f"High betweenness centrality ({score:.3f}) - this node is a cross-community bridge.",
386
- })
387
-
388
- # 3. God nodes with many INFERRED edges → verification questions
389
- degree = dict(G.degree())
390
- top_nodes = sorted(
391
- [(n, d) for n, d in degree.items() if not _is_file_node(G, n)],
392
- key=lambda x: x[1],
393
- reverse=True,
394
- )[:5]
395
- for node_id, _ in top_nodes:
396
- inferred = [
397
- (u, v, d) for u, v, d in G.edges(node_id, data=True)
398
- if d.get("confidence") == "INFERRED"
399
- ]
400
- if len(inferred) >= 2:
401
- label = G.nodes[node_id].get("label", node_id)
402
- # Use _src/_tgt to get the correct direction; fall back to v (the other node)
403
- others = []
404
- for u, v, d in inferred[:2]:
405
- src_id = d.get("_src", u)
406
- if src_id not in G.nodes:
407
- src_id = u
408
- tgt_id = d.get("_tgt", v)
409
- if tgt_id not in G.nodes:
410
- tgt_id = v
411
- other_id = tgt_id if src_id == node_id else src_id
412
- others.append(G.nodes[other_id].get("label", other_id))
413
- questions.append({
414
- "type": "verify_inferred",
415
- "question": f"Are the {len(inferred)} inferred relationships involving `{label}` (e.g. with `{others[0]}` and `{others[1]}`) actually correct?",
416
- "why": f"`{label}` has {len(inferred)} INFERRED edges - model-reasoned connections that need verification.",
417
- })
418
-
419
- # 4. Isolated or weakly-connected nodes → exploration questions
420
- isolated = [
421
- n for n in G.nodes()
422
- if G.degree(n) <= 1 and not _is_file_node(G, n) and not _is_concept_node(G, n)
423
- ]
424
- if isolated:
425
- labels = [G.nodes[n].get("label", n) for n in isolated[:3]]
426
- questions.append({
427
- "type": "isolated_nodes",
428
- "question": f"What connects {', '.join(f'`{l}`' for l in labels)} to the rest of the system?",
429
- "why": f"{len(isolated)} weakly-connected nodes found - possible documentation gaps or missing edges.",
430
- })
431
-
432
- # 5. Low-cohesion communities → structural questions
433
- from .cluster import cohesion_score
434
- for cid, nodes in communities.items():
435
- score = cohesion_score(G, nodes)
436
- if score < 0.15 and len(nodes) >= 5:
437
- label = community_labels.get(cid, f"Community {cid}")
438
- questions.append({
439
- "type": "low_cohesion",
440
- "question": f"Should `{label}` be split into smaller, more focused modules?",
441
- "why": f"Cohesion score {score} - nodes in this community are weakly interconnected.",
442
- })
443
-
444
- if not questions:
445
- return [{
446
- "type": "no_signal",
447
- "question": None,
448
- "why": (
449
- "Not enough signal to generate questions. "
450
- "This usually means the corpus has no AMBIGUOUS edges, no bridge nodes, "
451
- "no INFERRED relationships, and all communities are tightly cohesive. "
452
- "Add more files or run with --mode deep to extract richer edges."
453
- ),
454
- }]
455
-
456
- return questions[:top_n]
457
-
458
-
459
- def graph_diff(G_old: nx.Graph, G_new: nx.Graph) -> dict:
460
- """Compare two graph snapshots and return what changed.
461
-
462
- Returns:
463
- {
464
- "new_nodes": [{"id": ..., "label": ...}],
465
- "removed_nodes": [{"id": ..., "label": ...}],
466
- "new_edges": [{"source": ..., "target": ..., "relation": ..., "confidence": ...}],
467
- "removed_edges": [...],
468
- "summary": "3 new nodes, 5 new edges, 1 node removed"
469
- }
470
- """
471
- old_nodes = set(G_old.nodes())
472
- new_nodes = set(G_new.nodes())
473
-
474
- added_node_ids = new_nodes - old_nodes
475
- removed_node_ids = old_nodes - new_nodes
476
-
477
- new_nodes_list = [
478
- {"id": n, "label": G_new.nodes[n].get("label", n)}
479
- for n in added_node_ids
480
- ]
481
- removed_nodes_list = [
482
- {"id": n, "label": G_old.nodes[n].get("label", n)}
483
- for n in removed_node_ids
484
- ]
485
-
486
- def edge_key(G: nx.Graph, u: str, v: str, data: dict) -> tuple:
487
- if G.is_directed():
488
- return (u, v, data.get("relation", ""))
489
- return (min(u, v), max(u, v), data.get("relation", ""))
490
-
491
- old_edge_keys = {
492
- edge_key(G_old, u, v, d)
493
- for u, v, d in G_old.edges(data=True)
494
- }
495
- new_edge_keys = {
496
- edge_key(G_new, u, v, d)
497
- for u, v, d in G_new.edges(data=True)
498
- }
499
-
500
- added_edge_keys = new_edge_keys - old_edge_keys
501
- removed_edge_keys = old_edge_keys - new_edge_keys
502
-
503
- new_edges_list = []
504
- for u, v, d in G_new.edges(data=True):
505
- if edge_key(G_new, u, v, d) in added_edge_keys:
506
- new_edges_list.append({
507
- "source": u,
508
- "target": v,
509
- "relation": d.get("relation", ""),
510
- "confidence": d.get("confidence", ""),
511
- })
512
-
513
- removed_edges_list = []
514
- for u, v, d in G_old.edges(data=True):
515
- if edge_key(G_old, u, v, d) in removed_edge_keys:
516
- removed_edges_list.append({
517
- "source": u,
518
- "target": v,
519
- "relation": d.get("relation", ""),
520
- "confidence": d.get("confidence", ""),
521
- })
522
-
523
- parts = []
524
- if new_nodes_list:
525
- parts.append(f"{len(new_nodes_list)} new node{'s' if len(new_nodes_list) != 1 else ''}")
526
- if new_edges_list:
527
- parts.append(f"{len(new_edges_list)} new edge{'s' if len(new_edges_list) != 1 else ''}")
528
- if removed_nodes_list:
529
- parts.append(f"{len(removed_nodes_list)} node{'s' if len(removed_nodes_list) != 1 else ''} removed")
530
- if removed_edges_list:
531
- parts.append(f"{len(removed_edges_list)} edge{'s' if len(removed_edges_list) != 1 else ''} removed")
532
- summary = ", ".join(parts) if parts else "no changes"
533
-
534
- return {
535
- "new_nodes": new_nodes_list,
536
- "removed_nodes": removed_nodes_list,
537
- "new_edges": new_edges_list,
538
- "removed_edges": removed_edges_list,
539
- "summary": summary,
540
- }
@@ -1,129 +0,0 @@
1
- """Token-reduction benchmark - measures how much context graphify saves vs naive full-corpus approach."""
2
- from __future__ import annotations
3
- import json
4
- from pathlib import Path
5
- import networkx as nx
6
- from networkx.readwrite import json_graph
7
-
8
-
9
- _CHARS_PER_TOKEN = 4 # standard approximation
10
-
11
-
12
- def _estimate_tokens(text: str) -> int:
13
- return max(1, len(text) // _CHARS_PER_TOKEN)
14
-
15
-
16
- def _query_subgraph_tokens(G: nx.Graph, question: str, depth: int = 3) -> int:
17
- """Run BFS from best-matching nodes and return estimated tokens in the subgraph context."""
18
- terms = [t.lower() for t in question.split() if len(t) > 2]
19
- scored = []
20
- for nid, data in G.nodes(data=True):
21
- label = data.get("label", "").lower()
22
- score = sum(1 for t in terms if t in label)
23
- if score > 0:
24
- scored.append((score, nid))
25
- scored.sort(reverse=True)
26
- start_nodes = [nid for _, nid in scored[:3]]
27
- if not start_nodes:
28
- return 0
29
-
30
- visited: set[str] = set(start_nodes)
31
- frontier = set(start_nodes)
32
- edges_seen: list[tuple] = []
33
- for _ in range(depth):
34
- next_frontier: set[str] = set()
35
- for n in frontier:
36
- for neighbor in G.neighbors(n):
37
- if neighbor not in visited:
38
- next_frontier.add(neighbor)
39
- edges_seen.append((n, neighbor))
40
- visited.update(next_frontier)
41
- frontier = next_frontier
42
-
43
- lines = []
44
- for nid in visited:
45
- d = G.nodes[nid]
46
- lines.append(f"NODE {d.get('label', nid)} src={d.get('source_file', '')} loc={d.get('source_location', '')}")
47
- for u, v in edges_seen:
48
- if u in visited and v in visited:
49
- d = G.edges[u, v]
50
- lines.append(f"EDGE {G.nodes[u].get('label', u)} --{d.get('relation', '')}--> {G.nodes[v].get('label', v)}")
51
-
52
- return _estimate_tokens("\n".join(lines))
53
-
54
-
55
- _SAMPLE_QUESTIONS = [
56
- "how does authentication work",
57
- "what is the main entry point",
58
- "how are errors handled",
59
- "what connects the data layer to the api",
60
- "what are the core abstractions",
61
- ]
62
-
63
-
64
- def run_benchmark(
65
- graph_path: str = "graphify-out/graph.json",
66
- corpus_words: int | None = None,
67
- questions: list[str] | None = None,
68
- ) -> dict:
69
- """Measure token reduction: corpus tokens vs graphify query tokens.
70
-
71
- Args:
72
- graph_path: path to the built graph
73
- corpus_words: total word count from detect() output; if None, estimated from graph
74
- questions: list of questions to benchmark; defaults to _SAMPLE_QUESTIONS
75
-
76
- Returns dict with: corpus_tokens, avg_query_tokens, reduction_ratio, per_question
77
- """
78
- data = json.loads(Path(graph_path).read_text(encoding="utf-8"))
79
- try:
80
- G = json_graph.node_link_graph(data, edges="links")
81
- except TypeError:
82
- G = json_graph.node_link_graph(data)
83
-
84
- if corpus_words is None:
85
- # Rough estimate: each node label is ~3 words, plus source context
86
- corpus_words = G.number_of_nodes() * 50
87
-
88
- corpus_tokens = corpus_words * 100 // 75 # words → tokens (100 words ≈ 133 tokens)
89
-
90
- qs = questions or _SAMPLE_QUESTIONS
91
- per_question = []
92
- for q in qs:
93
- qt = _query_subgraph_tokens(G, q)
94
- if qt > 0:
95
- per_question.append({"question": q, "query_tokens": qt, "reduction": round(corpus_tokens / qt, 1)})
96
-
97
- if not per_question:
98
- return {"error": "No matching nodes found for sample questions. Build the graph first."}
99
-
100
- avg_query_tokens = sum(p["query_tokens"] for p in per_question) // len(per_question)
101
- reduction_ratio = round(corpus_tokens / avg_query_tokens, 1) if avg_query_tokens > 0 else 0
102
-
103
- return {
104
- "corpus_tokens": corpus_tokens,
105
- "corpus_words": corpus_words,
106
- "nodes": G.number_of_nodes(),
107
- "edges": G.number_of_edges(),
108
- "avg_query_tokens": avg_query_tokens,
109
- "reduction_ratio": reduction_ratio,
110
- "per_question": per_question,
111
- }
112
-
113
-
114
- def print_benchmark(result: dict) -> None:
115
- """Print a human-readable benchmark report."""
116
- if "error" in result:
117
- print(f"Benchmark error: {result['error']}")
118
- return
119
-
120
- print(f"\ngraphify token reduction benchmark")
121
- print(f"{'─' * 50}")
122
- print(f" Corpus: {result['corpus_words']:,} words → ~{result['corpus_tokens']:,} tokens (naive)")
123
- print(f" Graph: {result['nodes']:,} nodes, {result['edges']:,} edges")
124
- print(f" Avg query cost: ~{result['avg_query_tokens']:,} tokens")
125
- print(f" Reduction: {result['reduction_ratio']}x fewer tokens per query")
126
- print(f"\n Per question:")
127
- for p in result["per_question"]:
128
- print(f" [{p['reduction']}x] {p['question'][:55]}")
129
- print()