codiff 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.
- codiff/__init__.py +1 -0
- codiff/__main__.py +5 -0
- codiff/cli.py +247 -0
- codiff/db/__init__.py +16 -0
- codiff/db/engine.py +31 -0
- codiff/db/models.py +119 -0
- codiff/db/operations.py +238 -0
- codiff/diff/__init__.py +1 -0
- codiff/diff/analysis.py +145 -0
- codiff/diff/differ.py +45 -0
- codiff/diff/engine.py +80 -0
- codiff/diff/indexer.py +134 -0
- codiff/diff/snapshot.py +325 -0
- codiff/export/__init__.py +5 -0
- codiff/export/json.py +43 -0
- codiff/export/mermaid.py +475 -0
- codiff/export/terminal.py +866 -0
- codiff/languages/__init__.py +29 -0
- codiff/languages/parser.py +214 -0
- codiff/languages/python/__init__.py +0 -0
- codiff/languages/python/parser.py +927 -0
- codiff/languages/python/resolver.py +178 -0
- codiff/languages/repository.py +245 -0
- codiff/languages/resolver.py +582 -0
- codiff/languages/typescript/__init__.py +0 -0
- codiff/languages/typescript/parser.py +612 -0
- codiff/languages/typescript/resolver.py +95 -0
- codiff/mcp_server.py +83 -0
- codiff/schema/__init__.py +25 -0
- codiff/schema/diff.py +110 -0
- codiff/schema/parsing.py +76 -0
- codiff/setup.py +103 -0
- codiff/utils/__init__.py +0 -0
- codiff/utils/args.py +114 -0
- codiff/utils/files.py +62 -0
- codiff/utils/git.py +101 -0
- codiff/utils/instructions.py +14 -0
- codiff/utils/instructions.yaml +50 -0
- codiff/utils/terminal.py +10 -0
- codiff-0.1.0.dist-info/METADATA +487 -0
- codiff-0.1.0.dist-info/RECORD +45 -0
- codiff-0.1.0.dist-info/WHEEL +5 -0
- codiff-0.1.0.dist-info/entry_points.txt +3 -0
- codiff-0.1.0.dist-info/licenses/LICENSE +201 -0
- codiff-0.1.0.dist-info/top_level.txt +1 -0
codiff/utils/git.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Git and .gitignore utilities shared across the codebase."""
|
|
2
|
+
|
|
3
|
+
import io
|
|
4
|
+
import logging
|
|
5
|
+
import os
|
|
6
|
+
import subprocess
|
|
7
|
+
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# ---------------------------------------------------------------------------
|
|
12
|
+
# .gitignore exclusion
|
|
13
|
+
# ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def load_gitignore(repo_path: str):
|
|
17
|
+
"""Parse the .gitignore at the repo root.
|
|
18
|
+
|
|
19
|
+
Returns a ``pathspec.PathSpec`` instance, or ``None`` if:
|
|
20
|
+
- pathspec is not installed, or
|
|
21
|
+
- no .gitignore exists at repo_path.
|
|
22
|
+
"""
|
|
23
|
+
try:
|
|
24
|
+
import pathspec
|
|
25
|
+
except ImportError:
|
|
26
|
+
logger.debug("pathspec not installed; .gitignore exclusion disabled")
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
gitignore_path = os.path.join(repo_path, ".gitignore")
|
|
30
|
+
if not os.path.exists(gitignore_path):
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
with open(gitignore_path, "r", encoding="utf-8", errors="ignore") as f:
|
|
35
|
+
lines = f.readlines()
|
|
36
|
+
spec = pathspec.PathSpec.from_lines("gitwildmatch", lines)
|
|
37
|
+
logger.debug("Loaded .gitignore: %d pattern(s)", len(spec.patterns))
|
|
38
|
+
return spec
|
|
39
|
+
except Exception as exc:
|
|
40
|
+
logger.warning("Failed to load .gitignore: %s", exc)
|
|
41
|
+
return None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def is_dir_ignored(spec, repo_path: str, parent_abs: str, dirname: str) -> bool:
|
|
45
|
+
"""Return True if *dirname* (inside *parent_abs*) is matched by *spec*.
|
|
46
|
+
|
|
47
|
+
A trailing slash is appended to the relative path so that
|
|
48
|
+
directory-specific patterns like ``build/`` match correctly.
|
|
49
|
+
"""
|
|
50
|
+
if spec is None:
|
|
51
|
+
return False
|
|
52
|
+
rel = os.path.relpath(os.path.join(parent_abs, dirname), repo_path)
|
|
53
|
+
return spec.match_file(rel) or spec.match_file(rel + "/")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def is_file_ignored(spec, repo_path: str, abs_file_path: str) -> bool:
|
|
57
|
+
"""Return True if *abs_file_path* is matched by *spec*."""
|
|
58
|
+
if spec is None:
|
|
59
|
+
return False
|
|
60
|
+
rel = os.path.relpath(abs_file_path, repo_path)
|
|
61
|
+
return spec.match_file(rel)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# ---------------------------------------------------------------------------
|
|
65
|
+
# Git operations
|
|
66
|
+
# ---------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def resolve_sha(repo_path: str, ref: str) -> str:
|
|
70
|
+
"""Return the full 40-char commit SHA for a git ref."""
|
|
71
|
+
result = subprocess.run(
|
|
72
|
+
["git", "rev-parse", ref],
|
|
73
|
+
cwd=repo_path,
|
|
74
|
+
capture_output=True,
|
|
75
|
+
text=True,
|
|
76
|
+
check=True,
|
|
77
|
+
)
|
|
78
|
+
return result.stdout.strip()
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def changed_files_between(repo_path: str, from_ref: str, to_ref: str) -> set[str]:
|
|
82
|
+
"""Return relative paths of files changed between two git refs."""
|
|
83
|
+
result = subprocess.run(
|
|
84
|
+
["git", "diff", "--name-only", from_ref, to_ref],
|
|
85
|
+
cwd=repo_path,
|
|
86
|
+
capture_output=True,
|
|
87
|
+
text=True,
|
|
88
|
+
check=True,
|
|
89
|
+
)
|
|
90
|
+
raw = result.stdout.strip()
|
|
91
|
+
return set(raw.split("\n")) if raw else set()
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def git_archive(repo_path, ref):
|
|
95
|
+
proc = subprocess.run(
|
|
96
|
+
["git", "archive", ref, "--format=tar"],
|
|
97
|
+
cwd=repo_path,
|
|
98
|
+
capture_output=True,
|
|
99
|
+
check=True,
|
|
100
|
+
)
|
|
101
|
+
return io.BytesIO(proc.stdout)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Loader for codiff/utils/instructions.yaml."""
|
|
2
|
+
|
|
3
|
+
from functools import lru_cache
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
_PATH = Path(__file__).parent / "instructions.yaml"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@lru_cache(maxsize=1)
|
|
10
|
+
def load() -> dict:
|
|
11
|
+
import yaml
|
|
12
|
+
|
|
13
|
+
with open(_PATH) as f:
|
|
14
|
+
return yaml.safe_load(f)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
marker: "<!-- codiff -->"
|
|
2
|
+
|
|
3
|
+
body: |
|
|
4
|
+
## codiff — structural diff tool
|
|
5
|
+
|
|
6
|
+
codiff is available as an MCP tool (`codiff_diff`). Do NOT run `codiff diff`
|
|
7
|
+
as a shell command — always use the MCP tool so output is returned directly.
|
|
8
|
+
|
|
9
|
+
**When to use**
|
|
10
|
+
|
|
11
|
+
Call `codiff_diff` once when you are about to create a pull request — not
|
|
12
|
+
after every file edit.
|
|
13
|
+
|
|
14
|
+
**How to use**
|
|
15
|
+
|
|
16
|
+
Always call with `format="mermaid"` and embed the returned diagram in the PR
|
|
17
|
+
description. GitHub renders Mermaid natively — no plugin needed.
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
codiff_diff(base_ref="main", head_ref="HEAD", format="mermaid")
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
If the output is empty (no structural changes detected), omit the diagram from
|
|
24
|
+
the PR description entirely — do not include an empty code block.
|
|
25
|
+
|
|
26
|
+
cursor:
|
|
27
|
+
description: Use codiff_diff before creating pull requests to show structural changes
|
|
28
|
+
alwaysApply: true
|
|
29
|
+
|
|
30
|
+
mcp_description: |
|
|
31
|
+
Show the structural call-graph diff of the current codebase against a
|
|
32
|
+
base git reference.
|
|
33
|
+
|
|
34
|
+
WHEN TO CALL
|
|
35
|
+
Call this tool once when you are about to create a pull request — NOT after
|
|
36
|
+
every file edit.
|
|
37
|
+
|
|
38
|
+
HOW TO USE
|
|
39
|
+
Call with format="mermaid" and embed the returned string in the PR description.
|
|
40
|
+
GitHub renders Mermaid natively — no plugin needed.
|
|
41
|
+
|
|
42
|
+
codiff_diff(base_ref="main", head_ref="HEAD", format="mermaid")
|
|
43
|
+
|
|
44
|
+
Include it in the PR body like this:
|
|
45
|
+
|
|
46
|
+
## Structural diff
|
|
47
|
+
<paste the returned string here>
|
|
48
|
+
|
|
49
|
+
Pass include_deleted=True to also show removed functions in the diagram.
|
|
50
|
+
By default, test functions and deleted functions are excluded.
|
codiff/utils/terminal.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import shutil
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def detect_width() -> int:
|
|
6
|
+
"""Detect terminal width via COLUMNS env var or shutil fallback."""
|
|
7
|
+
val = os.environ.get("COLUMNS")
|
|
8
|
+
if val and val.isdigit():
|
|
9
|
+
return int(val)
|
|
10
|
+
return shutil.get_terminal_size(fallback=(80, 24)).columns
|
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codiff
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Structural call-graph diff for codebases, built for coding agents
|
|
5
|
+
Author-email: Issa Hammoud <issa.hammoud@outlook.com>
|
|
6
|
+
License: Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
15
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
18
|
+
the copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
21
|
+
other entities that control, are controlled by, or are under common
|
|
22
|
+
control with that entity. For the purposes of this definition,
|
|
23
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
24
|
+
direction or management of such entity, whether by contract or
|
|
25
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
26
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
29
|
+
exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation
|
|
33
|
+
source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form, including but
|
|
37
|
+
not limited to compiled object code, generated documentation,
|
|
38
|
+
and conversions to other media types.
|
|
39
|
+
|
|
40
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
41
|
+
Object form, made available under the License, as indicated by a
|
|
42
|
+
copyright notice that is included in or attached to the work
|
|
43
|
+
(an example is provided in the Appendix below).
|
|
44
|
+
|
|
45
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
46
|
+
form, that is based on (or derived from) the Work and for which the
|
|
47
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
48
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
49
|
+
of this License, Derivative Works shall not include works that remain
|
|
50
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
51
|
+
the Work and Derivative Works thereof.
|
|
52
|
+
|
|
53
|
+
"Contribution" shall mean any work of authorship, including
|
|
54
|
+
the original version of the Work and any modifications or additions
|
|
55
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
56
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
57
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
58
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
59
|
+
means any form of electronic, verbal, or written communication sent
|
|
60
|
+
to the Licensor or its representatives, including but not limited to
|
|
61
|
+
communication on electronic mailing lists, source code control systems,
|
|
62
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
63
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
64
|
+
excluding communication that is conspicuously marked or otherwise
|
|
65
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
66
|
+
|
|
67
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
68
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
69
|
+
subsequently incorporated within the Work.
|
|
70
|
+
|
|
71
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
72
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
73
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
74
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
75
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
76
|
+
Work and such Derivative Works in Source or Object form.
|
|
77
|
+
|
|
78
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
79
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
80
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
81
|
+
(except as stated in this section) patent license to make, have made,
|
|
82
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
83
|
+
where such license applies only to those patent claims licensable
|
|
84
|
+
by such Contributor that are necessarily infringed by their
|
|
85
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
86
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
87
|
+
institute patent litigation against any entity (including a
|
|
88
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
89
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
90
|
+
or contributory patent infringement, then any patent licenses
|
|
91
|
+
granted to You under this License for that Work shall terminate
|
|
92
|
+
as of the date such litigation is filed.
|
|
93
|
+
|
|
94
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
95
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
96
|
+
modifications, and in Source or Object form, provided that You
|
|
97
|
+
meet the following conditions:
|
|
98
|
+
|
|
99
|
+
(a) You must give any other recipients of the Work or
|
|
100
|
+
Derivative Works a copy of this License; and
|
|
101
|
+
|
|
102
|
+
(b) You must cause any modified files to carry prominent notices
|
|
103
|
+
stating that You changed the files; and
|
|
104
|
+
|
|
105
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
106
|
+
that You distribute, all copyright, patent, trademark, and
|
|
107
|
+
attribution notices from the Source form of the Work,
|
|
108
|
+
excluding those notices that do not pertain to any part of
|
|
109
|
+
the Derivative Works; and
|
|
110
|
+
|
|
111
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
112
|
+
distribution, then any Derivative Works that You distribute must
|
|
113
|
+
include a readable copy of the attribution notices contained
|
|
114
|
+
within such NOTICE file, excluding those notices that do not
|
|
115
|
+
pertain to any part of the Derivative Works, in at least one
|
|
116
|
+
of the following places: within a NOTICE text file distributed
|
|
117
|
+
as part of the Derivative Works; within the Source form or
|
|
118
|
+
documentation, if provided along with the Derivative Works; or,
|
|
119
|
+
within a display generated by the Derivative Works, if and
|
|
120
|
+
wherever such third-party notices normally appear. The contents
|
|
121
|
+
of the NOTICE file are for informational purposes only and
|
|
122
|
+
do not modify the License. You may add Your own attribution
|
|
123
|
+
notices within Derivative Works that You distribute, alongside
|
|
124
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
125
|
+
that such additional attribution notices cannot be construed
|
|
126
|
+
as modifying the License.
|
|
127
|
+
|
|
128
|
+
You may add Your own copyright statement to Your modifications and
|
|
129
|
+
may provide additional or different license terms and conditions
|
|
130
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
131
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
132
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
133
|
+
the conditions stated in this License.
|
|
134
|
+
|
|
135
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
136
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
137
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
138
|
+
this License, without any additional terms or conditions.
|
|
139
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
140
|
+
the terms of any separate license agreement you may have executed
|
|
141
|
+
with Licensor regarding such Contributions.
|
|
142
|
+
|
|
143
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
144
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
145
|
+
except as required for reasonable and customary use in describing the
|
|
146
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
147
|
+
|
|
148
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
149
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
150
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
151
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
152
|
+
implied, including, without limitation, any warranties or conditions
|
|
153
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
154
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
155
|
+
appropriateness of using or redistributing the Work and assume any
|
|
156
|
+
risks associated with Your exercise of permissions under this License.
|
|
157
|
+
|
|
158
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
159
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
160
|
+
unless required by applicable law (such as deliberate and grossly
|
|
161
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
162
|
+
liable to You for damages, including any direct, indirect, special,
|
|
163
|
+
incidental, or consequential damages of any character arising as a
|
|
164
|
+
result of this License or out of the use or inability to use the
|
|
165
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
166
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
167
|
+
other commercial damages or losses), even if such Contributor
|
|
168
|
+
has been advised of the possibility of such damages.
|
|
169
|
+
|
|
170
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
171
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
172
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
173
|
+
or other liability obligations and/or rights consistent with this
|
|
174
|
+
License. However, in accepting such obligations, You may act only
|
|
175
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
176
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
177
|
+
defend, and hold each Contributor harmless for any liability
|
|
178
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
179
|
+
of your accepting any such warranty or additional liability.
|
|
180
|
+
|
|
181
|
+
END OF TERMS AND CONDITIONS
|
|
182
|
+
|
|
183
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
184
|
+
|
|
185
|
+
To apply the Apache License to your work, attach the following
|
|
186
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
187
|
+
replaced with your own identifying information. (Don't include
|
|
188
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
189
|
+
comment syntax for the file format. We also recommend that a
|
|
190
|
+
file or class name and description of purpose be included on the
|
|
191
|
+
same "printed page" as the copyright notice for easier
|
|
192
|
+
identification within third-party archives.
|
|
193
|
+
|
|
194
|
+
Copyright [yyyy] [name of copyright owner]
|
|
195
|
+
|
|
196
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
197
|
+
you may not use this file except in compliance with the License.
|
|
198
|
+
You may obtain a copy of the License at
|
|
199
|
+
|
|
200
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
201
|
+
|
|
202
|
+
Unless required by applicable law or agreed to in writing, software
|
|
203
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
204
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
205
|
+
See the License for the specific language governing permissions and
|
|
206
|
+
limitations under the License.
|
|
207
|
+
|
|
208
|
+
Project-URL: Homepage, https://github.com/issahammoud/codiff
|
|
209
|
+
Project-URL: Repository, https://github.com/issahammoud/codiff
|
|
210
|
+
Project-URL: Bug Tracker, https://github.com/issahammoud/codiff/issues
|
|
211
|
+
Classifier: Development Status :: 4 - Beta
|
|
212
|
+
Classifier: Intended Audience :: Developers
|
|
213
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
214
|
+
Classifier: Programming Language :: Python :: 3
|
|
215
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
216
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
217
|
+
Classifier: Topic :: Software Development :: Version Control
|
|
218
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
219
|
+
Requires-Python: >=3.11
|
|
220
|
+
Description-Content-Type: text/markdown
|
|
221
|
+
License-File: LICENSE
|
|
222
|
+
Requires-Dist: sqlalchemy>=2.0.25
|
|
223
|
+
Requires-Dist: tree-sitter>=0.24.0
|
|
224
|
+
Requires-Dist: tree-sitter-python>=0.23.6
|
|
225
|
+
Requires-Dist: tree-sitter-typescript>=0.23.2
|
|
226
|
+
Requires-Dist: pathspec>=0.12.0
|
|
227
|
+
Requires-Dist: rich>=13.0.0
|
|
228
|
+
Requires-Dist: mcp>=1.0.0
|
|
229
|
+
Requires-Dist: pyyaml>=6.0
|
|
230
|
+
Requires-Dist: tomli-w>=1.0.0
|
|
231
|
+
Provides-Extra: dev
|
|
232
|
+
Requires-Dist: ruff>=0.5.0; extra == "dev"
|
|
233
|
+
Requires-Dist: mypy>=1.10.0; extra == "dev"
|
|
234
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
235
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
|
|
236
|
+
Requires-Dist: sqlalchemy[mypy]>=2.0.25; extra == "dev"
|
|
237
|
+
Dynamic: license-file
|
|
238
|
+
|
|
239
|
+
# codiff
|
|
240
|
+
|
|
241
|
+
A structural call-graph diff tool for multi-language codebases, built to work with coding agents. Instead of a line diff, it shows what changed at the function level, which functions were added and where they hook into existing code, which were modified, which were removed, with call relationships mapped across files.
|
|
242
|
+
|
|
243
|
+
Here's the output of `codiff diff --base main --format mermaid` run on codiff's own codebase:
|
|
244
|
+
|
|
245
|
+
```mermaid
|
|
246
|
+
%%{init: {'layout': 'elk', 'elk': {'direction': 'RIGHT'}, 'maxTextSize': 999999, 'theme': 'base', 'themeVariables': {'background': '#ffffff', 'clusterBkg': '#f8fafc', 'clusterBorder': '#94a3b8', 'primaryColor': '#f8fafc', 'primaryBorderColor': '#94a3b8', 'primaryTextColor': '#1e293b', 'lineColor': '#64748b', 'fontSize': '13px', 'fontFamily': 'ui-monospace, SFMono-Regular, Menlo, monospace'}}}%%
|
|
247
|
+
classDiagram
|
|
248
|
+
direction LR
|
|
249
|
+
|
|
250
|
+
class n5["codiff/cli.py"] {
|
|
251
|
+
~ _run_diff() sig
|
|
252
|
+
~ main()
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
class n7["codiff/diff/indexer.py"] {
|
|
256
|
+
+ _incremental_update_db()
|
|
257
|
+
~ _full_index() sig
|
|
258
|
+
~ ensure_indexed() sig
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
class n3["PythonParser"] {
|
|
262
|
+
<<codiff/languages/python/parser.py>>
|
|
263
|
+
~ build_package_exports() calls +1−1
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
class n8["codiff/diff/snapshot.py"] {
|
|
267
|
+
+ _chunk_to_node_info()
|
|
268
|
+
+ _git_changed_files()
|
|
269
|
+
+ _parse_and_expand_stale()
|
|
270
|
+
+ build_snapshot_incremental()
|
|
271
|
+
~ build_from_path() sig
|
|
272
|
+
~ build_from_ref() sig
|
|
273
|
+
~ load_from_db() calls +1−1
|
|
274
|
+
}
|
|
275
|
+
class n0["_ClassStub"] {
|
|
276
|
+
<<codiff/diff/snapshot.py>>
|
|
277
|
+
+ __init__()
|
|
278
|
+
}
|
|
279
|
+
class n1["_NodeStub"] {
|
|
280
|
+
<<codiff/diff/snapshot.py>>
|
|
281
|
+
+ __init__()
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
class n2["LanguageParser"] {
|
|
285
|
+
<<codiff/languages/parser.py>>
|
|
286
|
+
~ build_modules_dict() calls +1−1
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
class n6["codiff/db/operations.py"] {
|
|
290
|
+
+ _insert_call_edges()
|
|
291
|
+
+ _insert_classes()
|
|
292
|
+
+ _insert_functions()
|
|
293
|
+
+ _session()
|
|
294
|
+
+ get_indexed_sha()
|
|
295
|
+
+ load_snapshot()
|
|
296
|
+
+ update_sha()
|
|
297
|
+
+ write_full_snapshot()
|
|
298
|
+
+ write_incremental()
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
style n5 fill:#fefce8,color:#854d0e,stroke:#f59e0b,stroke-width:3px
|
|
302
|
+
style n7 fill:#fefce8,color:#854d0e,stroke:#f59e0b,stroke-width:3px
|
|
303
|
+
style n3 fill:#fefce8,color:#854d0e,stroke:#f59e0b,stroke-width:3px
|
|
304
|
+
style n8 fill:#fefce8,color:#854d0e,stroke:#f59e0b,stroke-width:3px
|
|
305
|
+
style n0 fill:#f0fdf4,color:#166534,stroke:#22c55e,stroke-width:3px
|
|
306
|
+
style n1 fill:#f0fdf4,color:#166534,stroke:#22c55e,stroke-width:3px
|
|
307
|
+
style n2 fill:#fefce8,color:#854d0e,stroke:#f59e0b,stroke-width:3px
|
|
308
|
+
style n6 fill:#f0fdf4,color:#166534,stroke:#22c55e,stroke-width:3px
|
|
309
|
+
|
|
310
|
+
%% Relationships
|
|
311
|
+
n3 --|> n2
|
|
312
|
+
n5 --> n8 : calls
|
|
313
|
+
n7 --> n0 : calls
|
|
314
|
+
n7 --> n1 : calls
|
|
315
|
+
n7 --> n6 : calls
|
|
316
|
+
n7 --> n8 : calls
|
|
317
|
+
n8 --> n0 : calls
|
|
318
|
+
n8 --> n1 : calls
|
|
319
|
+
n8 --> n6 : calls
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Each box is a file or class. **Green** = only additions, **yellow** = at least one modification. Inside each box: `+` added function, `~` modified. Annotations: `sig` = signature changed, `calls +N−N` = now calls N more / N fewer functions. Arrows show which files call into which.
|
|
323
|
+
|
|
324
|
+
## Supported languages
|
|
325
|
+
|
|
326
|
+
| Language | Extensions |
|
|
327
|
+
|---|---|
|
|
328
|
+
| Python | `.py` |
|
|
329
|
+
| TypeScript | `.ts`, `.tsx` |
|
|
330
|
+
|
|
331
|
+
## How it works
|
|
332
|
+
|
|
333
|
+
codiff maintains a SQLite call-graph index (`.codiff.db`) at the repo root. On first run it does a full parse; on subsequent runs it re-parses only the files changed since the last indexed commit, then detects stale callers (functions whose callees were renamed or deleted) and re-parses those too. Both the base and head snapshots are built incrementally from this index, so diffs stay fast even on large codebases.
|
|
334
|
+
|
|
335
|
+
The graph delta — added, modified, removed functions — is computed deterministically from the resolved call graph. No LLM, no embeddings, fully offline.
|
|
336
|
+
|
|
337
|
+
## Requirements
|
|
338
|
+
|
|
339
|
+
- Python 3.11+
|
|
340
|
+
- Git
|
|
341
|
+
|
|
342
|
+
## Installation
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
pip install codiff
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
## Usage
|
|
349
|
+
|
|
350
|
+
### CLI
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
# Index a repository (writes .codiff.db — runs automatically on first diff)
|
|
354
|
+
codiff index <path>
|
|
355
|
+
|
|
356
|
+
# Diff
|
|
357
|
+
codiff diff # diff HEAD vs working tree (terminal output)
|
|
358
|
+
codiff diff --format mermaid # output a Mermaid class diagram
|
|
359
|
+
codiff diff --format json # output structured JSON (for editor integrations)
|
|
360
|
+
codiff diff --base main # diff a specific base ref
|
|
361
|
+
codiff diff --head <ref> # diff two git refs directly
|
|
362
|
+
codiff diff --repo /path/to/repo # diff a different repo
|
|
363
|
+
codiff diff --include-tests # include test functions (hidden by default)
|
|
364
|
+
codiff diff --include-deleted # include deleted functions (hidden by default)
|
|
365
|
+
codiff diff --workers 8 # set parallel worker count (default: cpu_count // 2)
|
|
366
|
+
codiff diff --debug # print timing breakdown for each processing step
|
|
367
|
+
|
|
368
|
+
# Configure a coding agent (see Agent integration below)
|
|
369
|
+
codiff init --agent <agent>
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Output formats
|
|
373
|
+
|
|
374
|
+
| Format | Description |
|
|
375
|
+
|---|---|
|
|
376
|
+
| `terminal` | Colored terminal output with UML-style boxes (default) |
|
|
377
|
+
| `mermaid` | Two Mermaid `classDiagram` blocks — paste into any Markdown file or PR description |
|
|
378
|
+
| `json` | Structured JSON — consumed by editor integrations (e.g. the VS Code extension) |
|
|
379
|
+
|
|
380
|
+
### Agent integration (MCP + project instructions)
|
|
381
|
+
|
|
382
|
+
Run once per project to configure your coding agent:
|
|
383
|
+
|
|
384
|
+
```bash
|
|
385
|
+
codiff init --agent claude # Claude Code
|
|
386
|
+
codiff init --agent codex # OpenAI Codex CLI
|
|
387
|
+
codiff init --agent gemini # Gemini CLI
|
|
388
|
+
codiff init --agent vibe # Mistral Vibe
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Each command writes the MCP server config and a project instructions file telling the agent to use the `codiff_diff` MCP tool when creating pull requests:
|
|
392
|
+
|
|
393
|
+
| Agent | MCP config | Instructions file |
|
|
394
|
+
|---|---|---|
|
|
395
|
+
| `claude` | `.mcp.json` | `CLAUDE.md` |
|
|
396
|
+
| `codex` | `.codex/config.toml` | `AGENTS.md` |
|
|
397
|
+
| `gemini` | `~/.gemini/settings.json` ¹ | `GEMINI.md` |
|
|
398
|
+
| `vibe` | `~/.vibe/config.toml` ² | — |
|
|
399
|
+
|
|
400
|
+
¹ Gemini CLI MCP config is global (not project-scoped). Restart Gemini CLI after running.
|
|
401
|
+
² Mistral Vibe MCP config is global (not project-scoped). Restart Vibe after running.
|
|
402
|
+
|
|
403
|
+
When creating a pull request, the agent calls `codiff_diff(base_ref="main", head_ref="HEAD", format="mermaid")` and embeds the returned diagram in the PR description. GitHub renders Mermaid natively — no plugin needed.
|
|
404
|
+
|
|
405
|
+
## Reading the terminal output
|
|
406
|
+
|
|
407
|
+
The output shows one box per changed file. Boxes are laid out side by side when they fit the terminal width, with labeled arrows between adjacent connected boxes.
|
|
408
|
+
|
|
409
|
+
### Inside each file box
|
|
410
|
+
|
|
411
|
+
Methods belonging to the same class are grouped into a **dashed sub-box** (╭╌╌╌ `ClassName` ╌╌╌╮). Standalone functions appear directly in the file box. Deleted functions (only shown with `--include-deleted`) are collected into a red **╭╌╌╌ deleted ╌╌╌╮** sub-box.
|
|
412
|
+
|
|
413
|
+
Functions are listed with an indicator and an annotation:
|
|
414
|
+
|
|
415
|
+
| Indicator | Meaning |
|
|
416
|
+
|---|---|
|
|
417
|
+
| `+` green | Function was added |
|
|
418
|
+
| `~` yellow | Function was modified |
|
|
419
|
+
| `-` red | Function was removed |
|
|
420
|
+
|
|
421
|
+
| Annotation | Meaning |
|
|
422
|
+
|---|---|
|
|
423
|
+
| `entry point` | Nothing calls this new function — new public surface |
|
|
424
|
+
| `sig changed` | Parameters or return type changed |
|
|
425
|
+
| `calls changed` | The function now calls different things |
|
|
426
|
+
| `body changed` | Pure implementation change |
|
|
427
|
+
|
|
428
|
+
For added functions, `→` arrows show intra-file call relationships — a function indented under another calls it.
|
|
429
|
+
|
|
430
|
+
### Intra-file class relationships
|
|
431
|
+
|
|
432
|
+
When two changed classes in the same file are related, each class box shows a dim annotation before its methods:
|
|
433
|
+
|
|
434
|
+
```
|
|
435
|
+
╭╌╌╌ PageAwarePreChunker ╌╌╌╮
|
|
436
|
+
│ calls PageAwarePreChunkBuilder │
|
|
437
|
+
│ ────────────── │
|
|
438
|
+
│ + __init__ │
|
|
439
|
+
╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╯
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
Relationship types: `calls` (method calls to another class) and `inherits` (superclass relationship detected from class definitions).
|
|
443
|
+
|
|
444
|
+
### Colors
|
|
445
|
+
|
|
446
|
+
Functions that form a connected call chain share a color across the entire output — across boxes, across files. All magenta names belong to one chain, all cyan to another.
|
|
447
|
+
|
|
448
|
+
- **Chain color** on the function name — part of a call chain
|
|
449
|
+
- **White** on the function name — added/modified but not connected to any chain
|
|
450
|
+
- **`~` yellow** — always marks a modified function regardless of chain membership
|
|
451
|
+
|
|
452
|
+
### Arrows between file boxes
|
|
453
|
+
|
|
454
|
+
Labeled arrows appear between adjacent file boxes when there is a cross-file relationship:
|
|
455
|
+
|
|
456
|
+
| Label | Meaning |
|
|
457
|
+
|---|---|
|
|
458
|
+
| `calls ────▶` | A function in the left file calls a function in the right file |
|
|
459
|
+
| `inherits ────▶` | A class in the left file inherits from a class in the right file |
|
|
460
|
+
|
|
461
|
+
## Reading the Mermaid output
|
|
462
|
+
|
|
463
|
+
The Mermaid format produces **two diagrams**:
|
|
464
|
+
|
|
465
|
+
1. **Connected modules** — files that have call or inheritance relationships with other changed files. Rendered with ELK layout left-to-right, with `calls` and `inherits` arrows between class boxes.
|
|
466
|
+
|
|
467
|
+
2. **Isolated modules** — files with no cross-file relationships (e.g. migration files, config). Grouped by their top two folder levels into namespace clusters, rendered with Dagre left-to-right.
|
|
468
|
+
|
|
469
|
+
Both diagrams use color-coded class boxes:
|
|
470
|
+
- **Green** — only additions in this file/class
|
|
471
|
+
- **Yellow** — at least one modification
|
|
472
|
+
- **Red** — only deletions (requires `--include-deleted`)
|
|
473
|
+
|
|
474
|
+
Inside each box, functions are listed with a prefix and optional annotation:
|
|
475
|
+
|
|
476
|
+
| Prefix | Meaning |
|
|
477
|
+
|---|---|
|
|
478
|
+
| `+` | Function was added |
|
|
479
|
+
| `~` | Function was modified |
|
|
480
|
+
| `-` | Function was removed |
|
|
481
|
+
|
|
482
|
+
| Annotation | Meaning |
|
|
483
|
+
|---|---|
|
|
484
|
+
| `sig` | Parameters or return type changed |
|
|
485
|
+
| `calls +N−N` | Call list changed — N new callees, N dropped |
|
|
486
|
+
|
|
487
|
+
When a class appears inside a file box, its file path is shown as a `«stereotype»` subtitle below the class name.
|