mulle-roam-code 0.0.1__py3-none-any.whl

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 (257) hide show
  1. mulle_roam_code-0.0.1.dist-info/METADATA +1590 -0
  2. mulle_roam_code-0.0.1.dist-info/RECORD +257 -0
  3. mulle_roam_code-0.0.1.dist-info/WHEEL +5 -0
  4. mulle_roam_code-0.0.1.dist-info/entry_points.txt +3 -0
  5. mulle_roam_code-0.0.1.dist-info/licenses/LICENSE +21 -0
  6. mulle_roam_code-0.0.1.dist-info/top_level.txt +1 -0
  7. roam/__init__.py +8 -0
  8. roam/__main__.py +5 -0
  9. roam/analysis/__init__.py +1 -0
  10. roam/analysis/effects.py +639 -0
  11. roam/analysis/taint.py +689 -0
  12. roam/api.py +238 -0
  13. roam/bridges/__init__.py +3 -0
  14. roam/bridges/base.py +49 -0
  15. roam/bridges/bridge_config.py +218 -0
  16. roam/bridges/bridge_protobuf.py +352 -0
  17. roam/bridges/bridge_rest_api.py +242 -0
  18. roam/bridges/bridge_salesforce.py +198 -0
  19. roam/bridges/bridge_template.py +247 -0
  20. roam/bridges/registry.py +51 -0
  21. roam/catalog/__init__.py +0 -0
  22. roam/catalog/detectors.py +2242 -0
  23. roam/catalog/fixes.py +86 -0
  24. roam/catalog/smells.py +599 -0
  25. roam/catalog/tasks.py +1260 -0
  26. roam/cli.py +548 -0
  27. roam/commands/__init__.py +0 -0
  28. roam/commands/changed_files.py +139 -0
  29. roam/commands/cmd_adversarial.py +699 -0
  30. roam/commands/cmd_affected.py +432 -0
  31. roam/commands/cmd_affected_tests.py +375 -0
  32. roam/commands/cmd_agent_context.py +168 -0
  33. roam/commands/cmd_agent_export.py +890 -0
  34. roam/commands/cmd_agent_plan.py +315 -0
  35. roam/commands/cmd_ai_ratio.py +765 -0
  36. roam/commands/cmd_ai_readiness.py +775 -0
  37. roam/commands/cmd_alerts.py +409 -0
  38. roam/commands/cmd_annotate.py +210 -0
  39. roam/commands/cmd_api_changes.py +796 -0
  40. roam/commands/cmd_api_drift.py +781 -0
  41. roam/commands/cmd_attest.py +913 -0
  42. roam/commands/cmd_auth_gaps.py +799 -0
  43. roam/commands/cmd_bisect.py +216 -0
  44. roam/commands/cmd_breaking.py +464 -0
  45. roam/commands/cmd_budget.py +413 -0
  46. roam/commands/cmd_bus_factor.py +403 -0
  47. roam/commands/cmd_capsule.py +275 -0
  48. roam/commands/cmd_check_rules.py +574 -0
  49. roam/commands/cmd_clean.py +147 -0
  50. roam/commands/cmd_closure.py +294 -0
  51. roam/commands/cmd_clusters.py +457 -0
  52. roam/commands/cmd_codeowners.py +600 -0
  53. roam/commands/cmd_complexity.py +364 -0
  54. roam/commands/cmd_config.py +310 -0
  55. roam/commands/cmd_context.py +1151 -0
  56. roam/commands/cmd_conventions.py +697 -0
  57. roam/commands/cmd_coupling.py +462 -0
  58. roam/commands/cmd_coverage_gaps.py +638 -0
  59. roam/commands/cmd_cut.py +235 -0
  60. roam/commands/cmd_dark_matter.py +127 -0
  61. roam/commands/cmd_dashboard.py +365 -0
  62. roam/commands/cmd_dead.py +1585 -0
  63. roam/commands/cmd_debt.py +731 -0
  64. roam/commands/cmd_deps.py +121 -0
  65. roam/commands/cmd_describe.py +959 -0
  66. roam/commands/cmd_dev_profile.py +580 -0
  67. roam/commands/cmd_diagnose.py +377 -0
  68. roam/commands/cmd_diff.py +633 -0
  69. roam/commands/cmd_digest.py +214 -0
  70. roam/commands/cmd_doc_staleness.py +334 -0
  71. roam/commands/cmd_docs_coverage.py +193 -0
  72. roam/commands/cmd_doctor.py +319 -0
  73. roam/commands/cmd_drift.py +377 -0
  74. roam/commands/cmd_duplicates.py +559 -0
  75. roam/commands/cmd_effects.py +362 -0
  76. roam/commands/cmd_endpoints.py +768 -0
  77. roam/commands/cmd_entry_points.py +358 -0
  78. roam/commands/cmd_fan.py +311 -0
  79. roam/commands/cmd_file.py +334 -0
  80. roam/commands/cmd_fingerprint.py +172 -0
  81. roam/commands/cmd_fitness.py +723 -0
  82. roam/commands/cmd_fn_coupling.py +295 -0
  83. roam/commands/cmd_forecast.py +366 -0
  84. roam/commands/cmd_grep.py +282 -0
  85. roam/commands/cmd_guard.py +434 -0
  86. roam/commands/cmd_health.py +922 -0
  87. roam/commands/cmd_hooks.py +458 -0
  88. roam/commands/cmd_hotspots.py +606 -0
  89. roam/commands/cmd_impact.py +228 -0
  90. roam/commands/cmd_index.py +102 -0
  91. roam/commands/cmd_ingest_trace.py +143 -0
  92. roam/commands/cmd_init.py +166 -0
  93. roam/commands/cmd_intent.py +459 -0
  94. roam/commands/cmd_invariants.py +301 -0
  95. roam/commands/cmd_layers.py +387 -0
  96. roam/commands/cmd_map.py +275 -0
  97. roam/commands/cmd_math.py +213 -0
  98. roam/commands/cmd_mcp_setup.py +135 -0
  99. roam/commands/cmd_metrics.py +663 -0
  100. roam/commands/cmd_migration_safety.py +712 -0
  101. roam/commands/cmd_minimap.py +519 -0
  102. roam/commands/cmd_missing_index.py +885 -0
  103. roam/commands/cmd_module.py +204 -0
  104. roam/commands/cmd_mutate.py +400 -0
  105. roam/commands/cmd_n1.py +967 -0
  106. roam/commands/cmd_onboard.py +740 -0
  107. roam/commands/cmd_orchestrate.py +180 -0
  108. roam/commands/cmd_orphan_routes.py +754 -0
  109. roam/commands/cmd_over_fetch.py +633 -0
  110. roam/commands/cmd_owner.py +299 -0
  111. roam/commands/cmd_partition.py +714 -0
  112. roam/commands/cmd_path_coverage.py +564 -0
  113. roam/commands/cmd_patterns.py +689 -0
  114. roam/commands/cmd_plan.py +616 -0
  115. roam/commands/cmd_plan_refactor.py +432 -0
  116. roam/commands/cmd_pr_diff.py +292 -0
  117. roam/commands/cmd_pr_risk.py +677 -0
  118. roam/commands/cmd_preflight.py +706 -0
  119. roam/commands/cmd_relate.py +405 -0
  120. roam/commands/cmd_report.py +304 -0
  121. roam/commands/cmd_reset.py +117 -0
  122. roam/commands/cmd_risk.py +533 -0
  123. roam/commands/cmd_rules.py +319 -0
  124. roam/commands/cmd_safe_delete.py +224 -0
  125. roam/commands/cmd_safe_zones.py +295 -0
  126. roam/commands/cmd_schema.py +166 -0
  127. roam/commands/cmd_search.py +295 -0
  128. roam/commands/cmd_search_semantic.py +101 -0
  129. roam/commands/cmd_secrets.py +636 -0
  130. roam/commands/cmd_semantic_diff.py +538 -0
  131. roam/commands/cmd_simulate.py +296 -0
  132. roam/commands/cmd_simulate_departure.py +632 -0
  133. roam/commands/cmd_sketch.py +160 -0
  134. roam/commands/cmd_smells.py +179 -0
  135. roam/commands/cmd_snapshot.py +50 -0
  136. roam/commands/cmd_spectral.py +183 -0
  137. roam/commands/cmd_split.py +432 -0
  138. roam/commands/cmd_suggest_refactoring.py +486 -0
  139. roam/commands/cmd_suggest_reviewers.py +491 -0
  140. roam/commands/cmd_supply_chain.py +831 -0
  141. roam/commands/cmd_symbol.py +135 -0
  142. roam/commands/cmd_syntax_check.py +301 -0
  143. roam/commands/cmd_test_gaps.py +574 -0
  144. roam/commands/cmd_testmap.py +308 -0
  145. roam/commands/cmd_tour.py +377 -0
  146. roam/commands/cmd_trace.py +304 -0
  147. roam/commands/cmd_trend.py +461 -0
  148. roam/commands/cmd_trends.py +929 -0
  149. roam/commands/cmd_understand.py +763 -0
  150. roam/commands/cmd_uses.py +170 -0
  151. roam/commands/cmd_verify.py +812 -0
  152. roam/commands/cmd_verify_imports.py +435 -0
  153. roam/commands/cmd_vibe_check.py +932 -0
  154. roam/commands/cmd_visualize.py +361 -0
  155. roam/commands/cmd_vuln_map.py +139 -0
  156. roam/commands/cmd_vuln_reach.py +289 -0
  157. roam/commands/cmd_vulns.py +414 -0
  158. roam/commands/cmd_watch.py +759 -0
  159. roam/commands/cmd_weather.py +118 -0
  160. roam/commands/cmd_why.py +325 -0
  161. roam/commands/cmd_ws.py +755 -0
  162. roam/commands/cmd_xlang.py +170 -0
  163. roam/commands/context_helpers.py +1137 -0
  164. roam/commands/gate_presets.py +222 -0
  165. roam/commands/graph_helpers.py +93 -0
  166. roam/commands/metrics_history.py +298 -0
  167. roam/commands/next_steps.py +107 -0
  168. roam/commands/resolve.py +302 -0
  169. roam/competitor_site_data.py +2229 -0
  170. roam/coverage_reports.py +462 -0
  171. roam/db/__init__.py +0 -0
  172. roam/db/connection.py +359 -0
  173. roam/db/queries.py +151 -0
  174. roam/db/schema.py +335 -0
  175. roam/exit_codes.py +100 -0
  176. roam/graph/__init__.py +43 -0
  177. roam/graph/anomaly.py +493 -0
  178. roam/graph/builder.py +61 -0
  179. roam/graph/clusters.py +286 -0
  180. roam/graph/cycles.py +210 -0
  181. roam/graph/dark_matter.py +207 -0
  182. roam/graph/diff.py +467 -0
  183. roam/graph/fingerprint.py +297 -0
  184. roam/graph/layers.py +134 -0
  185. roam/graph/pagerank.py +171 -0
  186. roam/graph/partition.py +437 -0
  187. roam/graph/pathfinding.py +119 -0
  188. roam/graph/propagation.py +208 -0
  189. roam/graph/simulate.py +286 -0
  190. roam/graph/spectral.py +260 -0
  191. roam/index/__init__.py +5 -0
  192. roam/index/complexity.py +1108 -0
  193. roam/index/discovery.py +338 -0
  194. roam/index/file_roles.py +586 -0
  195. roam/index/git_stats.py +577 -0
  196. roam/index/incremental.py +75 -0
  197. roam/index/indexer.py +1191 -0
  198. roam/index/parser.py +461 -0
  199. roam/index/relations.py +537 -0
  200. roam/index/symbols.py +71 -0
  201. roam/index/test_conventions.py +508 -0
  202. roam/languages/__init__.py +21 -0
  203. roam/languages/apex_lang.py +241 -0
  204. roam/languages/aura_lang.py +228 -0
  205. roam/languages/base.py +111 -0
  206. roam/languages/c_lang.py +458 -0
  207. roam/languages/csharp_lang.py +1215 -0
  208. roam/languages/foxpro_lang.py +1554 -0
  209. roam/languages/generic_lang.py +702 -0
  210. roam/languages/go_lang.py +392 -0
  211. roam/languages/hcl_lang.py +398 -0
  212. roam/languages/java_lang.py +418 -0
  213. roam/languages/javascript_lang.py +799 -0
  214. roam/languages/kotlin_lang.py +147 -0
  215. roam/languages/objc_lang.py +401 -0
  216. roam/languages/php_lang.py +696 -0
  217. roam/languages/python_lang.py +850 -0
  218. roam/languages/registry.py +283 -0
  219. roam/languages/ruby_lang.py +429 -0
  220. roam/languages/rust_lang.py +545 -0
  221. roam/languages/sfxml_lang.py +276 -0
  222. roam/languages/swift_lang.py +173 -0
  223. roam/languages/typescript_lang.py +323 -0
  224. roam/languages/visualforce_lang.py +151 -0
  225. roam/languages/yaml_lang.py +566 -0
  226. roam/mcp_server.py +4794 -0
  227. roam/output/__init__.py +0 -0
  228. roam/output/formatter.py +557 -0
  229. roam/output/mermaid.py +62 -0
  230. roam/output/sarif.py +897 -0
  231. roam/output/schema_registry.py +57 -0
  232. roam/plugins.py +208 -0
  233. roam/refactor/__init__.py +0 -0
  234. roam/refactor/codegen.py +106 -0
  235. roam/refactor/transforms.py +711 -0
  236. roam/rules/__init__.py +0 -0
  237. roam/rules/ast_match.py +238 -0
  238. roam/rules/builtin.py +617 -0
  239. roam/rules/dataflow.py +515 -0
  240. roam/rules/engine.py +943 -0
  241. roam/runtime/__init__.py +3 -0
  242. roam/runtime/hotspots.py +138 -0
  243. roam/runtime/trace_ingest.py +535 -0
  244. roam/search/__init__.py +1 -0
  245. roam/search/framework_packs.py +673 -0
  246. roam/search/index_embeddings.py +732 -0
  247. roam/search/onnx_embeddings.py +233 -0
  248. roam/search/tfidf.py +355 -0
  249. roam/security/__init__.py +1 -0
  250. roam/security/vuln_reach.py +246 -0
  251. roam/security/vuln_store.py +334 -0
  252. roam/surface_counts.py +158 -0
  253. roam/workspace/__init__.py +3 -0
  254. roam/workspace/aggregator.py +426 -0
  255. roam/workspace/api_scanner.py +538 -0
  256. roam/workspace/config.py +95 -0
  257. roam/workspace/db.py +136 -0
