codegraph-ir 0.1.0__tar.gz

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 (128) hide show
  1. codegraph_ir-0.1.0/.github/workflows/ci.yml +29 -0
  2. codegraph_ir-0.1.0/.github/workflows/release.yml +62 -0
  3. codegraph_ir-0.1.0/.gitignore +221 -0
  4. codegraph_ir-0.1.0/.pre-commit-config.yaml +16 -0
  5. codegraph_ir-0.1.0/.python-version +1 -0
  6. codegraph_ir-0.1.0/CLAUDE.md +38 -0
  7. codegraph_ir-0.1.0/Code-IR.md +122 -0
  8. codegraph_ir-0.1.0/LICENSE +21 -0
  9. codegraph_ir-0.1.0/PKG-INFO +143 -0
  10. codegraph_ir-0.1.0/README.md +77 -0
  11. codegraph_ir-0.1.0/RELEASING.md +73 -0
  12. codegraph_ir-0.1.0/action.yml +99 -0
  13. codegraph_ir-0.1.0/docs/README.md +19 -0
  14. codegraph_ir-0.1.0/docs/architecture-rules.md +60 -0
  15. codegraph_ir-0.1.0/docs/architecture.md +141 -0
  16. codegraph_ir-0.1.0/docs/development.md +110 -0
  17. codegraph_ir-0.1.0/docs/experiment-log.md +204 -0
  18. codegraph_ir-0.1.0/docs/feature-research.md +308 -0
  19. codegraph_ir-0.1.0/docs/gate-noise.md +95 -0
  20. codegraph_ir-0.1.0/docs/github-action.md +94 -0
  21. codegraph_ir-0.1.0/docs/languages.md +67 -0
  22. codegraph_ir-0.1.0/docs/roadmap.md +86 -0
  23. codegraph_ir-0.1.0/docs/status.md +162 -0
  24. codegraph_ir-0.1.0/docs/strategy.md +102 -0
  25. codegraph_ir-0.1.0/examples/agent-pr-contract-drift.md +83 -0
  26. codegraph_ir-0.1.0/pyproject.toml +102 -0
  27. codegraph_ir-0.1.0/schemas/component_spec.schema.json +113 -0
  28. codegraph_ir-0.1.0/src/cgir/__init__.py +6 -0
  29. codegraph_ir-0.1.0/src/cgir/analyses/__init__.py +7 -0
  30. codegraph_ir-0.1.0/src/cgir/analyses/call_graph.py +114 -0
  31. codegraph_ir-0.1.0/src/cgir/analyses/cfg.py +320 -0
  32. codegraph_ir-0.1.0/src/cgir/analyses/effects.py +95 -0
  33. codegraph_ir-0.1.0/src/cgir/analyses/entrypoints.py +55 -0
  34. codegraph_ir-0.1.0/src/cgir/analyses/param_flow.py +75 -0
  35. codegraph_ir-0.1.0/src/cgir/analyses/pdg.py +75 -0
  36. codegraph_ir-0.1.0/src/cgir/analyses/purity.py +37 -0
  37. codegraph_ir-0.1.0/src/cgir/analyses/reaching_defs.py +115 -0
  38. codegraph_ir-0.1.0/src/cgir/analyses/symbols.py +106 -0
  39. codegraph_ir-0.1.0/src/cgir/api/__init__.py +1 -0
  40. codegraph_ir-0.1.0/src/cgir/api/mcp_server.py +172 -0
  41. codegraph_ir-0.1.0/src/cgir/api/server.py +107 -0
  42. codegraph_ir-0.1.0/src/cgir/cli.py +688 -0
  43. codegraph_ir-0.1.0/src/cgir/config.py +22 -0
  44. codegraph_ir-0.1.0/src/cgir/export/__init__.py +5 -0
  45. codegraph_ir-0.1.0/src/cgir/export/graphml.py +52 -0
  46. codegraph_ir-0.1.0/src/cgir/export/html_viz.py +1087 -0
  47. codegraph_ir-0.1.0/src/cgir/export/json_export.py +37 -0
  48. codegraph_ir-0.1.0/src/cgir/export/mermaid.py +57 -0
  49. codegraph_ir-0.1.0/src/cgir/export/neo4j.py +11 -0
  50. codegraph_ir-0.1.0/src/cgir/hooks.py +189 -0
  51. codegraph_ir-0.1.0/src/cgir/ir/__init__.py +16 -0
  52. codegraph_ir-0.1.0/src/cgir/ir/component_spec.py +100 -0
  53. codegraph_ir-0.1.0/src/cgir/ir/edges.py +31 -0
  54. codegraph_ir-0.1.0/src/cgir/ir/graph.py +132 -0
  55. codegraph_ir-0.1.0/src/cgir/ir/nodes.py +38 -0
  56. codegraph_ir-0.1.0/src/cgir/languages/__init__.py +25 -0
  57. codegraph_ir-0.1.0/src/cgir/languages/base.py +221 -0
  58. codegraph_ir-0.1.0/src/cgir/languages/cache.py +73 -0
  59. codegraph_ir-0.1.0/src/cgir/languages/python.py +1145 -0
  60. codegraph_ir-0.1.0/src/cgir/languages/registry.py +24 -0
  61. codegraph_ir-0.1.0/src/cgir/languages/typescript.py +853 -0
  62. codegraph_ir-0.1.0/src/cgir/manifest.py +77 -0
  63. codegraph_ir-0.1.0/src/cgir/pipeline.py +54 -0
  64. codegraph_ir-0.1.0/src/cgir/py.typed +0 -0
  65. codegraph_ir-0.1.0/src/cgir/regenerate/__init__.py +6 -0
  66. codegraph_ir-0.1.0/src/cgir/regenerate/prompt_pack.py +16 -0
  67. codegraph_ir-0.1.0/src/cgir/regenerate/regenerator.py +108 -0
  68. codegraph_ir-0.1.0/src/cgir/report/__init__.py +5 -0
  69. codegraph_ir-0.1.0/src/cgir/report/diff.py +226 -0
  70. codegraph_ir-0.1.0/src/cgir/report/flow.py +84 -0
  71. codegraph_ir-0.1.0/src/cgir/report/impact.py +234 -0
  72. codegraph_ir-0.1.0/src/cgir/report/lint.py +84 -0
  73. codegraph_ir-0.1.0/src/cgir/report/pack.py +271 -0
  74. codegraph_ir-0.1.0/src/cgir/report/stats.py +121 -0
  75. codegraph_ir-0.1.0/src/cgir/slicing/__init__.py +5 -0
  76. codegraph_ir-0.1.0/src/cgir/slicing/slicer.py +174 -0
  77. codegraph_ir-0.1.0/src/cgir/sources/__init__.py +6 -0
  78. codegraph_ir-0.1.0/src/cgir/sources/base.py +14 -0
  79. codegraph_ir-0.1.0/src/cgir/sources/codeql_source.py +13 -0
  80. codegraph_ir-0.1.0/src/cgir/sources/joern_source.py +13 -0
  81. codegraph_ir-0.1.0/src/cgir/sources/tree_sitter_source.py +270 -0
  82. codegraph_ir-0.1.0/src/cgir/trace/__init__.py +5 -0
  83. codegraph_ir-0.1.0/src/cgir/trace/trace_map.py +83 -0
  84. codegraph_ir-0.1.0/src/cgir/verify.py +173 -0
  85. codegraph_ir-0.1.0/src/cgir/watch.py +171 -0
  86. codegraph_ir-0.1.0/tests/__init__.py +0 -0
  87. codegraph_ir-0.1.0/tests/conftest.py +12 -0
  88. codegraph_ir-0.1.0/tests/fixtures/python_sample/orchestrator.py +5 -0
  89. codegraph_ir-0.1.0/tests/fixtures/python_sample/pricing.py +2 -0
  90. codegraph_ir-0.1.0/tests/fixtures/ts_sample/api/service.ts +17 -0
  91. codegraph_ir-0.1.0/tests/fixtures/ts_sample/util.ts +6 -0
  92. codegraph_ir-0.1.0/tests/integration/__init__.py +0 -0
  93. codegraph_ir-0.1.0/tests/integration/test_api.py +97 -0
  94. codegraph_ir-0.1.0/tests/integration/test_cli_scan.py +275 -0
  95. codegraph_ir-0.1.0/tests/integration/test_hook.py +120 -0
  96. codegraph_ir-0.1.0/tests/unit/__init__.py +0 -0
  97. codegraph_ir-0.1.0/tests/unit/test_action.py +46 -0
  98. codegraph_ir-0.1.0/tests/unit/test_call_graph.py +36 -0
  99. codegraph_ir-0.1.0/tests/unit/test_cfg.py +869 -0
  100. codegraph_ir-0.1.0/tests/unit/test_component_spec.py +106 -0
  101. codegraph_ir-0.1.0/tests/unit/test_diff.py +237 -0
  102. codegraph_ir-0.1.0/tests/unit/test_effects.py +475 -0
  103. codegraph_ir-0.1.0/tests/unit/test_entrypoints.py +57 -0
  104. codegraph_ir-0.1.0/tests/unit/test_graphml.py +71 -0
  105. codegraph_ir-0.1.0/tests/unit/test_html_viz.py +135 -0
  106. codegraph_ir-0.1.0/tests/unit/test_impact.py +192 -0
  107. codegraph_ir-0.1.0/tests/unit/test_ir_graph.py +50 -0
  108. codegraph_ir-0.1.0/tests/unit/test_language_adapter.py +63 -0
  109. codegraph_ir-0.1.0/tests/unit/test_lint.py +83 -0
  110. codegraph_ir-0.1.0/tests/unit/test_manifest.py +55 -0
  111. codegraph_ir-0.1.0/tests/unit/test_mcp_tools.py +140 -0
  112. codegraph_ir-0.1.0/tests/unit/test_mermaid.py +83 -0
  113. codegraph_ir-0.1.0/tests/unit/test_pack.py +213 -0
  114. codegraph_ir-0.1.0/tests/unit/test_param_flow.py +125 -0
  115. codegraph_ir-0.1.0/tests/unit/test_pdg.py +273 -0
  116. codegraph_ir-0.1.0/tests/unit/test_purity.py +116 -0
  117. codegraph_ir-0.1.0/tests/unit/test_python_di.py +114 -0
  118. codegraph_ir-0.1.0/tests/unit/test_reaching_defs.py +277 -0
  119. codegraph_ir-0.1.0/tests/unit/test_regenerator.py +76 -0
  120. codegraph_ir-0.1.0/tests/unit/test_slicer.py +266 -0
  121. codegraph_ir-0.1.0/tests/unit/test_source_cache.py +32 -0
  122. codegraph_ir-0.1.0/tests/unit/test_stats.py +129 -0
  123. codegraph_ir-0.1.0/tests/unit/test_symbols.py +241 -0
  124. codegraph_ir-0.1.0/tests/unit/test_trace_map.py +11 -0
  125. codegraph_ir-0.1.0/tests/unit/test_tree_sitter_source.py +292 -0
  126. codegraph_ir-0.1.0/tests/unit/test_typescript_adapter.py +200 -0
  127. codegraph_ir-0.1.0/tests/unit/test_verify.py +122 -0
  128. codegraph_ir-0.1.0/tests/unit/test_watch.py +84 -0
