codegraph-ir 0.1.0__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 (63) hide show
  1. cgir/__init__.py +6 -0
  2. cgir/analyses/__init__.py +7 -0
  3. cgir/analyses/call_graph.py +114 -0
  4. cgir/analyses/cfg.py +320 -0
  5. cgir/analyses/effects.py +95 -0
  6. cgir/analyses/entrypoints.py +55 -0
  7. cgir/analyses/param_flow.py +75 -0
  8. cgir/analyses/pdg.py +75 -0
  9. cgir/analyses/purity.py +37 -0
  10. cgir/analyses/reaching_defs.py +115 -0
  11. cgir/analyses/symbols.py +106 -0
  12. cgir/api/__init__.py +1 -0
  13. cgir/api/mcp_server.py +172 -0
  14. cgir/api/server.py +107 -0
  15. cgir/cli.py +688 -0
  16. cgir/config.py +22 -0
  17. cgir/export/__init__.py +5 -0
  18. cgir/export/graphml.py +52 -0
  19. cgir/export/html_viz.py +1087 -0
  20. cgir/export/json_export.py +37 -0
  21. cgir/export/mermaid.py +57 -0
  22. cgir/export/neo4j.py +11 -0
  23. cgir/hooks.py +189 -0
  24. cgir/ir/__init__.py +16 -0
  25. cgir/ir/component_spec.py +100 -0
  26. cgir/ir/edges.py +31 -0
  27. cgir/ir/graph.py +132 -0
  28. cgir/ir/nodes.py +38 -0
  29. cgir/languages/__init__.py +25 -0
  30. cgir/languages/base.py +221 -0
  31. cgir/languages/cache.py +73 -0
  32. cgir/languages/python.py +1145 -0
  33. cgir/languages/registry.py +24 -0
  34. cgir/languages/typescript.py +853 -0
  35. cgir/manifest.py +77 -0
  36. cgir/pipeline.py +54 -0
  37. cgir/py.typed +0 -0
  38. cgir/regenerate/__init__.py +6 -0
  39. cgir/regenerate/prompt_pack.py +16 -0
  40. cgir/regenerate/regenerator.py +108 -0
  41. cgir/report/__init__.py +5 -0
  42. cgir/report/diff.py +226 -0
  43. cgir/report/flow.py +84 -0
  44. cgir/report/impact.py +234 -0
  45. cgir/report/lint.py +84 -0
  46. cgir/report/pack.py +271 -0
  47. cgir/report/stats.py +121 -0
  48. cgir/slicing/__init__.py +5 -0
  49. cgir/slicing/slicer.py +174 -0
  50. cgir/sources/__init__.py +6 -0
  51. cgir/sources/base.py +14 -0
  52. cgir/sources/codeql_source.py +13 -0
  53. cgir/sources/joern_source.py +13 -0
  54. cgir/sources/tree_sitter_source.py +270 -0
  55. cgir/trace/__init__.py +5 -0
  56. cgir/trace/trace_map.py +83 -0
  57. cgir/verify.py +173 -0
  58. cgir/watch.py +171 -0
  59. codegraph_ir-0.1.0.dist-info/METADATA +143 -0
  60. codegraph_ir-0.1.0.dist-info/RECORD +63 -0
  61. codegraph_ir-0.1.0.dist-info/WHEEL +4 -0
  62. codegraph_ir-0.1.0.dist-info/entry_points.txt +2 -0
  63. codegraph_ir-0.1.0.dist-info/licenses/LICENSE +21 -0
cgir/config.py ADDED
@@ -0,0 +1,22 @@
1
+ """Runtime configuration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ from pydantic import BaseModel, Field
8
+
9
+
10
+ class CGIRConfig(BaseModel):
11
+ repo_path: Path
12
+ out_dir: Path = Field(default_factory=lambda: Path(".cgir"))
13
+ target_languages: list[str] = Field(default_factory=lambda: ["python"])
14
+ source_backend: str = "tree-sitter"
15
+
16
+ @classmethod
17
+ def for_scan(cls, repo_path: Path, out_dir: Path | None = None) -> CGIRConfig:
18
+ repo_path = repo_path.resolve()
19
+ return cls(
20
+ repo_path=repo_path,
21
+ out_dir=(out_dir or repo_path / ".cgir").resolve(),
22
+ )
@@ -0,0 +1,5 @@
1
+ """Export passes: json (working), graphml (P2 stub), neo4j (P2 stub)."""
2
+
3
+ from cgir.export.json_export import write_index
4
+
5
+ __all__ = ["write_index"]
cgir/export/graphml.py ADDED
@@ -0,0 +1,52 @@
1
+ """GraphML export — opens the RepoGraph in Gephi, yEd, or Cytoscape.
2
+
3
+ GraphML attribute values must be scalars, so list/dict attrs are
4
+ JSON-encoded strings and ``None`` attrs are dropped. ``kind`` carries the
5
+ Node/Edge enum value.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ from pathlib import Path
12
+
13
+ import networkx as nx
14
+
15
+ from cgir.ir.graph import RepoGraph
16
+
17
+
18
+ def write(out_dir: Path, graph: RepoGraph) -> Path:
19
+ """Write ``<out_dir>/repo_graph.graphml`` and return its path."""
20
+ out_dir.mkdir(parents=True, exist_ok=True)
21
+ flat: nx.MultiDiGraph = nx.MultiDiGraph()
22
+ for node in graph.nodes():
23
+ attrs: dict[str, str | int | float | bool] = {
24
+ "kind": node.kind.value,
25
+ "name": node.name,
26
+ }
27
+ if node.path is not None:
28
+ attrs["path"] = node.path
29
+ if node.start_line is not None:
30
+ attrs["start_line"] = node.start_line
31
+ if node.end_line is not None:
32
+ attrs["end_line"] = node.end_line
33
+ for key, value in node.attrs.items():
34
+ scalar = _to_scalar(value)
35
+ if scalar is not None:
36
+ attrs[key] = scalar
37
+ flat.add_node(node.id, **attrs)
38
+ for node in graph.nodes():
39
+ for edge in graph.out_edges(node.id):
40
+ flat.add_edge(edge.src, edge.dst, kind=edge.kind.value)
41
+
42
+ path = out_dir / "repo_graph.graphml"
43
+ nx.write_graphml(flat, path)
44
+ return path
45
+
46
+
47
+ def _to_scalar(value: object) -> str | int | float | bool | None:
48
+ if value is None:
49
+ return None
50
+ if isinstance(value, str | int | float | bool):
51
+ return value
52
+ return json.dumps(value)