@@ -0,0 +1,831 @@
1
+ """Dependency risk dashboard -- pin coverage, risk scoring, supply-chain health."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ from pathlib import Path
7
+ from typing import NamedTuple
8
+
9
+ import click
10
+
11
+ from roam import __version__
12
+ from roam.db.connection import find_project_root
13
+ from roam.output.formatter import format_table, json_envelope, to_json
14
+ from roam.output.sarif import to_sarif, write_sarif
15
+
16
+
17
+ class Dependency(NamedTuple):
18
+ name: str
19
+ version_spec: str
20
+ is_dev: bool
21
+ pin_status: str
22
+ risk_level: str
23
+ source_file: str
24
+ ecosystem: str
25
+
26
+
27
+ def _pin_status_python(spec: str) -> str:
28
+ if not spec or spec.strip() in ("*", ""):
29
+ return "unpinned"
30
+ if spec.startswith("=="):
31
+ return "exact"
32
+ if spec.startswith("~="):
33
+ return "range"
34
+ if "*" in spec:
35
+ return "unpinned"
36
+ if re.search(r"[><!]", spec):
37
+ return "range"
38
+ return "unpinned"
39
+
40
+
41
+ def _pin_status_npm(spec: str) -> str:
42
+ if not spec or spec in ("*", "latest", "x", ""):
43
+ return "unpinned"
44
+ if re.match(r"^=?[0-9]", spec):
45
+ return "exact"
46
+ if spec.startswith(("^", "~")):
47
+ return "range"
48
+ if spec.startswith((">", "<")):
49
+ return "range"
50
+ if re.search(r"[*xX]", spec):
51
+ return "unpinned"
52
+ return "range"
53
+
54
+
55
+ def _pin_status_go(spec: str) -> str:
56
+ if not spec:
57
+ return "unpinned"
58
+ if re.match(r"v\d+\.\d+\.\d+-\d{14}-[0-9a-f]+", spec):
59
+ return "exact"
60
+ if re.match(r"v\d+\.\d+\.\d+", spec):
61
+ return "exact"
62
+ return "range"
63
+
64
+
65
+ def _pin_status_rust(spec: str) -> str:
66
+ if not spec or spec in ("*", ""):
67
+ return "unpinned"
68
+ if spec.startswith("=") and not spec.startswith(">="):
69
+ return "exact"
70
+ if spec.startswith(("^", "~")):
71
+ return "range"
72
+ if re.match(r"^\d", spec):
73
+ return "range"
74
+ if re.search(r"[><!]", spec):
75
+ return "range"
76
+ if "*" in spec:
77
+ return "unpinned"
78
+ return "range"
79
+
80
+
81
+ def _pin_status_ruby(spec: str) -> str:
82
+ if not spec:
83
+ return "unpinned"
84
+ if re.match(r"^=\s*\d", spec):
85
+ return "exact"
86
+ if spec.startswith("~>"):
87
+ return "range"
88
+ if re.search(r"[><!]", spec):
89
+ return "range"
90
+ return "unpinned"
91
+
92
+
93
+ def _risk_level(pin_status: str, is_dev: bool) -> str: # noqa: ARG001
94
+ return {"exact": "low", "range": "medium", "unpinned": "high"}[pin_status]
95
+
96
+
97
+ def _parse_requirements_txt(path: Path, source: str) -> list[Dependency]:
98
+ deps: list[Dependency] = []
99
+ try:
100
+ text = path.read_text(encoding="utf-8", errors="replace")
101
+ except OSError:
102
+ return deps
103
+ for raw_line in text.splitlines():
104
+ line = raw_line.strip()
105
+ if not line or line.startswith("#") or line.startswith("-"):
106
+ continue
107
+ line = re.sub(r"\s+#.*$", "", line)
108
+ m = re.match(r"^([A-Za-z0-9_.\-]+)(\[.*?\])?(.*)?$", line)
109
+ if not m:
110
+ continue
111
+ name = m.group(1).strip()
112
+ spec = (m.group(3) or "").strip()
113
+ pin = _pin_status_python(spec)
114
+ deps.append(
115
+ Dependency(
116
+ name=name,
117
+ version_spec=spec,
118
+ is_dev=False,
119
+ pin_status=pin,
120
+ risk_level=_risk_level(pin, False),
121
+ source_file=source,
122
+ ecosystem="python",
123
+ )
124
+ )
125
+ return deps
126
+
127
+
128
+ _SETUP_INSTALL_REQUIRES_RE = re.compile(r"install_requires\s*=\s*\[([^\]]*)\]", re.DOTALL)
129
+
130
+
131
+ def _parse_setup_py(path: Path, source: str) -> list[Dependency]:
132
+ deps: list[Dependency] = []
133
+ try:
134
+ text = path.read_text(encoding="utf-8", errors="replace")
135
+ except OSError:
136
+ return deps
137
+ m = _SETUP_INSTALL_REQUIRES_RE.search(text)
138
+ if m:
139
+ for raw in re.findall(r"[\x27\x22]([^\x27\x22]+)[\x27\x22]", m.group(1)):
140
+ name_m = re.match(r"^([A-Za-z0-9_.\-]+)(.*)?$", raw.strip())
141
+ if not name_m:
142
+ continue
143
+ name = name_m.group(1)
144
+ spec = name_m.group(2).strip() if name_m.group(2) else ""
145
+ pin = _pin_status_python(spec)
146
+ deps.append(
147
+ Dependency(
148
+ name=name,
149
+ version_spec=spec,
150
+ is_dev=False,
151
+ pin_status=pin,
152
+ risk_level=_risk_level(pin, False),
153
+ source_file=source,
154
+ ecosystem="python",
155
+ )
156
+ )
157
+ return deps
158
+
159
+
160
+ def _parse_setup_cfg(path: Path, source: str) -> list[Dependency]:
161
+ deps: list[Dependency] = []
162
+ try:
163
+ text = path.read_text(encoding="utf-8", errors="replace")
164
+ except OSError:
165
+ return deps
166
+ in_install = False
167
+ in_continuation = False
168
+ for line in text.splitlines():
169
+ stripped = line.strip()
170
+ if stripped.startswith("["):
171
+ in_install = stripped == "[options]"
172
+ in_continuation = False
173
+ continue
174
+ if in_install:
175
+ if re.match(r"install_requires\s*=", stripped):
176
+ in_continuation = True
177
+ continue
178
+ if in_continuation and line.startswith((" ", " ")) and stripped and not stripped.startswith(";"):
179
+ m2 = re.match(r"^([A-Za-z0-9_.\-]+)(.*)?$", stripped)
180
+ if m2:
181
+ name = m2.group(1)
182
+ spec = m2.group(2).strip() if m2.group(2) else ""
183
+ pin = _pin_status_python(spec)
184
+ deps.append(
185
+ Dependency(
186
+ name=name,
187
+ version_spec=spec,
188
+ is_dev=False,
189
+ pin_status=pin,
190
+ risk_level=_risk_level(pin, False),
191
+ source_file=source,
192
+ ecosystem="python",
193
+ )
194
+ )
195
+ elif stripped and not line.startswith((" ", " ")):
196
+ in_continuation = False
197
+ return deps
198
+
199
+
200
+ def _parse_pyproject_toml(path: Path, source: str) -> list[Dependency]:
201
+ """Parse pyproject.toml -- [project] PEP 621 and [tool.poetry] formats."""
202
+ deps: list[Dependency] = []
203
+ try:
204
+ text = path.read_text(encoding="utf-8", errors="replace")
205
+ except OSError:
206
+ return deps
207
+
208
+ # PEP 621 [project] format
209
+ sec_m = re.search(r"^\[project\]", text, re.MULTILINE)
210
+ if sec_m:
211
+ dep_m = re.search(
212
+ r"^dependencies\s*=\s*\[([^\]]*)\]",
213
+ text[sec_m.start() :],
214
+ re.MULTILINE | re.DOTALL,
215
+ )
216
+ if dep_m:
217
+ for raw in re.findall(r"[\x27\x22]([^\x27\x22]+)[\x27\x22]", dep_m.group(1)):
218
+ raw = raw.strip()
219
+ nm = re.match(r"^([A-Za-z0-9_.\-]+)(\[.*?\])?(.*)?$", raw)
220
+ if nm:
221
+ name = nm.group(1)
222
+ spec = (nm.group(3) or "").strip()
223
+ pin = _pin_status_python(spec)
224
+ deps.append(
225
+ Dependency(
226
+ name=name,
227
+ version_spec=spec,
228
+ is_dev=False,
229
+ pin_status=pin,
230
+ risk_level=_risk_level(pin, False),
231
+ source_file=source,
232
+ ecosystem="python",
233
+ )
234
+ )
235
+ opt_m = re.search(
236
+ r"^\[project\.optional-dependencies\](.*?)(?=^\[|\Z)",
237
+ text,
238
+ re.MULTILINE | re.DOTALL,
239
+ )
240
+ if opt_m:
241
+ for raw in re.findall(r"[\x27\x22]([^\x27\x22]+)[\x27\x22]", opt_m.group(1)):
242
+ raw = raw.strip()
243
+ nm = re.match(r"^([A-Za-z0-9_.\-]+)(\[.*?\])?(.*)?$", raw)
244
+ if nm:
245
+ name = nm.group(1)
246
+ spec = (nm.group(3) or "").strip()
247
+ pin = _pin_status_python(spec)
248
+ deps.append(
249
+ Dependency(
250
+ name=name,
251
+ version_spec=spec,
252
+ is_dev=True,
253
+ pin_status=pin,
254
+ risk_level=_risk_level(pin, True),
255
+ source_file=source,
256
+ ecosystem="python",
257
+ )
258
+ )
259
+
260
+ # [tool.poetry.dependencies]
261
+ poetry_m = re.search(r"^\[tool\.poetry\.dependencies\](.*?)(?=^\[|\Z)", text, re.MULTILINE | re.DOTALL)
262
+ if poetry_m:
263
+ for line in poetry_m.group(1).splitlines():
264
+ line = line.strip()
265
+ if not line or line.startswith("#"):
266
+ continue
267
+ kv = re.match(r"^([A-Za-z0-9_.\-]+)\s*=\s*(.+)$", line)
268
+ if not kv:
269
+ continue
270
+ name = kv.group(1)
271
+ if name.lower() == "python":
272
+ continue
273
+ val = kv.group(2).strip().strip('"').strip("'")
274
+ tv = re.search(r"version\s*=\s*[\x27\x22]([^\x27\x22]+)[\x27\x22]", val)
275
+ if tv:
276
+ val = tv.group(1)
277
+ pin = _pin_status_python(val)
278
+ deps.append(
279
+ Dependency(
280
+ name=name,
281
+ version_spec=val,
282
+ is_dev=False,
283
+ pin_status=pin,
284
+ risk_level=_risk_level(pin, False),
285
+ source_file=source,
286
+ ecosystem="python",
287
+ )
288
+ )
289
+
290
+ # [tool.poetry.dev-dependencies]
291
+ poetry_dev_m = re.search(r"^\[tool\.poetry\.dev-dependencies\](.*?)(?=^\[|\Z)", text, re.MULTILINE | re.DOTALL)
292
+ if poetry_dev_m:
293
+ for line in poetry_dev_m.group(1).splitlines():
294
+ line = line.strip()
295
+ if not line or line.startswith("#"):
296
+ continue
297
+ kv = re.match(r"^([A-Za-z0-9_.\-]+)\s*=\s*(.+)$", line)
298
+ if not kv:
299
+ continue
300
+ name = kv.group(1)
301
+ val = kv.group(2).strip().strip('"').strip("'")
302
+ tv = re.search(r"version\s*=\s*[\x27\x22]([^\x27\x22]+)[\x27\x22]", val)
303
+ if tv:
304
+ val = tv.group(1)
305
+ pin = _pin_status_python(val)
306
+ deps.append(
307
+ Dependency(
308
+ name=name,
309
+ version_spec=val,
310
+ is_dev=True,
311
+ pin_status=pin,
312
+ risk_level=_risk_level(pin, True),
313
+ source_file=source,
314
+ ecosystem="python",
315
+ )
316
+ )
317
+
318
+ return deps
319
+
320
+
321
+ def _parse_package_json(path: Path, source: str) -> list[Dependency]:
322
+ import json as _json
323
+
324
+ deps: list[Dependency] = []
325
+ try:
326
+ data = _json.loads(path.read_text(encoding="utf-8", errors="replace"))
327
+ except (OSError, ValueError):
328
+ return deps
329
+ for section, is_dev in [
330
+ ("dependencies", False),
331
+ ("devDependencies", True),
332
+ ("peerDependencies", True),
333
+ ("optionalDependencies", True),
334
+ ]:
335
+ for name, spec in (data.get(section) or {}).items():
336
+ if not isinstance(spec, str):
337
+ continue
338
+ pin = _pin_status_npm(spec)
339
+ deps.append(
340
+ Dependency(
341
+ name=name,
342
+ version_spec=spec,
343
+ is_dev=is_dev,
344
+ pin_status=pin,
345
+ risk_level=_risk_level(pin, is_dev),
346
+ source_file=source,
347
+ ecosystem="javascript",
348
+ )
349
+ )
350
+ return deps
351
+
352
+
353
+ def _parse_go_mod(path: Path, source: str) -> list[Dependency]:
354
+ deps: list[Dependency] = []
355
+ try:
356
+ text = path.read_text(encoding="utf-8", errors="replace")
357
+ except OSError:
358
+ return deps
359
+ for block in re.findall(r"require\s*\((.*?)\)", text, re.DOTALL):
360
+ for line in block.splitlines():
361
+ line = line.strip()
362
+ if not line or line.startswith("//"):
363
+ continue
364
+ parts = line.split()
365
+ if len(parts) >= 2:
366
+ name, ver = parts[0], parts[1]
367
+ is_indirect = "// indirect" in line
368
+ pin = _pin_status_go(ver)
369
+ deps.append(
370
+ Dependency(
371
+ name=name,
372
+ version_spec=ver,
373
+ is_dev=is_indirect,
374
+ pin_status=pin,
375
+ risk_level=_risk_level(pin, is_indirect),
376
+ source_file=source,
377
+ ecosystem="go",
378
+ )
379
+ )
380
+ for m in re.finditer(r"^require\s+(\S+)\s+(\S+)", text, re.MULTILINE):
381
+ name, ver = m.group(1), m.group(2)
382
+ pin = _pin_status_go(ver)
383
+ deps.append(
384
+ Dependency(
385
+ name=name,
386
+ version_spec=ver,
387
+ is_dev=False,
388
+ pin_status=pin,
389
+ risk_level=_risk_level(pin, False),
390
+ source_file=source,
391
+ ecosystem="go",
392
+ )
393
+ )
394
+ return deps
395
+
396
+
397
+ def _parse_cargo_toml(path: Path, source: str) -> list[Dependency]:
398
+ deps: list[Dependency] = []
399
+ try:
400
+ text = path.read_text(encoding="utf-8", errors="replace")
401
+ except OSError:
402
+ return deps
403
+ section_re = re.compile(r"^\[([^\]]+)\]", re.MULTILINE)
404
+ sections = [(m.group(1), m.start()) for m in section_re.finditer(text)]
405
+
406
+ def _get_section_body(section_name: str) -> str:
407
+ for i, (sname, start) in enumerate(sections):
408
+ if sname.strip() == section_name:
409
+ end = sections[i + 1][1] if i + 1 < len(sections) else len(text)
410
+ return text[start:end]
411
+ return ""
412
+
413
+ for sec_name, is_dev in [
414
+ ("dependencies", False),
415
+ ("dev-dependencies", True),
416
+ ("build-dependencies", True),
417
+ ]:
418
+ body = _get_section_body(sec_name)
419
+ if not body:
420
+ continue
421
+ for line in body.splitlines():
422
+ line = line.strip()
423
+ if not line or line.startswith("#") or line.startswith("["):
424
+ continue
425
+ kv = re.match(r"^([A-Za-z0-9_\-]+)\s*=\s*(.+)$", line)
426
+ if not kv:
427
+ continue
428
+ name = kv.group(1)
429
+ val = kv.group(2).strip()
430
+ tv = re.search(r"version\s*=\s*[\x27\x22]([^\x27\x22]*)[\x27\x22]", val)
431
+ if tv:
432
+ spec = tv.group(1)
433
+ else:
434
+ spec = val.strip(chr(34)).strip(chr(39))
435
+ pin = _pin_status_rust(spec)
436
+ deps.append(
437
+ Dependency(
438
+ name=name,
439
+ version_spec=spec,
440
+ is_dev=is_dev,
441
+ pin_status=pin,
442
+ risk_level=_risk_level(pin, is_dev),
443
+ source_file=source,
444
+ ecosystem="rust",
445
+ )
446
+ )
447
+ return deps
448
+
449
+
450
+ def _parse_pom_xml(path: Path, source: str) -> list[Dependency]:
451
+ deps: list[Dependency] = []
452
+ try:
453
+ text = path.read_text(encoding="utf-8", errors="replace")
454
+ except OSError:
455
+ return deps
456
+ for dep_block in re.findall(r"<dependency>(.*?)</dependency>", text, re.DOTALL):
457
+ group_m = re.search(r"<groupId>([^<]+)</groupId>", dep_block)
458
+ art_m = re.search(r"<artifactId>([^<]+)</artifactId>", dep_block)
459
+ ver_m = re.search(r"<version>([^<]+)</version>", dep_block)
460
+ scope_m = re.search(r"<scope>([^<]+)</scope>", dep_block)
461
+ if not (group_m and art_m):
462
+ continue
463
+ name = f"{group_m.group(1).strip()}:{art_m.group(1).strip()}"
464
+ spec = ver_m.group(1).strip() if ver_m else ""
465
+ scope = (scope_m.group(1).strip() if scope_m else "compile").lower()
466
+ is_dev = scope in ("test", "provided", "system")
467
+ pin = "exact" if spec and re.match(r"^\d+\.\d+", spec) else _pin_status_python(spec)
468
+ deps.append(
469
+ Dependency(
470
+ name=name,
471
+ version_spec=spec,
472
+ is_dev=is_dev,
473
+ pin_status=pin,
474
+ risk_level=_risk_level(pin, is_dev),
475
+ source_file=source,
476
+ ecosystem="java",
477
+ )
478
+ )
479
+ return deps
480
+
481
+
482
+ def _parse_build_gradle(path: Path, source: str) -> list[Dependency]:
483
+ deps: list[Dependency] = []
484
+ try:
485
+ text = path.read_text(encoding="utf-8", errors="replace")
486
+ except OSError:
487
+ return deps
488
+ for m in re.finditer(r"(\w+)\s+[\x27\x22]([^\x27\x22]+:[^\x27\x22]+:[^\x27\x22]+)[\x27\x22]", text):
489
+ config = m.group(1).lower()
490
+ parts = m.group(2).split(":")
491
+ if len(parts) < 3:
492
+ continue
493
+ name = f"{parts[0]}:{parts[1]}"
494
+ spec = parts[2]
495
+ is_dev = config in (
496
+ "testimplementation",
497
+ "testcompile",
498
+ "testruntime",
499
+ "debugimplementation",
500
+ "androidtestimplementation",
501
+ )
502
+ pin = "exact" if re.match(r"^\d+\.\d+", spec) else "range"
503
+ deps.append(
504
+ Dependency(
505
+ name=name,
506
+ version_spec=spec,
507
+ is_dev=is_dev,
508
+ pin_status=pin,
509
+ risk_level=_risk_level(pin, is_dev),
510
+ source_file=source,
511
+ ecosystem="java",
512
+ )
513
+ )
514
+ return deps
515
+
516
+
517
+ def _parse_gemfile(path: Path, source: str) -> list[Dependency]:
518
+ deps: list[Dependency] = []
519
+ try:
520
+ text = path.read_text(encoding="utf-8", errors="replace")
521
+ except OSError:
522
+ return deps
523
+ in_test_group = False
524
+ for line in text.splitlines():
525
+ stripped = line.strip()
526
+ if re.match(r"group\s+.*:(?:test|development|staging)", stripped):
527
+ in_test_group = True
528
+ if stripped == "end" and in_test_group:
529
+ in_test_group = False
530
+ continue
531
+ if stripped.startswith("#"):
532
+ continue
533
+ m = re.match(
534
+ r"gem\s+[\x27\x22]([^\x27\x22]+)[\x27\x22](?:,\s*[\x27\x22]([^\x27\x22]*)[\x27\x22])?",
535
+ stripped,
536
+ )
537
+ if not m:
538
+ continue
539
+ name = m.group(1)
540
+ spec = m.group(2) or ""
541
+ pin = _pin_status_ruby(spec)
542
+ deps.append(
543
+ Dependency(
544
+ name=name,
545
+ version_spec=spec,
546
+ is_dev=in_test_group,
547
+ pin_status=pin,
548
+ risk_level=_risk_level(pin, in_test_group),
549
+ source_file=source,
550
+ ecosystem="ruby",
551
+ )
552
+ )
553
+ return deps
554
+
555
+
556
+ _DEP_FILES: dict[str, tuple] = {
557
+ "requirements.txt": (_parse_requirements_txt, "python"),
558
+ "requirements-dev.txt": (_parse_requirements_txt, "python"),
559
+ "requirements_dev.txt": (_parse_requirements_txt, "python"),
560
+ "requirements-test.txt": (_parse_requirements_txt, "python"),
561
+ "constraints.txt": (_parse_requirements_txt, "python"),
562
+ "setup.py": (_parse_setup_py, "python"),
563
+ "setup.cfg": (_parse_setup_cfg, "python"),
564
+ "pyproject.toml": (_parse_pyproject_toml, "python"),
565
+ "package.json": (_parse_package_json, "javascript"),
566
+ "go.mod": (_parse_go_mod, "go"),
567
+ "Cargo.toml": (_parse_cargo_toml, "rust"),
568
+ "pom.xml": (_parse_pom_xml, "java"),
569
+ "build.gradle": (_parse_build_gradle, "java"),
570
+ "build.gradle.kts": (_parse_build_gradle, "java"),
571
+ "Gemfile": (_parse_gemfile, "ruby"),
572
+ }
573
+
574
+
575
+ _DEV_FILE_MARKERS = frozenset(
576
+ [
577
+ "requirements-dev.txt",
578
+ "requirements_dev.txt",
579
+ "requirements-test.txt",
580
+ "requirements-ci.txt",
581
+ ]
582
+ )
583
+
584
+
585
+ def discover_and_parse(project_root: Path) -> list[Dependency]:
586
+ all_deps: list[Dependency] = []
587
+ for filename, (parser_fn, _eco) in _DEP_FILES.items():
588
+ candidate = project_root / filename
589
+ if candidate.is_file():
590
+ parsed = parser_fn(candidate, filename)
591
+ if filename in _DEV_FILE_MARKERS:
592
+ parsed = [d._replace(is_dev=True) for d in parsed]
593
+ all_deps.extend(parsed)
594
+ seen: set[tuple[str, str, str]] = set()
595
+ unique: list[Dependency] = []
596
+ for dep in all_deps:
597
+ key = (dep.name.lower(), dep.ecosystem, dep.source_file)
598
+ if key not in seen:
599
+ seen.add(key)
600
+ unique.append(dep)
601
+ return unique
602
+
603
+
604
+ def compute_risk_score(deps: list[Dependency]) -> dict:
605
+ if not deps:
606
+ return dict(
607
+ score=100,
608
+ pin_coverage=1.0,
609
+ dev_ratio=0.0,
610
+ total=0,
611
+ direct_count=0,
612
+ dev_count=0,
613
+ exact_count=0,
614
+ range_count=0,
615
+ unpinned_count=0,
616
+ )
617
+ total = len(deps)
618
+ direct = [d for d in deps if not d.is_dev]
619
+ dev = [d for d in deps if d.is_dev]
620
+ exact = sum(1 for d in deps if d.pin_status == "exact")
621
+ rng = sum(1 for d in deps if d.pin_status == "range")
622
+ unpinned = sum(1 for d in deps if d.pin_status == "unpinned")
623
+ pin_coverage = exact / total
624
+ dev_ratio = len(dev) / total
625
+ diversity_penalty = 1.0 - (unpinned / total)
626
+ raw = pin_coverage * 0.6 + dev_ratio * 0.2 + diversity_penalty * 0.2
627
+ score = max(0, min(100, round(raw * 100)))
628
+ return dict(
629
+ score=score,
630
+ pin_coverage=round(pin_coverage, 4),
631
+ dev_ratio=round(dev_ratio, 4),
632
+ total=total,
633
+ direct_count=len(direct),
634
+ dev_count=len(dev),
635
+ exact_count=exact,
636
+ range_count=rng,
637
+ unpinned_count=unpinned,
638
+ )
639
+
640
+
641
+ def top_risky(deps: list[Dependency], n: int = 5) -> list[Dependency]:
642
+ _pin_rank = {"unpinned": 2, "range": 1, "exact": 0}
643
+ return sorted(deps, key=lambda d: (_pin_rank[d.pin_status], not d.is_dev), reverse=True)[:n]
644
+
645
+
646
+ def supply_chain_to_sarif(deps: list[Dependency], score: int) -> dict:
647
+ rules = [
648
+ {
649
+ "id": "supply-chain/unpinned-dependency",
650
+ "shortDescription": "Dependency has no version pin",
651
+ "helpUri": "https://github.com/AbanteAI/roam-code#supply-chain",
652
+ "defaultLevel": "warning",
653
+ },
654
+ {
655
+ "id": "supply-chain/range-dependency",
656
+ "shortDescription": "Dependency uses a version range instead of exact pin",
657
+ "helpUri": "https://github.com/AbanteAI/roam-code#supply-chain",
658
+ "defaultLevel": "note",
659
+ },
660
+ ]
661
+ results = []
662
+ for dep in deps:
663
+ if dep.pin_status == "exact":
664
+ continue
665
+ rule_id = (
666
+ "supply-chain/unpinned-dependency" if dep.pin_status == "unpinned" else "supply-chain/range-dependency"
667
+ )
668
+ level = "warning" if dep.pin_status == "unpinned" else "note"
669
+ spec_str = f" ({dep.version_spec})" if dep.version_spec else ""
670
+ dev_str = " [dev]" if dep.is_dev else ""
671
+ results.append(
672
+ {
673
+ "ruleId": rule_id,
674
+ "level": level,
675
+ "message": {
676
+ "text": (
677
+ f"{dep.name}{spec_str} in {dep.source_file} -- {dep.pin_status}{dev_str} ({dep.ecosystem})"
678
+ )
679
+ },
680
+ "locations": [{"physicalLocation": {"artifactLocation": {"uri": dep.source_file.replace("\\", "/")}}}],
681
+ }
682
+ )
683
+ return to_sarif("roam-code", __version__, rules, results)
684
+
685
+
686
+ @click.command("supply-chain")
687
+ @click.option("--top", default=5, show_default=True, help="Number of riskiest dependencies to highlight")
688
+ @click.pass_context
689
+ def supply_chain(ctx, top):
690
+ """Dependency risk dashboard: pin coverage, risk scoring, supply-chain health."""
691
+ json_mode = ctx.obj.get("json") if ctx.obj else False
692
+ sarif_mode = ctx.obj.get("sarif") if ctx.obj else False
693
+ token_budget = ctx.obj.get("budget", 0) if ctx.obj else 0
694
+
695
+ try:
696
+ project_root = find_project_root()
697
+ except Exception:
698
+ project_root = Path.cwd()
699
+
700
+ deps = discover_and_parse(project_root)
701
+ metrics = compute_risk_score(deps)
702
+ score = metrics["score"]
703
+ risky = top_risky(deps, top)
704
+ found_files = sorted({d.source_file for d in deps})
705
+ ecosystems: dict[str, int] = {}
706
+ for d in deps:
707
+ ecosystems[d.ecosystem] = ecosystems.get(d.ecosystem, 0) + 1
708
+ if not deps:
709
+ verdict = "No dependency files found"
710
+ elif score >= 80:
711
+ _pct = int(metrics["pin_coverage"] * 100)
712
+ verdict = f"Supply chain healthy ({score}/100) -- {_pct}% pinned"
713
+ elif score >= 60:
714
+ _u = metrics["unpinned_count"]
715
+ _r = metrics["range_count"]
716
+ verdict = f"Supply chain fair ({score}/100) -- {_u} unpinned, {_r} ranges"
717
+ else:
718
+ _u = metrics["unpinned_count"]
719
+ verdict = f"Supply chain risky ({score}/100) -- {_u} unpinned dependencies"
720
+
721
+ if sarif_mode:
722
+ sarif = supply_chain_to_sarif(deps, score)
723
+ click.echo(write_sarif(sarif))
724
+ return
725
+
726
+ if json_mode:
727
+ envelope = json_envelope(
728
+ "supply-chain",
729
+ summary=dict(
730
+ verdict=verdict,
731
+ risk_score=score,
732
+ total_dependencies=metrics["total"],
733
+ direct_count=metrics["direct_count"],
734
+ dev_count=metrics["dev_count"],
735
+ pin_coverage_pct=round(metrics["pin_coverage"] * 100, 1),
736
+ unpinned_count=metrics["unpinned_count"],
737
+ range_count=metrics["range_count"],
738
+ exact_count=metrics["exact_count"],
739
+ files_scanned=found_files,
740
+ ecosystems=ecosystems,
741
+ ),
742
+ budget=token_budget,
743
+ risk_score=score,
744
+ total_dependencies=metrics["total"],
745
+ direct_count=metrics["direct_count"],
746
+ dev_count=metrics["dev_count"],
747
+ exact_count=metrics["exact_count"],
748
+ range_count=metrics["range_count"],
749
+ unpinned_count=metrics["unpinned_count"],
750
+ pin_coverage_pct=round(metrics["pin_coverage"] * 100, 1),
751
+ files_scanned=found_files,
752
+ ecosystems=ecosystems,
753
+ top_risky=[
754
+ dict(
755
+ name=d.name,
756
+ version_spec=d.version_spec,
757
+ pin_status=d.pin_status,
758
+ risk_level=d.risk_level,
759
+ is_dev=d.is_dev,
760
+ ecosystem=d.ecosystem,
761
+ source_file=d.source_file,
762
+ )
763
+ for d in risky
764
+ ],
765
+ all_dependencies=[
766
+ dict(
767
+ name=d.name,
768
+ version_spec=d.version_spec,
769
+ pin_status=d.pin_status,
770
+ risk_level=d.risk_level,
771
+ is_dev=d.is_dev,
772
+ ecosystem=d.ecosystem,
773
+ source_file=d.source_file,
774
+ )
775
+ for d in deps
776
+ ],
777
+ )
778
+ click.echo(to_json(envelope))
779
+ return
780
+
781
+ click.echo(f"VERDICT: {verdict}")
782
+ click.echo()
783
+
784
+ if not deps:
785
+ click.echo(" No dependency files found.")
786
+ return
787
+
788
+ _t = metrics["total"]
789
+ _dc = metrics["direct_count"]
790
+ _dv = metrics["dev_count"]
791
+ _pct = int(metrics["pin_coverage"] * 100)
792
+ _ex = metrics["exact_count"]
793
+ _rng = metrics["range_count"]
794
+ _unp = metrics["unpinned_count"]
795
+ click.echo(f"Risk Score: {score}/100 | Total: {_t} | Direct: {_dc} | Dev: {_dv}")
796
+ click.echo(f"Pin Coverage: {_pct}% | Exact: {_ex} | Range: {_rng} | Unpinned: {_unp}")
797
+ if found_files:
798
+ click.echo("Files: " + ", ".join(found_files))
799
+ if ecosystems:
800
+ eco_str = " ".join(f"{k}:{v}" for k, v in sorted(ecosystems.items()))
801
+ click.echo(f"Ecosystems: {eco_str}")
802
+ click.echo()
803
+
804
+ if risky:
805
+ _topn = min(top, len(risky))
806
+ click.echo(f"=== Top {_topn} Riskiest Dependencies ===")
807
+ rows = []
808
+ for d in risky:
809
+ spec = d.version_spec if d.version_spec else "(none)"
810
+ dev_str = "dev" if d.is_dev else "direct"
811
+ rows.append([d.name, spec, d.pin_status, d.risk_level, dev_str, d.ecosystem, d.source_file])
812
+ click.echo(
813
+ format_table(
814
+ ["Name", "Version Spec", "Pin Status", "Risk", "Type", "Ecosystem", "File"],
815
+ rows,
816
+ )
817
+ )
818
+ click.echo()
819
+
820
+ recs = []
821
+ if metrics["unpinned_count"] > 0:
822
+ _u = metrics["unpinned_count"]
823
+ recs.append(f"Pin {_u} unpinned dependencies to exact versions")
824
+ if metrics["range_count"] > 5:
825
+ _r = metrics["range_count"]
826
+ recs.append(f"Consider pinning {_r} range-versioned dependencies")
827
+ if not recs:
828
+ recs.append("Dependency pinning looks good")
829
+ click.echo("Recommendations:")
830
+ for rec in recs:
831
+ click.echo(f" - {rec}")