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.
- cgir/__init__.py +6 -0
- cgir/analyses/__init__.py +7 -0
- cgir/analyses/call_graph.py +114 -0
- cgir/analyses/cfg.py +320 -0
- cgir/analyses/effects.py +95 -0
- cgir/analyses/entrypoints.py +55 -0
- cgir/analyses/param_flow.py +75 -0
- cgir/analyses/pdg.py +75 -0
- cgir/analyses/purity.py +37 -0
- cgir/analyses/reaching_defs.py +115 -0
- cgir/analyses/symbols.py +106 -0
- cgir/api/__init__.py +1 -0
- cgir/api/mcp_server.py +172 -0
- cgir/api/server.py +107 -0
- cgir/cli.py +688 -0
- cgir/config.py +22 -0
- cgir/export/__init__.py +5 -0
- cgir/export/graphml.py +52 -0
- cgir/export/html_viz.py +1087 -0
- cgir/export/json_export.py +37 -0
- cgir/export/mermaid.py +57 -0
- cgir/export/neo4j.py +11 -0
- cgir/hooks.py +189 -0
- cgir/ir/__init__.py +16 -0
- cgir/ir/component_spec.py +100 -0
- cgir/ir/edges.py +31 -0
- cgir/ir/graph.py +132 -0
- cgir/ir/nodes.py +38 -0
- cgir/languages/__init__.py +25 -0
- cgir/languages/base.py +221 -0
- cgir/languages/cache.py +73 -0
- cgir/languages/python.py +1145 -0
- cgir/languages/registry.py +24 -0
- cgir/languages/typescript.py +853 -0
- cgir/manifest.py +77 -0
- cgir/pipeline.py +54 -0
- cgir/py.typed +0 -0
- cgir/regenerate/__init__.py +6 -0
- cgir/regenerate/prompt_pack.py +16 -0
- cgir/regenerate/regenerator.py +108 -0
- cgir/report/__init__.py +5 -0
- cgir/report/diff.py +226 -0
- cgir/report/flow.py +84 -0
- cgir/report/impact.py +234 -0
- cgir/report/lint.py +84 -0
- cgir/report/pack.py +271 -0
- cgir/report/stats.py +121 -0
- cgir/slicing/__init__.py +5 -0
- cgir/slicing/slicer.py +174 -0
- cgir/sources/__init__.py +6 -0
- cgir/sources/base.py +14 -0
- cgir/sources/codeql_source.py +13 -0
- cgir/sources/joern_source.py +13 -0
- cgir/sources/tree_sitter_source.py +270 -0
- cgir/trace/__init__.py +5 -0
- cgir/trace/trace_map.py +83 -0
- cgir/verify.py +173 -0
- cgir/watch.py +171 -0
- codegraph_ir-0.1.0.dist-info/METADATA +143 -0
- codegraph_ir-0.1.0.dist-info/RECORD +63 -0
- codegraph_ir-0.1.0.dist-info/WHEEL +4 -0
- codegraph_ir-0.1.0.dist-info/entry_points.txt +2 -0
- 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
|
+
)
|
cgir/export/__init__.py
ADDED
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)
|