@@ -0,0 +1,29 @@
1
+ name: ci
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.11", "3.12"]
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: astral-sh/setup-uv@v3
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ - name: Install
21
+ run: uv pip install --system -e ".[dev,api]"
22
+ - name: Lint
23
+ run: ruff check .
24
+ - name: Format check
25
+ run: ruff format --check .
26
+ - name: Typecheck
27
+ run: mypy src
28
+ - name: Test
29
+ run: pytest -q
@@ -0,0 +1,62 @@
1
+ name: release
2
+
3
+ # Publish codegraph-ir to PyPI on a version tag, via trusted publishing
4
+ # (OIDC — no token stored in the repo). One-time setup on PyPI:
5
+ # project "codegraph-ir" -> Publishing -> add GitHub publisher for
6
+ # asonkiya/llm-semantic-compilers, workflow release.yml, environment pypi.
7
+
8
+ on:
9
+ push:
10
+ tags: ["v*"]
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: astral-sh/setup-uv@v3
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.12"
21
+
22
+ - name: Gate (tests + lint + types)
23
+ run: |
24
+ uv pip install --system -e ".[dev,api]"
25
+ ruff check . && ruff format --check . && mypy src && pytest -q
26
+
27
+ - name: Tag matches package version
28
+ run: |
29
+ PKG=$(python -c 'import cgir; print(cgir.__version__)')
30
+ TAG="${GITHUB_REF_NAME#v}"
31
+ if [ "$PKG" != "$TAG" ]; then
32
+ echo "::error::tag v$TAG != cgir.__version__ $PKG"; exit 1
33
+ fi
34
+
35
+ - name: Build sdist + wheel
36
+ run: uv build
37
+
38
+ - name: Smoke-test the wheel in a clean env
39
+ run: |
40
+ uv venv /tmp/rel
41
+ uv pip install --python /tmp/rel/bin/python dist/*.whl
42
+ /tmp/rel/bin/cgir --version
43
+ mkdir -p /tmp/proj && printf 'def f(x):\n return x\n' > /tmp/proj/m.py
44
+ cd /tmp/proj && /tmp/rel/bin/cgir scan . --out .cgir && /tmp/rel/bin/cgir impact m.f --index .cgir
45
+
46
+ - uses: actions/upload-artifact@v4
47
+ with:
48
+ name: dist
49
+ path: dist/
50
+
51
+ publish:
52
+ needs: build
53
+ runs-on: ubuntu-latest
54
+ environment: pypi
55
+ permissions:
56
+ id-token: write # trusted publishing (OIDC)
57
+ steps:
58
+ - uses: actions/download-artifact@v4
59
+ with:
60
+ name: dist
61
+ path: dist/
62
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,221 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml
219
+
220
+ # CGIR scan output
221
+ .cgir/
@@ -0,0 +1,16 @@
1
+ repos:
2
+ - repo: https://github.com/astral-sh/ruff-pre-commit
3
+ rev: v0.5.7
4
+ hooks:
5
+ - id: ruff
6
+ args: [--fix]
7
+ - id: ruff-format
8
+ - repo: https://github.com/pre-commit/mirrors-mypy
9
+ rev: v1.10.0
10
+ hooks:
11
+ - id: mypy
12
+ args: [--config-file=pyproject.toml]
13
+ additional_dependencies:
14
+ - pydantic>=2.6
15
+ - types-jsonschema
16
+ files: ^src/
@@ -0,0 +1 @@
1
+ 3.11
@@ -0,0 +1,38 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Where the docs live
6
+
7
+ - [`Code-IR.md`](./Code-IR.md) — authoritative product specification.
8
+ - [`docs/`](./docs/) — working docs for engineers and Claude. Start at [`docs/README.md`](./docs/README.md). Key files:
9
+ - [`docs/architecture.md`](./docs/architecture.md) — layered pipeline, data model, extension seams.
10
+ - [`docs/status.md`](./docs/status.md) — what runs today vs. what's stubbed.
11
+ - [`docs/roadmap.md`](./docs/roadmap.md) — milestone sequencing.
12
+ - [`docs/development.md`](./docs/development.md) — install, commands, **red-green TDD workflow**, milestone-tag convention.
13
+
14
+ When `CLAUDE.md` and a doc disagree, the doc is canonical for content; this file is canonical for "what Claude must remember to do."
15
+
16
+ ## Common commands
17
+
18
+ ```bash
19
+ uv pip install -e ".[dev,api]"
20
+ pytest -q
21
+ ruff check . && ruff format --check . && mypy src
22
+ cgir scan tests/fixtures/python_sample --out /tmp/cgir-out
23
+ ```
24
+
25
+ Full command catalogue and CI workflow are in [`docs/development.md`](./docs/development.md).
26
+
27
+ ## Working conventions (must-follow)
28
+
29
+ - **Red-green TDD for milestones.** Every `milestone:` or `# STUB:` tag is a TDD entry point. Cycle: write failing tests pinning the public contract → implement until green → refactor. Detail in [`docs/development.md`](./docs/development.md). Don't skip the red phase — even in auto mode.
30
+ - **Milestone-tag hygiene.** Backlog is `grep -rn "milestone:\|STUB:" src/`. Completing a milestone means the tag *literally disappears*. Don't leave both real and stub paths in source.
31
+ - **Pipeline order is fixed.** New analyses wire into `src/cgir/pipeline.py:scan_repo` in the order `ingest → symbols → call_graph → cfg → pdg → effects → purity → slice → export`. The CLI and the HTTP API are thin surfaces over that one driver. New graph backends subclass `GraphSource` in `src/cgir/sources/base.py`.
32
+ - **Vocabulary is fixed by the spec.** `NodeKind` and `EdgeKind` enums in `src/cgir/ir/` come straight from `Code-IR.md` §Data model. Don't add ad-hoc kinds without updating the spec first.
33
+ - **`ComponentSpec` is the agent-facing contract.** Schema lives in two places: `schemas/component_spec.schema.json` (published) and `src/cgir/ir/component_spec.py:COMPONENT_SPEC_SCHEMA` (runtime source of truth). Change both, add a schema test.
34
+ - **Local-first parsing.** No network in the ingest or analysis layers. Only the optional regeneration step touches an LLM, and it gates on `ComponentSpec` rather than raw source.
35
+
36
+ ## Out of scope (per spec)
37
+
38
+ Don't propose work in these directions without explicit user buy-in: full compiler replacement, exact semantic equivalence for all dynamic/runtime features, build-system emulation, or perfect cross-language decompilation. Dynamic dispatch, `eval`, monkeypatching, and reflection are acknowledged precision limits — flag them rather than try to solve them perfectly.
@@ -0,0 +1,122 @@
1
+ # CodeGraph IR Product Specification
2
+
3
+ ## Executive summary
4
+
5
+ **Project name:** **CodeGraph IR**.
6
+ **Vision:** transform a Python/TypeScript repository into small, traceable, language-agnostic **ComponentSpec** units that an LLM can rewrite, reassemble, and audit without holding the whole repo in context. This extends today’s repo-graph tools: Graphify builds a local knowledge graph from whole projects with Tree-sitter and exports `graph.json`/`graph.html`; Joern builds cross-language Code Property Graphs; CodeQL databases already expose AST, data-flow, and control-flow representations; RepoGraph and CodexGraph show that repository graphs improve retrieval for repo-scale coding. The product gap is a **semantic IR layer** above those graphs. citeturn4view0turn4view1turn4view2turn4view3turn4view4turn5view0
7
+
8
+ **Unspecified:** target org size, budget, exact timeline.
9
+
10
+ ## Product scope
11
+
12
+ **Goals:** whole-repo graphing; interprocedural symbol/data-flow; side-effect and purity analysis; component slicing; traceability from source→graph→ComponentSpec→generated code; CLI/API usable by Codex or other agents.
13
+ **Non-goals:** full compiler replacement, exact semantic equivalence for all dynamic/runtime features, build-system emulation, or perfect cross-language decompilation. Tree-sitter is excellent for incremental, error-tolerant parsing, but deeper semantics must come from extra passes; CodeQL databases are single-language snapshots, so CGIR must normalize above tool-specific schemas. citeturn7view0turn4view3
14
+
15
+ **Target users:** AI-tooling teams, platform engineers, migration/refactor teams, and maintainers of large Python/TypeScript repos.
16
+ **Success metrics:** component coverage, purity/effect precision, source-to-spec trace completeness, regeneration compile/test pass rate, incremental re-index latency, and token reduction versus raw-file prompting. RepoGraph/CodexGraph are evidence that graph-structured repo context improves retrieval quality. citeturn4view4turn5view0
17
+
18
+ ## Architecture and prioritized features
19
+
20
+ ```mermaid
21
+ flowchart TD
22
+ A[Repo] --> B[Tree-sitter parse]
23
+ A --> C[Joern/CodeQL adapters]
24
+ B --> D[RepoGraph]
25
+ C --> D
26
+ D --> E[CFG / PDG / CPG overlays]
27
+ E --> F[Effect & purity analysis]
28
+ F --> G[Component slicing]
29
+ G --> H[ComponentSpec JSON]
30
+ H --> I[LLM regenerate / test / trace]
31
+ ```
32
+
33
+ | Priority | Feature | Why |
34
+ |---|---|---|
35
+ | P0 | Parse + symbol table + call graph | foundation |
36
+ | P0 | Effect detection + purity scoring | enables “small pure-ish units” |
37
+ | P0 | ComponentSpec export | agent-facing contract |
38
+ | P1 | Interprocedural data-flow + reaching defs | variable reassignment lineage |
39
+ | P1 | Trace map + regeneration validation | trust and debugging |
40
+ | P2 | Neo4j explorer + CodeQL bridge | scale and query UX |
41
+
42
+ **Recommended stack:** Tree-sitter for fast local parsing and incremental refresh; Joern as the strongest whole-program graph substrate for CPG-style overlays; CodeQL as a secondary analyzer/export bridge; NetworkX for in-memory orchestration; Neo4j for persistent property-graph exploration. citeturn7view0turn4view2turn4view3turn2search3turn6view2
43
+
44
+ ## Data model
45
+
46
+ **Internal nodes:** `Repository File Module Class Function Method Parameter Variable Assignment Expr Statement Branch Loop Return Import Effect Test`.
47
+ **Edges:** `CONTAINS IMPORTS CALLS READS WRITES MUTATES RETURNS THROWS FLOWS_TO CONTROLS DEPENDS_ON TRACE_OF REGENERATED_AS`.
48
+
49
+ **ComponentSpec JSON Schema**
50
+ ```json
51
+ {"type":"object","required":["id","kind","inputs","outputs","effects","calls","trace"],
52
+ "properties":{
53
+ "id":{"type":"string"},"kind":{"enum":["pure_function","state_transformer","effect_adapter","orchestrator","unknown"]},
54
+ "language":{"type":"string"},"signature":{"type":"string"},
55
+ "inputs":{"type":"array","items":{"type":"string"}},"outputs":{"type":"array","items":{"type":"string"}},
56
+ "effects":{"type":"array","items":{"type":"string"}},"calls":{"type":"array","items":{"type":"string"}},
57
+ "reads":{"type":"array","items":{"type":"string"}},"writes":{"type":"array","items":{"type":"string"}},
58
+ "purity":{"type":"number"},"algorithm":{"type":"array","items":{"type":"string"}},
59
+ "trace":{"type":"array","items":{"type":"string"}}}}
60
+ ```
61
+
62
+ **Example Python → ComponentSpec**
63
+ ```python
64
+ def add_tax(price: float, rate: float) -> float: return price * (1 + rate)
65
+ ```
66
+ ```json
67
+ {"id":"pricing.add_tax","kind":"pure_function","language":"python","signature":"add_tax(price:float,rate:float)->float","inputs":["price","rate"],"outputs":["float"],"effects":[],"calls":[],"reads":[],"writes":[],"purity":1.0,"algorithm":["multiply price by 1+rate"],"trace":["pricing.py:1"]}
68
+ ```
69
+ **Regenerated TypeScript stub**
70
+ ```ts
71
+ export function addTax(price:number, rate:number): number { return price * (1 + rate); }
72
+ ```
73
+
74
+ ## Analysis, interfaces, and workflow
75
+
76
+ **Required analyses:** parsing, symbol resolution, cross-file import resolution, CFG, reaching definitions, PDG, CPG-style overlays, side-effect detection, purity scoring, and component slicing. Reaching definitions tracks which assignments may reach each use; PDGs make data and control dependencies explicit; Joern’s CPG lineage merges syntax, control flow, and data flow into one attributed multigraph. citeturn1search12turn1search2turn8view2
77
+
78
+ **CLI**
79
+ ```bash
80
+ cgir scan <repo>
81
+ cgir export --format json|graphml|neo4j
82
+ cgir component <id>
83
+ cgir trace <source-loc>
84
+ cgir regenerate <id> --lang typescript
85
+ ```
86
+
87
+ **API**
88
+ - `POST /scan`
89
+ - `GET /components/{id}`
90
+ - `GET /trace?path=&line=`
91
+ - `POST /regenerate`
92
+
93
+ **Exports:** `repo_graph.json`, `components/*.json`, GraphML, Neo4j import CSV, provenance map, prompt pack. Graphify already demonstrates useful HTML/JSON report patterns for graph export. citeturn4view0turn4view1
94
+
95
+ **Prompt template**
96
+ ```text
97
+ Given ComponentSpec + dependent interfaces + tests, recreate this component in {target_language}. Preserve contracts, effects, and trace IDs. Do not invent hidden dependencies.
98
+ ```
99
+
100
+ ```mermaid
101
+ flowchart LR
102
+ A[ComponentSpec] --> B[Prompt pack]
103
+ B --> C[LLM rewrite]
104
+ C --> D[Compile/test]
105
+ D --> E[Trace link back]
106
+ ```
107
+
108
+ ## Validation, risk, and roadmap
109
+
110
+ **Testing:** unit tests for parsers and classifiers; integration tests on fixture repos; differential tests against Joern/CodeQL outputs; regeneration correctness = compile + unit tests + behavior snapshots.
111
+ **Performance:** incremental parsing/watch mode via Tree-sitter; content-hash re-indexing; in-memory NetworkX for small/medium repos, Neo4j or Joern backend for large repos. citeturn7view0turn2search3turn6view2
112
+
113
+ **Threat model / limitations:** dynamic dispatch, reflection, `eval`, monkeypatching, generated code, async race conditions, environment-dependent effects, and incomplete third-party source lower precision. Local-first parsing reduces code-exfiltration risk; Graphify explicitly emphasizes local AST extraction with no network in the AST pass. citeturn4view1
114
+
115
+ | Milestone | Effort |
116
+ |---|---:|
117
+ | MVP parse/graph/export | 4–6 weeks |
118
+ | Data-flow/effects/purity | 6–8 weeks |
119
+ | Component slicing/regeneration | 4–6 weeks |
120
+ | Scale/Neo4j/validation | 4–6 weeks |
121
+
122
+ **Priority sources to ground implementation:** Graphify repo/docs, Joern docs + CPG spec, CodeQL docs, Tree-sitter docs, RepoGraph, CodexGraph, Ferrante PDG paper, NetworkX docs, Neo4j docs. citeturn4view0turn4view2turn4view3turn7view0turn4view4turn5view0turn1search2turn2search3turn6view2
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aryaman Sonkiya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,143 @@
1
+ Metadata-Version: 2.4
2
+ Name: codegraph-ir
3
+ Version: 0.1.0
4
+ Summary: The deterministic contract layer for AI-modified codebases — effects, purity, contracts, and blast radius, with zero LLM calls.
5
+ Project-URL: Homepage, https://github.com/asonkiya/llm-semantic-compilers
6
+ Project-URL: Repository, https://github.com/asonkiya/llm-semantic-compilers
7
+ Project-URL: Issues, https://github.com/asonkiya/llm-semantic-compilers/issues
8
+ Author: Aryaman Sonkiya
9
+ License: MIT License
10
+
11
+ Copyright (c) 2026 Aryaman Sonkiya
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+ License-File: LICENSE
31
+ Keywords: ai-agents,code-graph,code-review,contracts,effects,llm,mcp,purity,static-analysis,tree-sitter
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Operating System :: OS Independent
36
+ Classifier: Programming Language :: Python :: 3.11
37
+ Classifier: Programming Language :: Python :: 3.12
38
+ Classifier: Programming Language :: Python :: 3.13
39
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
40
+ Classifier: Topic :: Software Development :: Quality Assurance
41
+ Classifier: Typing :: Typed
42
+ Requires-Python: >=3.11
43
+ Requires-Dist: jsonschema>=4.21
44
+ Requires-Dist: networkx>=3.2
45
+ Requires-Dist: pydantic>=2.6
46
+ Requires-Dist: tree-sitter-python<0.24,>=0.23
47
+ Requires-Dist: tree-sitter-typescript<0.24,>=0.23
48
+ Requires-Dist: tree-sitter<0.25,>=0.23
49
+ Requires-Dist: typer>=0.12
50
+ Provides-Extra: api
51
+ Requires-Dist: fastapi>=0.110; extra == 'api'
52
+ Requires-Dist: uvicorn>=0.27; extra == 'api'
53
+ Provides-Extra: dev
54
+ Requires-Dist: httpx>=0.27; extra == 'dev'
55
+ Requires-Dist: mypy>=1.10; extra == 'dev'
56
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
57
+ Requires-Dist: pytest>=8.0; extra == 'dev'
58
+ Requires-Dist: pyyaml>=6.0; extra == 'dev'
59
+ Requires-Dist: ruff>=0.5; extra == 'dev'
60
+ Requires-Dist: types-jsonschema; extra == 'dev'
61
+ Provides-Extra: llm
62
+ Requires-Dist: anthropic>=0.40; extra == 'llm'
63
+ Provides-Extra: mcp
64
+ Requires-Dist: mcp>=1.2; extra == 'mcp'
65
+ Description-Content-Type: text/markdown
66
+
67
+ # CodeGraph IR (CGIR)
68
+
69
+ **The deterministic contract layer for AI-modified codebases.** Agents write
70
+ more of the code than you can review. CGIR reads a repo and — with **zero LLM
71
+ calls** — tells you what each component *is* (effects, purity, contract,
72
+ entrypoints, call surface) and whether a change *altered* it. Think **ruff,
73
+ but for architecture instead of style**: fast, static, hallucination-free.
74
+
75
+ Distributed as **`codegraph-ir`**; the command and import package are both
76
+ `cgir`.
77
+
78
+ ## Install
79
+
80
+ ```bash
81
+ uv tool install codegraph-ir # isolated CLI (recommended); or: pipx install codegraph-ir
82
+ cgir --version
83
+ ```
84
+
85
+ For library/agent use in a project: `uv pip install codegraph-ir`
86
+ (extras: `[mcp]` for the agent server, `[api]` for the HTTP surface,
87
+ `[llm]` for regeneration).
88
+
89
+ ## The local loop
90
+
91
+ ```bash
92
+ cgir scan . # build the .cgir index (Python + TypeScript)
93
+ cgir watch . # keep it live: re-scan + show contract drift on save
94
+ cgir pack app.service.charge --repo . # minimal context bundle for one component
95
+ cgir impact app.service.charge # blast radius: affected callers, entrypoints, tests
96
+ cgir impact app.service.charge --candidate new.py --repo . # radius narrowed by the real delta
97
+ cgir verify app.service.charge --candidate new.py --repo . # contract-check an edit
98
+ cgir hook install # pre-commit seatbelt: block contract-breaking commits
99
+ ```
100
+
101
+ `pack` → edit → `impact` → `verify` → `hook`, with `watch` keeping the index
102
+ fresh underneath — an always-on membrane you and your agent both consult.
103
+
104
+ ## Gate CI on contract drift
105
+
106
+ The [GitHub Action](./docs/github-action.md) scans a PR's base and head and
107
+ fails the build on drift — a pure function that starts hitting the network, a
108
+ service that *stops* persisting, a new `POST /admin` route — deterministically,
109
+ with no per-seat LLM cost:
110
+
111
+ ```yaml
112
+ - uses: asonkiya/llm-semantic-compilers@v0
113
+ with:
114
+ fail-on: "effect-gain:net effect-gain:fs effect-gain:db effect-loss:net effect-loss:fs effect-loss:db"
115
+ ```
116
+
117
+ The default rule set is [evidence-based](./docs/gate-noise.md): replaying real
118
+ commit history, the I/O effect rules fire on ~0–10% of commits, each a genuine
119
+ change in a component's I/O surface.
120
+
121
+ ## Agents as first-class users
122
+
123
+ `cgir mcp --index .cgir` serves the index over MCP. Instead of grepping, an
124
+ agent calls `search` / `pack` to load minimal context, `impact` to see what a
125
+ change touches, and `verify` / `impact_of_change` to contract-check its own
126
+ edit before proposing it. See [`examples/`](./examples) for a worked
127
+ agent-PR case study.
128
+
129
+ ## Docs
130
+
131
+ - [`docs/strategy.md`](./docs/strategy.md) — positioning: the deterministic contract layer
132
+ - [`docs/status.md`](./docs/status.md) — what runs today, test coverage, milestones
133
+ - [`docs/gate-noise.md`](./docs/gate-noise.md) — false-alarm measurement on real history
134
+ - [`docs/github-action.md`](./docs/github-action.md) — CI contract-diff gate
135
+ - [`docs/experiment-log.md`](./docs/experiment-log.md) — rewrite-readiness / contract-preservation benchmarks
136
+ - [`docs/architecture.md`](./docs/architecture.md) — layered pipeline, data model, extension seams
137
+ - [`docs/languages.md`](./docs/languages.md) — adding a language (the `LanguageAdapter` seam)
138
+ - [`Code-IR.md`](./Code-IR.md) — full product specification
139
+ - [`RELEASING.md`](./RELEASING.md) — how to cut a release
140
+
141
+ ## License
142
+
143
+ MIT — see [`LICENSE`](./LICENSE).