graphe-code 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Amélien Bergerot
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,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: graphe-code
3
+ Version: 0.1.0
4
+ Summary: The code graph of a host project: what calls what, what cites what.
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.13
7
+ License-File: LICENSE
8
+ Requires-Dist: networkx>=3.6.1
9
+ Requires-Dist: numpy>=2.4.4
10
+ Requires-Dist: scipy>=1.18.1
11
+ Requires-Dist: tree-sitter<0.27,>=0.26.1
12
+ Requires-Dist: tree-sitter-c<0.25,>=0.24.2
13
+ Requires-Dist: tree-sitter-c-sharp<0.25,>=0.24.0
14
+ Requires-Dist: tree-sitter-cpp<0.24,>=0.23.4
15
+ Requires-Dist: tree-sitter-go<0.26,>=0.25.0
16
+ Requires-Dist: tree-sitter-java<0.24,>=0.23.5
17
+ Requires-Dist: tree-sitter-javascript<0.26,>=0.25.0
18
+ Requires-Dist: tree-sitter-kotlin<2,>=1.1.0
19
+ Requires-Dist: tree-sitter-php<0.26,>=0.25.2
20
+ Requires-Dist: tree-sitter-ruby<0.24,>=0.23.1
21
+ Requires-Dist: tree-sitter-rust<0.25,>=0.24.2
22
+ Requires-Dist: tree-sitter-swift<0.8,>=0.7.4
23
+ Requires-Dist: tree-sitter-typescript<0.24,>=0.23.2
24
+ Dynamic: license-file
@@ -0,0 +1,147 @@
1
+ # graphe
2
+
3
+ The code graph of a host project: what calls what, what cites what. `graphe --help` lists the commands.
4
+
5
+ ## Why
6
+
7
+ An agent that navigates code (or a person) finds its way with grep, then reads files to sort out what grep matched. Grep matches text: `.step(` finds the `step` of every class, plus comments and strings. Graphe reads the code once, links each call to its definition, and answers a question about a function in a few hundred bytes: what it calls, what calls it, and the tickets that cite it. One query costs 2 to 12 times fewer tokens than grep plus reading ([Tested on](#tested-on)), and it is more exact.
8
+
9
+ It also links code to its documents. A Markdown ticket that names a function between backticks cites it, so `explain` says which tickets motivated some code. A text shown on screen (the `displayed_text` pattern of `graphe.toml`) leads back to the function that displays it. A key both ends share, such as a route the front requests and the back answers, links them (a *keyed link*, `[keys]` of `graphe.toml`), where no name in the code does.
10
+
11
+ It says where it stops. A link guessed from the name alone is marked `[by name]` or `?`. When some calls cannot be attributed (a receiver of unknown type, a name several classes bear), the answer says so: "+ N calls named `f` the graph could not attribute: grep them".
12
+
13
+ ```
14
+ $ graphe explain assemble
15
+ assemble() [function] src/graphe/cli.py:223-254
16
+
17
+ what it calls:
18
+ calls (5)
19
+ src/graphe/cli.py: _declared_extensions:153, _extension:157, _insert:174, _take_over:207, _sorted:263
20
+ cites (2)
21
+ T-0007, T-0008
22
+
23
+ what calls it:
24
+ calls (2)
25
+ src/graphe/cli.py: build:408, check:848
26
+ names (3) [by name]
27
+ T-0012, T-0025, T-0034
28
+ ```
29
+
30
+ ## What it reads
31
+
32
+ | How | What |
33
+ |---|---|
34
+ | Through imports and types (sure links) | Python, JavaScript, TypeScript, Svelte (script and markup), GDScript (Godot) |
35
+ | By name (the generic reader, `[by name]` links) | Go, Rust, Java, Kotlin, C, C++, C#, Ruby, Swift, PHP |
36
+ | Documents | Markdown: tickets and documents, and what they cite |
37
+ | Frameworks | None specifically: a front-to-back link (a route the front requests and the back answers) through `[keys]` of `graphe.toml` |
38
+ | Not read | `.jsx`, `.tsx`, Vue |
39
+
40
+ Each language in detail, with its suffixes: [docs/readers.md](docs/readers.md).
41
+
42
+ ## Install
43
+
44
+ The same commands on Windows, macOS and Linux, with [uv](https://docs.astral.sh/uv/) (it fetches the Python graphe needs):
45
+
46
+ ```
47
+ uv tool install graphe-code
48
+ ```
49
+
50
+ The command is `graphe`. If `graphe-cli` (a CLI for the Graphe API) already installed a `graphe` command, uv refuses to replace it without `--force`.
51
+
52
+ The Claude Code skill, which teaches the command to the agent in every project, is a plugin; this repository is its marketplace:
53
+
54
+ ```
55
+ claude plugin install graphe --marketplace amelienbergerot/graphe
56
+ ```
57
+
58
+ Without an allow rule, each `graphe` query asks for approval (and a headless `claude -p` falls back to grep): add `Bash(graphe *)` and `PowerShell(graphe *)` to `permissions.allow` in `~/.claude/settings.json`.
59
+
60
+ Another agent: copy the [`skills/graphe/`](skills/graphe) folder where that agent reads its skills (the Agent Skills format).
61
+
62
+ ## First graph
63
+
64
+ From inside a git repository (graphe reads the files git tracks):
65
+
66
+ ```
67
+ cd my-project
68
+ graphe install # the git hooks that rebuild the graph after a commit, merge or checkout; graphe/ git-ignored
69
+ graphe explain main # any function of the project: the first query builds the graph
70
+ ```
71
+
72
+ No configuration is needed. A `graphe.toml` at the repository's root is optional; every key in it is too:
73
+
74
+ ```toml
75
+ exclude = ["vendor", "**/fixtures"] # folders graphe does not read
76
+ displayed_text = '\btr\("([^"]*)"' # the call that shows a text on screen, the text in its group
77
+
78
+ [keys] # a link from the code that names a key to the code that answers it
79
+ names = 'api\("([^"]+)"' # the front's api("zones")
80
+ answers = '"/api/([^"]+)"' # the back's "/api/zones"
81
+ ```
82
+
83
+ Every key, and the local extensions: [docs/contribution.md](docs/contribution.md).
84
+
85
+ A gap in the graph (a call it should have linked, a language it misreads) is welcome in the [GitHub issues](https://github.com/amelienbergerot/graphe/issues).
86
+
87
+ ## How it works
88
+
89
+ 1. **Files**: graphe reads the files git tracks, plus untracked files that are not ignored, minus the folders listed in `exclude` in the host's optional `graphe.toml`. Each file goes to the reader for its extension.
90
+ 2. **Readers** turn the files into nodes (files, classes, functions, methods, fields, constants) and links between them (`calls`, `contains`, `uses`, `reads`). A *dedicated reader* (Python through its ast, JavaScript/TypeScript/Svelte, GDScript) follows imports and types, so it can link a call to its definition with certainty. The *generic reader* (tree-sitter: Go, Rust, Java/Kotlin, C/C++, C#, Ruby, Swift, PHP) links a call by name, and only when the language defines that name once. It never does this for a common name like `get` or `push`.
91
+ 3. **The core** reads the text: where each body ends, its comment, the texts it displays, module variables and who reads them, and the Markdown documents with what they cite (code between backticks, other documents by identifier, `T-0012`). With `[keys]` in `graphe.toml`, it links the code that names a key to the code that answers it (`sends`).
92
+ 4. **Local extensions** add enrichments that only make sense for one host. They live in the host's repository and are declared in its `graphe.toml` ([ADR 0001](docs/adr/0001-one-tool-local-extensions.md), [the contract](docs/contribution.md)). A `graphe.toml` that declares extensions runs their code at every build, the git hooks' included, like a Makefile: build a cloned repository only if you trust it.
93
+ 5. **Output**, in the host's `graphe/` folder (git-ignored): `graphe.json` (the graph, its communities found with Louvain) and `REPORT.md` (counts, the most connected nodes). The page that draws the nodes by community, `graphe.html`, is made only on demand, whatever the host's size: `graphe view` writes and opens it, `graphe view X` on node X.
94
+ 6. **Freshness**: the git hooks rebuild the graph in the background after a commit, merge, checkout or rewrite. A query on a graph older than the code or the tool rebuilds it first, so the answer can be trusted.
95
+
96
+ Words such as *reader*, *contribution* and *takeover* are defined in [GLOSSARY.md](GLOSSARY.md).
97
+
98
+ ## Readers
99
+
100
+ The languages the graph reads, and how each is read: [docs/readers.md](docs/readers.md).
101
+
102
+ ## Tested on
103
+
104
+ Public sample hosts, pinned in `docs/sample-hosts.md`. Measures only: the build on this machine (Windows, median of three, warm), one query against grep's lines for the same name.
105
+
106
+ | Host | Languages | Files | Build | One query, compared with grep |
107
+ |---|---|---|---|---|
108
+ | Django | Python, JavaScript | 7104 (2943 `.py`) | 54.8 s | `explain django/shortcuts.py::get_object_or_404`: 5 callers, 839 bytes; grep `get_object_or_404(`: 21 lines, 2130 bytes |
109
+ | gitea | Go, TypeScript | 6431 (3199 `.go`) | 31.4 s | `explain GetRepositoryByID`: 76 callers by name, 1778 bytes; grep `GetRepositoryByID(`: 80 lines in 63 files, 7973 bytes |
110
+ | libsignal | Rust, Java/Kotlin, Swift, TypeScript | 1852 (612 `.rs`, 344 `.java`, 218 `.swift`, 125 `.kt`) | 20.6 s | `explain Timestamp.from_epoch_millis`: 57 callers by name, 1577 bytes; grep `from_epoch_millis(`: 81 lines in 30 files, 8260 bytes |
111
+ | protobuf | C/C++, Java/Kotlin, C#, Ruby, Python, Rust, PHP, Go | 3795 (1363 C/C++, 293 `.java`, 224 `.cs`, 158 `.php`, 54 `.rb`) | 62.7 s | `callers ByteString.copyFromUtf8`: 128 callers by name, 11526 bytes; grep `copyFromUtf8(` in `.java` and `.kt`: 176 lines in 44 files, 26514 bytes |
112
+
113
+ ## Developing graphe
114
+
115
+ The author's install, from the root of a clone, editable, so that a change in the clone serves every host at once ([ADR 0004](docs/adr/0004-published-install-editable-for-the-author.md)):
116
+
117
+ ```
118
+ uv tool install -e .
119
+ ```
120
+
121
+ An install made before the distribution became `graphe-code` is named `graphe` for uv: remove it once, then install as above.
122
+
123
+ ```
124
+ uv tool uninstall graphe
125
+ ```
126
+
127
+ The skill, as a link to the clone rather than the plugin (a plugin is a cached copy, which would lag the clone):
128
+
129
+ ```powershell
130
+ # Windows: a junction.
131
+ New-Item -ItemType Junction -Path "$HOME\.claude\skills\graphe" -Target "$PWD\skills\graphe"
132
+ ```
133
+
134
+ ```sh
135
+ # macOS, Linux: a symbolic link.
136
+ ln -s "$PWD/skills/graphe" ~/.claude/skills/graphe
137
+ ```
138
+
139
+ The gaps met while using the graph go in `BACKLOG.md`, naming the host (`AGENTS.md`).
140
+
141
+ A release (`.github/workflows/release.yml`), in one commit then a tag:
142
+
143
+ 1. Set the same version `X.Y.Z` in `pyproject.toml` and `.claude-plugin/plugin.json`.
144
+ 2. Add its entry `## X.Y.Z` to `CHANGELOG.md`, with a **Contract** section if it changes `contribute(project)`, `Project` or the shape of the nodes and links.
145
+ 3. Commit, then push the tag: `git tag vX.Y.Z` and `git push origin vX.Y.Z`. The workflow stops before the upload if the tag and the two versions differ (`python .github/check_release.py vX.Y.Z` checks it locally), then uploads `graphe-code` to PyPI and creates the GitHub release.
146
+
147
+ Raising a grammar's cap, when the newest-versions job flags one, is an ordinary commit, not a release step.
@@ -0,0 +1,51 @@
1
+ [project]
2
+ name = "graphe-code"
3
+ version = "0.1.0"
4
+ description = "The code graph of a host project: what calls what, what cites what."
5
+ license = "MIT"
6
+ license-files = ["LICENSE"]
7
+ requires-python = ">=3.13"
8
+ # Exact versions live in uv.lock; tree-sitter grammars capped at the next minor, as the queries name their node types.
9
+ dependencies = [
10
+ "networkx>=3.6.1",
11
+ "numpy>=2.4.4",
12
+ "scipy>=1.18.1",
13
+ "tree-sitter>=0.26.1,<0.27",
14
+ "tree-sitter-c>=0.24.2,<0.25",
15
+ "tree-sitter-c-sharp>=0.24.0,<0.25",
16
+ "tree-sitter-cpp>=0.23.4,<0.24",
17
+ "tree-sitter-go>=0.25.0,<0.26",
18
+ "tree-sitter-java>=0.23.5,<0.24",
19
+ "tree-sitter-javascript>=0.25.0,<0.26",
20
+ "tree-sitter-kotlin>=1.1.0,<2",
21
+ "tree-sitter-php>=0.25.2,<0.26",
22
+ "tree-sitter-ruby>=0.23.1,<0.24",
23
+ "tree-sitter-rust>=0.24.2,<0.25",
24
+ "tree-sitter-swift>=0.7.4,<0.8",
25
+ "tree-sitter-typescript>=0.23.2,<0.24",
26
+ ]
27
+
28
+ [project.scripts]
29
+ graphe = "graphe.cli:main"
30
+
31
+ [dependency-groups]
32
+ dev = ["pytest==9.1.1"]
33
+
34
+ [build-system]
35
+ requires = ["setuptools>=77"]
36
+ build-backend = "setuptools.build_meta"
37
+
38
+ [tool.setuptools]
39
+ package-dir = { "" = "src" }
40
+ packages = ["graphe"]
41
+
42
+ [tool.pytest.ini_options]
43
+ testpaths = ["tests"]
44
+
45
+ # Grid Zero's rules, where the code comes from.
46
+ [tool.ruff]
47
+ target-version = "py313"
48
+
49
+ [tool.ruff.lint]
50
+ select = ["E4", "E7", "E9", "F", "B", "UP"]
51
+ ignore = ["E741"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes