codiff 0.1.0__tar.gz → 0.1.2__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 (66) hide show
  1. {codiff-0.1.0 → codiff-0.1.2}/PKG-INFO +88 -50
  2. {codiff-0.1.0 → codiff-0.1.2}/README.md +87 -49
  3. {codiff-0.1.0 → codiff-0.1.2}/codiff/cli.py +44 -0
  4. {codiff-0.1.0 → codiff-0.1.2}/codiff/diff/indexer.py +9 -1
  5. {codiff-0.1.0 → codiff-0.1.2}/codiff/export/mermaid.py +14 -1
  6. {codiff-0.1.0 → codiff-0.1.2}/codiff/languages/repository.py +31 -24
  7. {codiff-0.1.0 → codiff-0.1.2}/codiff/languages/resolver.py +8 -3
  8. {codiff-0.1.0 → codiff-0.1.2}/codiff/mcp_server.py +2 -1
  9. {codiff-0.1.0 → codiff-0.1.2}/codiff/utils/args.py +1 -1
  10. {codiff-0.1.0 → codiff-0.1.2}/codiff.egg-info/PKG-INFO +88 -50
  11. {codiff-0.1.0 → codiff-0.1.2}/pyproject.toml +1 -1
  12. {codiff-0.1.0 → codiff-0.1.2}/LICENSE +0 -0
  13. {codiff-0.1.0 → codiff-0.1.2}/codiff/__init__.py +0 -0
  14. {codiff-0.1.0 → codiff-0.1.2}/codiff/__main__.py +0 -0
  15. {codiff-0.1.0 → codiff-0.1.2}/codiff/db/__init__.py +0 -0
  16. {codiff-0.1.0 → codiff-0.1.2}/codiff/db/engine.py +0 -0
  17. {codiff-0.1.0 → codiff-0.1.2}/codiff/db/models.py +0 -0
  18. {codiff-0.1.0 → codiff-0.1.2}/codiff/db/operations.py +0 -0
  19. {codiff-0.1.0 → codiff-0.1.2}/codiff/diff/__init__.py +0 -0
  20. {codiff-0.1.0 → codiff-0.1.2}/codiff/diff/analysis.py +0 -0
  21. {codiff-0.1.0 → codiff-0.1.2}/codiff/diff/differ.py +0 -0
  22. {codiff-0.1.0 → codiff-0.1.2}/codiff/diff/engine.py +0 -0
  23. {codiff-0.1.0 → codiff-0.1.2}/codiff/diff/snapshot.py +0 -0
  24. {codiff-0.1.0 → codiff-0.1.2}/codiff/export/__init__.py +0 -0
  25. {codiff-0.1.0 → codiff-0.1.2}/codiff/export/json.py +0 -0
  26. {codiff-0.1.0 → codiff-0.1.2}/codiff/export/terminal.py +0 -0
  27. {codiff-0.1.0 → codiff-0.1.2}/codiff/languages/__init__.py +0 -0
  28. {codiff-0.1.0 → codiff-0.1.2}/codiff/languages/parser.py +0 -0
  29. {codiff-0.1.0 → codiff-0.1.2}/codiff/languages/python/__init__.py +0 -0
  30. {codiff-0.1.0 → codiff-0.1.2}/codiff/languages/python/parser.py +0 -0
  31. {codiff-0.1.0 → codiff-0.1.2}/codiff/languages/python/resolver.py +0 -0
  32. {codiff-0.1.0 → codiff-0.1.2}/codiff/languages/typescript/__init__.py +0 -0
  33. {codiff-0.1.0 → codiff-0.1.2}/codiff/languages/typescript/parser.py +0 -0
  34. {codiff-0.1.0 → codiff-0.1.2}/codiff/languages/typescript/resolver.py +0 -0
  35. {codiff-0.1.0 → codiff-0.1.2}/codiff/schema/__init__.py +0 -0
  36. {codiff-0.1.0 → codiff-0.1.2}/codiff/schema/diff.py +0 -0
  37. {codiff-0.1.0 → codiff-0.1.2}/codiff/schema/parsing.py +0 -0
  38. {codiff-0.1.0 → codiff-0.1.2}/codiff/setup.py +0 -0
  39. {codiff-0.1.0 → codiff-0.1.2}/codiff/utils/__init__.py +0 -0
  40. {codiff-0.1.0 → codiff-0.1.2}/codiff/utils/files.py +0 -0
  41. {codiff-0.1.0 → codiff-0.1.2}/codiff/utils/git.py +0 -0
  42. {codiff-0.1.0 → codiff-0.1.2}/codiff/utils/instructions.py +0 -0
  43. {codiff-0.1.0 → codiff-0.1.2}/codiff/utils/instructions.yaml +0 -0
  44. {codiff-0.1.0 → codiff-0.1.2}/codiff/utils/terminal.py +0 -0
  45. {codiff-0.1.0 → codiff-0.1.2}/codiff.egg-info/SOURCES.txt +0 -0
  46. {codiff-0.1.0 → codiff-0.1.2}/codiff.egg-info/dependency_links.txt +0 -0
  47. {codiff-0.1.0 → codiff-0.1.2}/codiff.egg-info/entry_points.txt +0 -0
  48. {codiff-0.1.0 → codiff-0.1.2}/codiff.egg-info/requires.txt +0 -0
  49. {codiff-0.1.0 → codiff-0.1.2}/codiff.egg-info/top_level.txt +0 -0
  50. {codiff-0.1.0 → codiff-0.1.2}/setup.cfg +0 -0
  51. {codiff-0.1.0 → codiff-0.1.2}/tests/test_call_patterns.py +0 -0
  52. {codiff-0.1.0 → codiff-0.1.2}/tests/test_call_resolver.py +0 -0
  53. {codiff-0.1.0 → codiff-0.1.2}/tests/test_cli.py +0 -0
  54. {codiff-0.1.0 → codiff-0.1.2}/tests/test_code_parser.py +0 -0
  55. {codiff-0.1.0 → codiff-0.1.2}/tests/test_db.py +0 -0
  56. {codiff-0.1.0 → codiff-0.1.2}/tests/test_diff.py +0 -0
  57. {codiff-0.1.0 → codiff-0.1.2}/tests/test_export_json.py +0 -0
  58. {codiff-0.1.0 → codiff-0.1.2}/tests/test_export_mermaid.py +0 -0
  59. {codiff-0.1.0 → codiff-0.1.2}/tests/test_export_terminal.py +0 -0
  60. {codiff-0.1.0 → codiff-0.1.2}/tests/test_indexer.py +0 -0
  61. {codiff-0.1.0 → codiff-0.1.2}/tests/test_setup.py +0 -0
  62. {codiff-0.1.0 → codiff-0.1.2}/tests/test_snapshot.py +0 -0
  63. {codiff-0.1.0 → codiff-0.1.2}/tests/test_ts_integration.py +0 -0
  64. {codiff-0.1.0 → codiff-0.1.2}/tests/test_ts_parser.py +0 -0
  65. {codiff-0.1.0 → codiff-0.1.2}/tests/test_ts_resolver.py +0 -0
  66. {codiff-0.1.0 → codiff-0.1.2}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codiff
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Structural call-graph diff for codebases, built for coding agents
5
5
  Author-email: Issa Hammoud <issa.hammoud@outlook.com>
6
6
  License: Apache License
@@ -238,9 +238,87 @@ Dynamic: license-file
238
238
 
239
239
  # codiff
240
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.
241
+ A structural call-graph diff tool for multi-language codebases, built to work with coding agents.
242
242
 
243
- Here's the output of `codiff diff --base main --format mermaid` run on codiff's own codebase:
243
+ Instead of a line diff, codiff 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.
244
+
245
+ No LLM, no embeddings, fully offline.
246
+
247
+ ## Supported languages
248
+
249
+ | Language | Extensions |
250
+ |---|---|
251
+ | Python | `.py` |
252
+ | TypeScript | `.ts`, `.tsx` |
253
+
254
+ ## Installation
255
+
256
+ ```bash
257
+ pip install codiff
258
+ ```
259
+
260
+ ## Quickstart
261
+
262
+ ```bash
263
+ # Run from inside any git repository
264
+ codiff diff
265
+ ```
266
+
267
+ This compares your working tree against `HEAD`. If everything is already committed, use `--base` and `--head` to compare two refs explicitly:
268
+
269
+ ```bash
270
+ # Diff between two branches
271
+ codiff diff --base main --head my-feature
272
+
273
+ # Diff introduced by the last commit only
274
+ codiff diff --base HEAD~1 --head HEAD
275
+
276
+ # Diff between two arbitrary commits
277
+ codiff diff --base a1b2c3d --head e4f5g6h
278
+ ```
279
+
280
+ To get a Mermaid diagram (useful for PR descriptions):
281
+
282
+ ```bash
283
+ codiff diff --base main --format mermaid
284
+ ```
285
+
286
+ To save the diagram to a file and preview it:
287
+
288
+ ```bash
289
+ codiff diff --base main --format mermaid > mermaid.md
290
+ ```
291
+
292
+ Open `mermaid.md` in any Markdown previewer (VS Code, GitHub, etc.) to visualise the diagram.
293
+
294
+ ## Agent integration (MCP)
295
+
296
+ Run once per project to wire codiff into your coding agent:
297
+
298
+ ```bash
299
+ codiff init --agent claude # Claude Code
300
+ codiff init --agent codex # OpenAI Codex CLI
301
+ codiff init --agent gemini # Gemini CLI
302
+ codiff init --agent vibe # Mistral Vibe
303
+ codiff init --agent github-actions # GitHub Actions
304
+ ```
305
+
306
+ This writes the MCP server config and a project instructions file that tells the agent to call `codiff_diff` when creating pull requests. The agent then automatically embeds a structural diagram in every PR description.
307
+
308
+ The `github-actions` option creates `.github/workflows/codiff.yml`, which posts the diagram as a PR comment on every pull request — no AI coding agent required.
309
+
310
+ > **Note:** Use either an agent integration or the GitHub Action, not both. If both are active, codiff detects the redundancy automatically and the action stays silent when the agent has already embedded a diagram in the PR description.
311
+
312
+ | Agent | MCP config | Instructions file |
313
+ |---|---|---|
314
+ | `claude` | `.mcp.json` | `CLAUDE.md` |
315
+ | `codex` | `.codex/config.toml` | `AGENTS.md` |
316
+ | `gemini` | `~/.gemini/settings.json` | `GEMINI.md` |
317
+ | `vibe` | `~/.vibe/config.toml` | — |
318
+ | `github-actions` | — | `.github/workflows/codiff.yml` |
319
+
320
+
321
+ Here's the output of `codiff diff --base b8dde67 --head d25c385 --format mermaid` run on codiff's own codebase:
244
322
 
245
323
  ```mermaid
246
324
  %%{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'}}}%%
@@ -321,33 +399,18 @@ classDiagram
321
399
 
322
400
  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
401
 
324
- ## Supported languages
325
-
326
- | Language | Extensions |
327
- |---|---|
328
- | Python | `.py` |
329
- | TypeScript | `.ts`, `.tsx` |
330
-
331
402
  ## How it works
332
403
 
333
404
  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
405
 
335
- The graph delta — added, modified, removed functions — is computed deterministically from the resolved call graph. No LLM, no embeddings, fully offline.
406
+ The graph delta — added, modified, removed functions — is computed deterministically from the resolved call graph.
336
407
 
337
408
  ## Requirements
338
409
 
339
410
  - Python 3.11+
340
411
  - Git
341
412
 
342
- ## Installation
343
-
344
- ```bash
345
- pip install codiff
346
- ```
347
-
348
- ## Usage
349
-
350
- ### CLI
413
+ ## CLI reference
351
414
 
352
415
  ```bash
353
416
  # Index a repository (writes .codiff.db — runs automatically on first diff)
@@ -365,7 +428,7 @@ codiff diff --include-deleted # include deleted functions (hidden by defa
365
428
  codiff diff --workers 8 # set parallel worker count (default: cpu_count // 2)
366
429
  codiff diff --debug # print timing breakdown for each processing step
367
430
 
368
- # Configure a coding agent (see Agent integration below)
431
+ # Configure a coding agent
369
432
  codiff init --agent <agent>
370
433
  ```
371
434
 
@@ -377,31 +440,6 @@ codiff init --agent <agent>
377
440
  | `mermaid` | Two Mermaid `classDiagram` blocks — paste into any Markdown file or PR description |
378
441
  | `json` | Structured JSON — consumed by editor integrations (e.g. the VS Code extension) |
379
442
 
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
443
  ## Reading the terminal output
406
444
 
407
445
  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.
@@ -433,10 +471,10 @@ When two changed classes in the same file are related, each class box shows a di
433
471
 
434
472
  ```
435
473
  ╭╌╌╌ PageAwarePreChunker ╌╌╌╮
436
- │ calls PageAwarePreChunkBuilder │
437
- │ ────────────── │
438
- │ + __init__ │
439
- ╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╯
474
+ │ calls PageAwareBuilder │
475
+ │ ────────────── │
476
+ │ + __init__ │
477
+ ╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╯
440
478
  ```
441
479
 
442
480
  Relationship types: `calls` (method calls to another class) and `inherits` (superclass relationship detected from class definitions).
@@ -1,8 +1,86 @@
1
1
  # codiff
2
2
 
3
- 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.
3
+ A structural call-graph diff tool for multi-language codebases, built to work with coding agents.
4
4
 
5
- Here's the output of `codiff diff --base main --format mermaid` run on codiff's own codebase:
5
+ Instead of a line diff, codiff 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.
6
+
7
+ No LLM, no embeddings, fully offline.
8
+
9
+ ## Supported languages
10
+
11
+ | Language | Extensions |
12
+ |---|---|
13
+ | Python | `.py` |
14
+ | TypeScript | `.ts`, `.tsx` |
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ pip install codiff
20
+ ```
21
+
22
+ ## Quickstart
23
+
24
+ ```bash
25
+ # Run from inside any git repository
26
+ codiff diff
27
+ ```
28
+
29
+ This compares your working tree against `HEAD`. If everything is already committed, use `--base` and `--head` to compare two refs explicitly:
30
+
31
+ ```bash
32
+ # Diff between two branches
33
+ codiff diff --base main --head my-feature
34
+
35
+ # Diff introduced by the last commit only
36
+ codiff diff --base HEAD~1 --head HEAD
37
+
38
+ # Diff between two arbitrary commits
39
+ codiff diff --base a1b2c3d --head e4f5g6h
40
+ ```
41
+
42
+ To get a Mermaid diagram (useful for PR descriptions):
43
+
44
+ ```bash
45
+ codiff diff --base main --format mermaid
46
+ ```
47
+
48
+ To save the diagram to a file and preview it:
49
+
50
+ ```bash
51
+ codiff diff --base main --format mermaid > mermaid.md
52
+ ```
53
+
54
+ Open `mermaid.md` in any Markdown previewer (VS Code, GitHub, etc.) to visualise the diagram.
55
+
56
+ ## Agent integration (MCP)
57
+
58
+ Run once per project to wire codiff into your coding agent:
59
+
60
+ ```bash
61
+ codiff init --agent claude # Claude Code
62
+ codiff init --agent codex # OpenAI Codex CLI
63
+ codiff init --agent gemini # Gemini CLI
64
+ codiff init --agent vibe # Mistral Vibe
65
+ codiff init --agent github-actions # GitHub Actions
66
+ ```
67
+
68
+ This writes the MCP server config and a project instructions file that tells the agent to call `codiff_diff` when creating pull requests. The agent then automatically embeds a structural diagram in every PR description.
69
+
70
+ The `github-actions` option creates `.github/workflows/codiff.yml`, which posts the diagram as a PR comment on every pull request — no AI coding agent required.
71
+
72
+ > **Note:** Use either an agent integration or the GitHub Action, not both. If both are active, codiff detects the redundancy automatically and the action stays silent when the agent has already embedded a diagram in the PR description.
73
+
74
+ | Agent | MCP config | Instructions file |
75
+ |---|---|---|
76
+ | `claude` | `.mcp.json` | `CLAUDE.md` |
77
+ | `codex` | `.codex/config.toml` | `AGENTS.md` |
78
+ | `gemini` | `~/.gemini/settings.json` | `GEMINI.md` |
79
+ | `vibe` | `~/.vibe/config.toml` | — |
80
+ | `github-actions` | — | `.github/workflows/codiff.yml` |
81
+
82
+
83
+ Here's the output of `codiff diff --base b8dde67 --head d25c385 --format mermaid` run on codiff's own codebase:
6
84
 
7
85
  ```mermaid
8
86
  %%{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'}}}%%
@@ -83,33 +161,18 @@ classDiagram
83
161
 
84
162
  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.
85
163
 
86
- ## Supported languages
87
-
88
- | Language | Extensions |
89
- |---|---|
90
- | Python | `.py` |
91
- | TypeScript | `.ts`, `.tsx` |
92
-
93
164
  ## How it works
94
165
 
95
166
  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.
96
167
 
97
- The graph delta — added, modified, removed functions — is computed deterministically from the resolved call graph. No LLM, no embeddings, fully offline.
168
+ The graph delta — added, modified, removed functions — is computed deterministically from the resolved call graph.
98
169
 
99
170
  ## Requirements
100
171
 
101
172
  - Python 3.11+
102
173
  - Git
103
174
 
104
- ## Installation
105
-
106
- ```bash
107
- pip install codiff
108
- ```
109
-
110
- ## Usage
111
-
112
- ### CLI
175
+ ## CLI reference
113
176
 
114
177
  ```bash
115
178
  # Index a repository (writes .codiff.db — runs automatically on first diff)
@@ -127,7 +190,7 @@ codiff diff --include-deleted # include deleted functions (hidden by defa
127
190
  codiff diff --workers 8 # set parallel worker count (default: cpu_count // 2)
128
191
  codiff diff --debug # print timing breakdown for each processing step
129
192
 
130
- # Configure a coding agent (see Agent integration below)
193
+ # Configure a coding agent
131
194
  codiff init --agent <agent>
132
195
  ```
133
196
 
@@ -139,31 +202,6 @@ codiff init --agent <agent>
139
202
  | `mermaid` | Two Mermaid `classDiagram` blocks — paste into any Markdown file or PR description |
140
203
  | `json` | Structured JSON — consumed by editor integrations (e.g. the VS Code extension) |
141
204
 
142
- ### Agent integration (MCP + project instructions)
143
-
144
- Run once per project to configure your coding agent:
145
-
146
- ```bash
147
- codiff init --agent claude # Claude Code
148
- codiff init --agent codex # OpenAI Codex CLI
149
- codiff init --agent gemini # Gemini CLI
150
- codiff init --agent vibe # Mistral Vibe
151
- ```
152
-
153
- 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:
154
-
155
- | Agent | MCP config | Instructions file |
156
- |---|---|---|
157
- | `claude` | `.mcp.json` | `CLAUDE.md` |
158
- | `codex` | `.codex/config.toml` | `AGENTS.md` |
159
- | `gemini` | `~/.gemini/settings.json` ¹ | `GEMINI.md` |
160
- | `vibe` | `~/.vibe/config.toml` ² | — |
161
-
162
- ¹ Gemini CLI MCP config is global (not project-scoped). Restart Gemini CLI after running.
163
- ² Mistral Vibe MCP config is global (not project-scoped). Restart Vibe after running.
164
-
165
- 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.
166
-
167
205
  ## Reading the terminal output
168
206
 
169
207
  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.
@@ -195,10 +233,10 @@ When two changed classes in the same file are related, each class box shows a di
195
233
 
196
234
  ```
197
235
  ╭╌╌╌ PageAwarePreChunker ╌╌╌╮
198
- │ calls PageAwarePreChunkBuilder │
199
- │ ────────────── │
200
- │ + __init__ │
201
- ╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╯
236
+ │ calls PageAwareBuilder │
237
+ │ ────────────── │
238
+ │ + __init__ │
239
+ ╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╯
202
240
  ```
203
241
 
204
242
  Relationship types: `calls` (method calls to another class) and `inherits` (superclass relationship detected from class definitions).
@@ -200,19 +200,63 @@ def _init_vibe(repo_path: str) -> None:
200
200
  print("\n Restart Vibe to load the new MCP server.\n")
201
201
 
202
202
 
203
+ _GITHUB_ACTIONS_WORKFLOW = """\
204
+ name: codiff
205
+
206
+ on:
207
+ pull_request:
208
+ types: [opened, synchronize, reopened]
209
+
210
+ jobs:
211
+ codiff:
212
+ runs-on: ubuntu-latest
213
+ permissions:
214
+ pull-requests: write
215
+ steps:
216
+ - uses: issahammoud/codiff-action@v1
217
+ """
218
+
219
+
220
+ def _init_github_actions(repo_path: str) -> None:
221
+ """GitHub Actions: .github/workflows/codiff.yml"""
222
+ workflow_path = Path(repo_path) / ".github" / "workflows" / "codiff.yml"
223
+ label = ".github/workflows/codiff.yml"
224
+
225
+ if workflow_path.exists():
226
+ print(f" ~ {label:<30} codiff workflow already exists, skipped")
227
+ else:
228
+ workflow_path.parent.mkdir(parents=True, exist_ok=True)
229
+ workflow_path.write_text(_GITHUB_ACTIONS_WORKFLOW)
230
+ print(f" + {label:<30} created codiff workflow")
231
+
232
+ print("\n Commit and push .github/workflows/codiff.yml to activate the action.\n")
233
+
234
+
203
235
  _INIT_AGENTS = {
204
236
  "claude": _init_claude,
205
237
  "codex": _init_codex,
206
238
  "gemini": _init_gemini,
207
239
  "vibe": _init_vibe,
240
+ "github-actions": _init_github_actions,
208
241
  }
209
242
 
210
243
 
211
244
  def _run_init(repo_path: str, agent: str) -> None:
245
+ import subprocess
246
+
247
+ from codiff.diff.indexer import ensure_indexed
248
+
212
249
  repo_path = os.path.abspath(repo_path)
213
250
  print(f"\nConfiguring codiff for {agent} in {repo_path}\n")
214
251
  _INIT_AGENTS[agent](repo_path)
215
252
 
253
+ print(" Building initial call-graph index...")
254
+ try:
255
+ ensure_indexed(repo_path, "HEAD", max_workers=_DEFAULT_WORKERS)
256
+ print(" Index complete.\n")
257
+ except subprocess.CalledProcessError:
258
+ print(" Skipped: not a git repository. Index will be built on first diff.\n")
259
+
216
260
 
217
261
  def _run_diff(
218
262
  repo_path: str,
@@ -9,6 +9,7 @@ The only responsibilities here are:
9
9
 
10
10
  import logging
11
11
  import os
12
+ import subprocess
12
13
  import tarfile
13
14
  import tempfile
14
15
 
@@ -50,7 +51,14 @@ def ensure_indexed(repo_path: str, ref: str = "HEAD", max_workers: int = 4) -> s
50
51
  _full_index(repo_path, db_path, ref, sha, max_workers=max_workers)
51
52
  else:
52
53
  logger.info("DB at %s — incremental update to %s", current[:8], sha[:8])
53
- _incremental_update_db(repo_path, db_path, current, sha, max_workers=max_workers)
54
+ try:
55
+ _incremental_update_db(repo_path, db_path, current, sha, max_workers=max_workers)
56
+ except subprocess.CalledProcessError:
57
+ logger.warning(
58
+ "Incremental update failed (SHA %s unreachable) — falling back to full re-index",
59
+ current[:8],
60
+ )
61
+ _full_index(repo_path, db_path, ref, sha, max_workers=max_workers)
54
62
 
55
63
  return sha
56
64
 
@@ -472,4 +472,17 @@ def render_mermaid(result: AnalysisResult) -> str:
472
472
  _build_diagram(d1_body, d1_styles, d1_del, d1_del_styles, edge_lines),
473
473
  _build_diagram(d2_body, d2_styles, d2_del, d2_del_styles, init=_INIT_GRID),
474
474
  ]
475
- return "\n\n".join(d for d in diagrams if d is not None)
475
+ output = "\n\n".join(d for d in diagrams if d is not None)
476
+ if not output:
477
+ return output
478
+
479
+ s = result.summary
480
+ parts = (
481
+ ([f"{s.added_functions} added"] if s.added_functions else [])
482
+ + ([f"{s.modified_functions} modified"] if s.modified_functions else [])
483
+ + ([f"{s.removed_functions} removed"] if s.removed_functions else [])
484
+ )
485
+ n = len(s.modules_touched)
486
+ summary = " · ".join(parts) + f" functions across {n} file{'s' if n != 1 else ''}"
487
+ output = f"{summary}\n\n{output}\n\n<!-- codiff-mermaid -->"
488
+ return output
@@ -166,34 +166,41 @@ def parse_repository(
166
166
  "[timing] file walk (collect): %.2fs (%d files)", time.perf_counter() - t0, len(pending)
167
167
  )
168
168
 
169
- # Phase 2: parse files across worker processes for true CPU parallelism.
170
- # modules_dict is sent once per worker via the initializer — not once per task.
171
- # chunksize batches multiple files per IPC round-trip to reduce pickle overhead.
169
+ # Phase 2: parse files. When max_workers <= 1, run inline in the calling
170
+ # process — no subprocess, no inherited file descriptors (required for MCP
171
+ # stdio servers where child processes inherit the JSON-RPC pipes and corrupt
172
+ # the channel). With multiple workers, use ProcessPoolExecutor as before.
172
173
  t0 = time.perf_counter()
173
- chunksize = max(1, len(pending) // (max_workers * 8))
174
- with ProcessPoolExecutor(
175
- max_workers=max_workers,
176
- initializer=_init_mp_worker,
177
- initargs=(modules_dict,),
178
- ) as pool:
179
- for result in pool.map(_parse_file_mp, pending, chunksize=chunksize):
180
- if result is None:
181
- continue
182
- ext, rel, funcs, classes, imports, mod_doc = result
183
- resolver_cls = ext_to_resolver[ext]
184
- if mod_doc:
185
- module_docstrings[rel] = mod_doc
186
- resolver_funcs[resolver_cls].extend(funcs)
187
- resolver_classes[resolver_cls].extend(classes)
188
- resolver_imports[resolver_cls].update(imports)
189
- for cls in classes:
190
- if cls.docstring:
191
- class_docstrings[cls.name] = cls.docstring
174
+ if max_workers <= 1:
175
+ _init_mp_worker(modules_dict)
176
+ file_results = [_parse_file_mp(args) for args in pending]
177
+ else:
178
+ chunksize = max(1, len(pending) // (max_workers * 8))
179
+ with ProcessPoolExecutor(
180
+ max_workers=max_workers,
181
+ initializer=_init_mp_worker,
182
+ initargs=(modules_dict,),
183
+ ) as pool:
184
+ file_results = list(pool.map(_parse_file_mp, pending, chunksize=chunksize))
185
+
186
+ for result in file_results:
187
+ if result is None:
188
+ continue
189
+ ext, rel, funcs, classes, imports, mod_doc = result
190
+ resolver_cls = ext_to_resolver[ext]
191
+ if mod_doc:
192
+ module_docstrings[rel] = mod_doc
193
+ resolver_funcs[resolver_cls].extend(funcs)
194
+ resolver_classes[resolver_cls].extend(classes)
195
+ resolver_imports[resolver_cls].update(imports)
196
+ for cls in classes:
197
+ if cls.docstring:
198
+ class_docstrings[cls.name] = cls.docstring
192
199
 
193
200
  n_fresh = sum(len(f) for f in resolver_funcs.values())
194
201
  logger.debug(
195
- "[timing] parse files (parallel, %d workers): %.2fs (%d functions, %d classes)",
196
- max_workers,
202
+ "[timing] parse files (%s): %.2fs (%d functions, %d classes)",
203
+ f"{max_workers} workers" if max_workers > 1 else "sequential",
197
204
  time.perf_counter() - t0,
198
205
  n_fresh,
199
206
  sum(len(c) for c in resolver_classes.values()),
@@ -168,10 +168,15 @@ class BaseCallResolver(ABC):
168
168
  global _mp_resolver_instance
169
169
  _mp_resolver_instance = self
170
170
  try:
171
- with ProcessPoolExecutor(max_workers=max_workers) as pool:
172
- for batch_result in pool.map(_resolve_batch_mp, batches, chunksize=1):
173
- for func_id, resolved_calls in batch_result:
171
+ if max_workers <= 1:
172
+ for batch in batches:
173
+ for func_id, resolved_calls in _resolve_batch_mp(batch):
174
174
  id_to_func[func_id].calls = resolved_calls
175
+ else:
176
+ with ProcessPoolExecutor(max_workers=max_workers) as pool:
177
+ for batch_result in pool.map(_resolve_batch_mp, batches, chunksize=1):
178
+ for func_id, resolved_calls in batch_result:
179
+ id_to_func[func_id].calls = resolved_calls
175
180
  finally:
176
181
  _mp_resolver_instance = None
177
182
 
@@ -46,7 +46,7 @@ def codiff_diff(
46
46
  head_ref: Optional[str] = None,
47
47
  include_tests: bool = False,
48
48
  include_deleted: bool = False,
49
- format: str = "terminal",
49
+ format: str = "mermaid",
50
50
  ) -> str:
51
51
  """Compute and render the structural call-graph diff.
52
52
 
@@ -62,6 +62,7 @@ def codiff_diff(
62
62
  head_ref=head_ref,
63
63
  include_tests=include_tests,
64
64
  include_deleted=include_deleted,
65
+ max_workers=1,
65
66
  )
66
67
  head_label = head_ref or "working tree"
67
68
 
@@ -5,7 +5,7 @@ import os
5
5
 
6
6
  DEFAULT_WORKERS: int = max(1, (os.cpu_count() or 2) // 2)
7
7
 
8
- SUPPORTED_AGENTS: list[str] = ["claude", "codex", "gemini", "vibe"]
8
+ SUPPORTED_AGENTS: list[str] = ["claude", "codex", "gemini", "vibe", "github-actions"]
9
9
 
10
10
 
11
11
  def build_parser() -> argparse.ArgumentParser:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codiff
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Structural call-graph diff for codebases, built for coding agents
5
5
  Author-email: Issa Hammoud <issa.hammoud@outlook.com>
6
6
  License: Apache License
@@ -238,9 +238,87 @@ Dynamic: license-file
238
238
 
239
239
  # codiff
240
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.
241
+ A structural call-graph diff tool for multi-language codebases, built to work with coding agents.
242
242
 
243
- Here's the output of `codiff diff --base main --format mermaid` run on codiff's own codebase:
243
+ Instead of a line diff, codiff 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.
244
+
245
+ No LLM, no embeddings, fully offline.
246
+
247
+ ## Supported languages
248
+
249
+ | Language | Extensions |
250
+ |---|---|
251
+ | Python | `.py` |
252
+ | TypeScript | `.ts`, `.tsx` |
253
+
254
+ ## Installation
255
+
256
+ ```bash
257
+ pip install codiff
258
+ ```
259
+
260
+ ## Quickstart
261
+
262
+ ```bash
263
+ # Run from inside any git repository
264
+ codiff diff
265
+ ```
266
+
267
+ This compares your working tree against `HEAD`. If everything is already committed, use `--base` and `--head` to compare two refs explicitly:
268
+
269
+ ```bash
270
+ # Diff between two branches
271
+ codiff diff --base main --head my-feature
272
+
273
+ # Diff introduced by the last commit only
274
+ codiff diff --base HEAD~1 --head HEAD
275
+
276
+ # Diff between two arbitrary commits
277
+ codiff diff --base a1b2c3d --head e4f5g6h
278
+ ```
279
+
280
+ To get a Mermaid diagram (useful for PR descriptions):
281
+
282
+ ```bash
283
+ codiff diff --base main --format mermaid
284
+ ```
285
+
286
+ To save the diagram to a file and preview it:
287
+
288
+ ```bash
289
+ codiff diff --base main --format mermaid > mermaid.md
290
+ ```
291
+
292
+ Open `mermaid.md` in any Markdown previewer (VS Code, GitHub, etc.) to visualise the diagram.
293
+
294
+ ## Agent integration (MCP)
295
+
296
+ Run once per project to wire codiff into your coding agent:
297
+
298
+ ```bash
299
+ codiff init --agent claude # Claude Code
300
+ codiff init --agent codex # OpenAI Codex CLI
301
+ codiff init --agent gemini # Gemini CLI
302
+ codiff init --agent vibe # Mistral Vibe
303
+ codiff init --agent github-actions # GitHub Actions
304
+ ```
305
+
306
+ This writes the MCP server config and a project instructions file that tells the agent to call `codiff_diff` when creating pull requests. The agent then automatically embeds a structural diagram in every PR description.
307
+
308
+ The `github-actions` option creates `.github/workflows/codiff.yml`, which posts the diagram as a PR comment on every pull request — no AI coding agent required.
309
+
310
+ > **Note:** Use either an agent integration or the GitHub Action, not both. If both are active, codiff detects the redundancy automatically and the action stays silent when the agent has already embedded a diagram in the PR description.
311
+
312
+ | Agent | MCP config | Instructions file |
313
+ |---|---|---|
314
+ | `claude` | `.mcp.json` | `CLAUDE.md` |
315
+ | `codex` | `.codex/config.toml` | `AGENTS.md` |
316
+ | `gemini` | `~/.gemini/settings.json` | `GEMINI.md` |
317
+ | `vibe` | `~/.vibe/config.toml` | — |
318
+ | `github-actions` | — | `.github/workflows/codiff.yml` |
319
+
320
+
321
+ Here's the output of `codiff diff --base b8dde67 --head d25c385 --format mermaid` run on codiff's own codebase:
244
322
 
245
323
  ```mermaid
246
324
  %%{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'}}}%%
@@ -321,33 +399,18 @@ classDiagram
321
399
 
322
400
  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
401
 
324
- ## Supported languages
325
-
326
- | Language | Extensions |
327
- |---|---|
328
- | Python | `.py` |
329
- | TypeScript | `.ts`, `.tsx` |
330
-
331
402
  ## How it works
332
403
 
333
404
  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
405
 
335
- The graph delta — added, modified, removed functions — is computed deterministically from the resolved call graph. No LLM, no embeddings, fully offline.
406
+ The graph delta — added, modified, removed functions — is computed deterministically from the resolved call graph.
336
407
 
337
408
  ## Requirements
338
409
 
339
410
  - Python 3.11+
340
411
  - Git
341
412
 
342
- ## Installation
343
-
344
- ```bash
345
- pip install codiff
346
- ```
347
-
348
- ## Usage
349
-
350
- ### CLI
413
+ ## CLI reference
351
414
 
352
415
  ```bash
353
416
  # Index a repository (writes .codiff.db — runs automatically on first diff)
@@ -365,7 +428,7 @@ codiff diff --include-deleted # include deleted functions (hidden by defa
365
428
  codiff diff --workers 8 # set parallel worker count (default: cpu_count // 2)
366
429
  codiff diff --debug # print timing breakdown for each processing step
367
430
 
368
- # Configure a coding agent (see Agent integration below)
431
+ # Configure a coding agent
369
432
  codiff init --agent <agent>
370
433
  ```
371
434
 
@@ -377,31 +440,6 @@ codiff init --agent <agent>
377
440
  | `mermaid` | Two Mermaid `classDiagram` blocks — paste into any Markdown file or PR description |
378
441
  | `json` | Structured JSON — consumed by editor integrations (e.g. the VS Code extension) |
379
442
 
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
443
  ## Reading the terminal output
406
444
 
407
445
  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.
@@ -433,10 +471,10 @@ When two changed classes in the same file are related, each class box shows a di
433
471
 
434
472
  ```
435
473
  ╭╌╌╌ PageAwarePreChunker ╌╌╌╮
436
- │ calls PageAwarePreChunkBuilder │
437
- │ ────────────── │
438
- │ + __init__ │
439
- ╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╯
474
+ │ calls PageAwareBuilder │
475
+ │ ────────────── │
476
+ │ + __init__ │
477
+ ╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╯
440
478
  ```
441
479
 
442
480
  Relationship types: `calls` (method calls to another class) and `inherits` (superclass relationship detected from class definitions).
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "codiff"
7
- version = "0.1.0"
7
+ version = "0.1.2"
8
8
  description = "Structural call-graph diff for codebases, built for coding agents"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes