graphsnip 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.
- graphsnip-0.1.0/LICENSE +202 -0
- graphsnip-0.1.0/NOTICE +7 -0
- graphsnip-0.1.0/PKG-INFO +186 -0
- graphsnip-0.1.0/README.md +168 -0
- graphsnip-0.1.0/pyproject.toml +35 -0
- graphsnip-0.1.0/setup.cfg +4 -0
- graphsnip-0.1.0/src/graphsnip/__init__.py +3 -0
- graphsnip-0.1.0/src/graphsnip/__main__.py +4 -0
- graphsnip-0.1.0/src/graphsnip/baseline.py +89 -0
- graphsnip-0.1.0/src/graphsnip/bench.py +208 -0
- graphsnip-0.1.0/src/graphsnip/cli.py +368 -0
- graphsnip-0.1.0/src/graphsnip/dashboard.py +322 -0
- graphsnip-0.1.0/src/graphsnip/engine.py +453 -0
- graphsnip-0.1.0/src/graphsnip/hooks.py +178 -0
- graphsnip-0.1.0/src/graphsnip/installer.py +291 -0
- graphsnip-0.1.0/src/graphsnip/ledger.py +88 -0
- graphsnip-0.1.0/src/graphsnip/mcp_server.py +146 -0
- graphsnip-0.1.0/src/graphsnip/project.py +308 -0
- graphsnip-0.1.0/src/graphsnip/py.typed +0 -0
- graphsnip-0.1.0/src/graphsnip/shellfilter.py +116 -0
- graphsnip-0.1.0/src/graphsnip/slicer.py +217 -0
- graphsnip-0.1.0/src/graphsnip/tokens.py +35 -0
- graphsnip-0.1.0/src/graphsnip.egg-info/PKG-INFO +186 -0
- graphsnip-0.1.0/src/graphsnip.egg-info/SOURCES.txt +28 -0
- graphsnip-0.1.0/src/graphsnip.egg-info/dependency_links.txt +1 -0
- graphsnip-0.1.0/src/graphsnip.egg-info/entry_points.txt +2 -0
- graphsnip-0.1.0/src/graphsnip.egg-info/requires.txt +7 -0
- graphsnip-0.1.0/src/graphsnip.egg-info/top_level.txt +1 -0
- graphsnip-0.1.0/tests/test_core.py +143 -0
- graphsnip-0.1.0/tests/test_integrations.py +142 -0
graphsnip-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
graphsnip-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
graphsnip
|
|
2
|
+
Copyright 2026 Nithin and the graphsnip contributors.
|
|
3
|
+
|
|
4
|
+
graphsnip is a companion layer built on top of Graphify
|
|
5
|
+
(https://github.com/Graphify-Labs/graphify), which is licensed under the
|
|
6
|
+
Apache License 2.0. Graphify is a separate project; graphsnip calls it as a
|
|
7
|
+
library and does not copy its source.
|
graphsnip-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: graphsnip
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Token-saving layer on top of Graphify: symbol-level code slicing, context packs, a savings ledger with an honest baseline, hooks and MCP for Claude Code, Copilot and Codex.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Repository, https://github.com/naubadnithin7/codegraf
|
|
7
|
+
Keywords: graphify,knowledge-graph,tokens,claude-code,copilot,codex,mcp,tree-sitter
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Requires-Dist: graphifyy>=0.9
|
|
13
|
+
Provides-Extra: accurate
|
|
14
|
+
Requires-Dist: tiktoken>=0.7; extra == "accurate"
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# graphsnip
|
|
20
|
+
|
|
21
|
+
**A token-saving layer on top of [Graphify](https://github.com/Graphify-Labs/graphify).**
|
|
22
|
+
|
|
23
|
+
Graphify turns a codebase into a knowledge graph (tree-sitter, no LLM, runs locally). graphsnip uses that graph to give coding agents *exactly the code they need* instead of whole files, and then **proves the savings** with an honest baseline and a dashboard you can put on a projector.
|
|
24
|
+
|
|
25
|
+
Works with **Claude Code**, **GitHub Copilot** (VS Code / CLI) and **Codex**.
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
your repo ──► Graphify (AST → graph.json, graph.html, communities)
|
|
29
|
+
│
|
|
30
|
+
▼
|
|
31
|
+
┌───────────────────── graphsnip ─────────────────────┐
|
|
32
|
+
│ symbol slicer · context packs · session dedupe │
|
|
33
|
+
│ budgeted tools · hooks · shell compressor│
|
|
34
|
+
│ savings ledger (honest baseline) · dashboard │
|
|
35
|
+
└──────────────┬───────────────────────────┬──────────┘
|
|
36
|
+
▼ ▼
|
|
37
|
+
MCP server (gs_pack, gs_symbol, …) .graphsnip/dashboard.html
|
|
38
|
+
Claude Code · Copilot · Codex (+ Graphify's graph.html embedded)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Demo in three commands
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pipx install graphsnip # or: uvx graphsnip … (see "Install")
|
|
45
|
+
cd your-repo
|
|
46
|
+
graphsnip demo --open # graph → benchmark → dashboard
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Then wire it into your agents and watch live savings land in the same dashboard:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
graphsnip init # graph + MCP + hooks + guidance for claude, copilot, codex
|
|
53
|
+
graphsnip report --open # refresh the dashboard from real agent usage
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## What Graphify gives you vs. what graphsnip adds
|
|
57
|
+
|
|
58
|
+
| | Graphify | graphsnip |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| Parse code → knowledge graph, communities, `graph.html` | ✅ | uses it, embeds it |
|
|
61
|
+
| `query` / `path` / `explain` / `affected` | ✅ (maps, no source code) | wraps them, adds the code |
|
|
62
|
+
| Returns **exact source of one symbol** (not the file) | – | `gs_symbol` (tree-sitter ranges, docstring trimming) |
|
|
63
|
+
| One-call **context pack** for a task, under a token budget | – | `gs_pack` (graph-ranked, class skeletons, signatures) |
|
|
64
|
+
| Suppresses re-sending code the agent already has | – | per-session dedupe |
|
|
65
|
+
| Redirects broad `Read` / `grep` to the graph when it can answer | partial | PreToolUse hook with nudge / strict modes |
|
|
66
|
+
| Compresses noisy test/build output | – | `graphsnip run -- <cmd>` (exact savings) |
|
|
67
|
+
| **Measures** savings against a realistic baseline | corpus-vs-query only | per-call ledger, benchmark, dashboard |
|
|
68
|
+
| Installs for Claude Code, Copilot, Codex | skills / rules | MCP + hooks + guidance + subagent, idempotent and reversible |
|
|
69
|
+
|
|
70
|
+
## Measured results
|
|
71
|
+
|
|
72
|
+
Same eight questions per repo, priced as tokens an agent would put in context.
|
|
73
|
+
Baseline = *grep the question's terms, read the top 8 matching files in full* (what an agent does with no graph).
|
|
74
|
+
"Graphify + read" = Graphify `query`, then reading the whole files its top hits point to.
|
|
75
|
+
Token counts use the chars/4 estimate (install `graphsnip[accurate]` for tiktoken).
|
|
76
|
+
|
|
77
|
+
| Repo | grep + read | Graphify + read | graphsnip | vs grep + read | vs Graphify + read | answered with code |
|
|
78
|
+
|---|---:|---:|---:|---:|---:|---:|
|
|
79
|
+
| Flask (Python, 1,500 symbols) | 366,565 | 164,491 | 17,869 | **95.1%** | 89.1% | 8/8 |
|
|
80
|
+
| Express (JavaScript) | 165,832 | 58,553 | 8,955 | **94.6%** | 84.7% | 8/8 |
|
|
81
|
+
|
|
82
|
+
Graphify's bare `query` is cheaper still (about 13k and 18k tokens across the eight tasks) but returns a map with **no source code**, so the agent still has to read files afterwards. graphsnip returns the map *and* the code in the same step. A task counts as answered only if the expected symbol appears with its source.
|
|
83
|
+
|
|
84
|
+
Reproduce: `graphsnip bench` (tasks live in `.graphsnip/tasks.json`; replace them with your own questions).
|
|
85
|
+
|
|
86
|
+
## Install
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
pipx install graphsnip # recommended
|
|
90
|
+
# or
|
|
91
|
+
uvx graphsnip init # run without installing
|
|
92
|
+
# or
|
|
93
|
+
npx graphsnip init # thin wrapper, needs Python 3.10+ and pipx/uv
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Requires Python 3.10+. Graphify is installed as a dependency (`graphifyy`).
|
|
97
|
+
|
|
98
|
+
## Commands
|
|
99
|
+
|
|
100
|
+
| Command | What it does |
|
|
101
|
+
|---|---|
|
|
102
|
+
| `graphsnip init` | build graph, install integrations, benchmark, write dashboard (`--dry-run` previews, writes nothing) |
|
|
103
|
+
| `graphsnip demo [--open] [--bundle DIR]` | graph + benchmark + dashboard in one go; `--bundle` makes a shareable folder |
|
|
104
|
+
| `graphsnip build [--force]` | build or refresh the Graphify graph (code only, no LLM) |
|
|
105
|
+
| `graphsnip pack "task"` | token-budgeted bundle of the code relevant to a task |
|
|
106
|
+
| `graphsnip find "question"` | budgeted map: where things live, how they connect |
|
|
107
|
+
| `graphsnip symbol Name` | one function/class: exact lines + callers + callees |
|
|
108
|
+
| `graphsnip impact Name` | what depends on a symbol |
|
|
109
|
+
| `graphsnip outline path` | symbols in a file with line numbers |
|
|
110
|
+
| `graphsnip run -- <cmd>` | run a command, compress its output, keep the exit code |
|
|
111
|
+
| `graphsnip stats` / `report` | savings in the terminal / the HTML dashboard |
|
|
112
|
+
| `graphsnip bench` | offline benchmark: grep+read vs Graphify vs graphsnip |
|
|
113
|
+
| `graphsnip install` / `uninstall` | per-client config (`--clients claude,copilot,codex`) |
|
|
114
|
+
| `graphsnip doctor` | check Python, Graphify, tree-sitter, graph freshness, client configs |
|
|
115
|
+
|
|
116
|
+
Every query command prints `~N tokens returned vs ~M for grep+read → saved P%` to stderr. That is the number to show live.
|
|
117
|
+
|
|
118
|
+
## MCP tools
|
|
119
|
+
|
|
120
|
+
| Tool | Use it for |
|
|
121
|
+
|---|---|
|
|
122
|
+
| `gs_pack(task, budget)` | first call for "how does X work" or before a change |
|
|
123
|
+
| `gs_find(question, budget)` | locate things (map only) |
|
|
124
|
+
| `gs_symbol(name, max_lines, docs)` | read one definition instead of the file |
|
|
125
|
+
| `gs_impact(name, depth)` | blast radius before changing a signature |
|
|
126
|
+
| `gs_outline(path)` | symbols of a big file before opening it |
|
|
127
|
+
| `gs_savings()` | tokens saved so far |
|
|
128
|
+
|
|
129
|
+
The server is a small dependency-free stdio JSON-RPC implementation (it does not depend on the MCP SDK's changing API). It auto-refreshes a stale graph and records every call in `.graphsnip/ledger.jsonl`.
|
|
130
|
+
|
|
131
|
+
## What `install` writes
|
|
132
|
+
|
|
133
|
+
Everything is idempotent (run it twice, nothing changes) and reversible (`graphsnip uninstall`). Your existing content is preserved: text files get a marked block, JSON is merged.
|
|
134
|
+
|
|
135
|
+
| Client | Files |
|
|
136
|
+
|---|---|
|
|
137
|
+
| Claude Code | `.mcp.json`, `.claude/settings.json` (PreToolUse hook), `CLAUDE.md` block, `.claude/agents/graphsnip-explorer.md` (read-only Haiku subagent) |
|
|
138
|
+
| Copilot (VS Code) | `.vscode/mcp.json`, `.github/copilot-instructions.md` block |
|
|
139
|
+
| Codex | `.codex/config.toml` (or `~/.codex/config.toml` with `--codex-scope user`), `AGENTS.md` block |
|
|
140
|
+
|
|
141
|
+
Flags: `--allow-tools` pre-approves the read-only tools in Claude Code, `--portable` writes bare `graphsnip` instead of this machine's absolute path (use it before committing the configs), `--strict` sets hook mode to strict.
|
|
142
|
+
|
|
143
|
+
## Hooks (Claude Code)
|
|
144
|
+
|
|
145
|
+
Fail-open: any error means "do nothing". Configure in `.graphsnip/config.json` (or `GRAPHSNIP_MODE`).
|
|
146
|
+
|
|
147
|
+
| Mode | Behaviour |
|
|
148
|
+
|---|---|
|
|
149
|
+
| `nudge` (default) | adds context: the file's outline for big reads, `gs_symbol("X")` when a grep pattern is a known symbol. Blocks nothing |
|
|
150
|
+
| `strict` | denies those same calls with a reason that tells the agent what to call. Literal-string greps and reads with `offset`/`limit` are never blocked |
|
|
151
|
+
| `off` | nothing |
|
|
152
|
+
|
|
153
|
+
`shell_filter: true` additionally rewrites noisy test/build commands to run through `graphsnip run`. It is **off by default** because the rewrite returns an `allow` decision, which skips the permission prompt; it is limited to an allow-list and never touches pipelines or chained commands. POSIX shells only.
|
|
154
|
+
|
|
155
|
+
## How the numbers are measured (and what they are not)
|
|
156
|
+
|
|
157
|
+
- **Baseline per call.** `find`/`pack`: grep the question's terms, read the top 8 matching files in full. `symbol`: read the whole file. `impact`: grep the name, read matching files (cap 10). Deliberately far below "read the whole repo", the figure Graphify's own `benchmark` compares against.
|
|
158
|
+
- **Counted once.** In a real session, tokens that stay in context are re-sent every turn, so true savings compound. The dashboard does not claim that.
|
|
159
|
+
- **Shell savings are exact** (raw vs compressed output), not estimated.
|
|
160
|
+
- **Quality is checked**, not assumed (see `answered` above).
|
|
161
|
+
- **Cost** is `tokens saved × price per million input tokens` (default $3, set `price_per_mtok` in the config). It ignores caching discounts and output tokens.
|
|
162
|
+
|
|
163
|
+
## Known limits
|
|
164
|
+
|
|
165
|
+
- Hooks and the three client configs follow each tool's documented formats, but only the MCP server was verified against a real client in development (the official MCP Python client). Run `graphsnip doctor` and a short session in each client before relying on them.
|
|
166
|
+
- Symbol slicing is exact for the ~25 languages with tree-sitter grammars installed; elsewhere it falls back to indentation / brace matching.
|
|
167
|
+
- The graph only covers what Graphify extracts from code. Docs, PDFs and images need Graphify's semantic pass (needs an LLM key) and are not part of graphsnip's tools.
|
|
168
|
+
- Graphify's `graph.html` loads vis-network from a CDN; graphsnip caches it locally so the dashboard works offline (needs internet once).
|
|
169
|
+
|
|
170
|
+
## Development
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
pip install -e ".[dev]"
|
|
174
|
+
pytest -q
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Publishing
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
python -m build && twine upload dist/* # PyPI (name `graphsnip`)
|
|
181
|
+
cd npm && npm publish # npm wrapper (name `graphsnip`)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
Apache-2.0. graphsnip is a separate project that calls Graphify (also Apache-2.0) as a library; see `NOTICE`.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# graphsnip
|
|
2
|
+
|
|
3
|
+
**A token-saving layer on top of [Graphify](https://github.com/Graphify-Labs/graphify).**
|
|
4
|
+
|
|
5
|
+
Graphify turns a codebase into a knowledge graph (tree-sitter, no LLM, runs locally). graphsnip uses that graph to give coding agents *exactly the code they need* instead of whole files, and then **proves the savings** with an honest baseline and a dashboard you can put on a projector.
|
|
6
|
+
|
|
7
|
+
Works with **Claude Code**, **GitHub Copilot** (VS Code / CLI) and **Codex**.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
your repo ──► Graphify (AST → graph.json, graph.html, communities)
|
|
11
|
+
│
|
|
12
|
+
▼
|
|
13
|
+
┌───────────────────── graphsnip ─────────────────────┐
|
|
14
|
+
│ symbol slicer · context packs · session dedupe │
|
|
15
|
+
│ budgeted tools · hooks · shell compressor│
|
|
16
|
+
│ savings ledger (honest baseline) · dashboard │
|
|
17
|
+
└──────────────┬───────────────────────────┬──────────┘
|
|
18
|
+
▼ ▼
|
|
19
|
+
MCP server (gs_pack, gs_symbol, …) .graphsnip/dashboard.html
|
|
20
|
+
Claude Code · Copilot · Codex (+ Graphify's graph.html embedded)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Demo in three commands
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pipx install graphsnip # or: uvx graphsnip … (see "Install")
|
|
27
|
+
cd your-repo
|
|
28
|
+
graphsnip demo --open # graph → benchmark → dashboard
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then wire it into your agents and watch live savings land in the same dashboard:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
graphsnip init # graph + MCP + hooks + guidance for claude, copilot, codex
|
|
35
|
+
graphsnip report --open # refresh the dashboard from real agent usage
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## What Graphify gives you vs. what graphsnip adds
|
|
39
|
+
|
|
40
|
+
| | Graphify | graphsnip |
|
|
41
|
+
|---|---|---|
|
|
42
|
+
| Parse code → knowledge graph, communities, `graph.html` | ✅ | uses it, embeds it |
|
|
43
|
+
| `query` / `path` / `explain` / `affected` | ✅ (maps, no source code) | wraps them, adds the code |
|
|
44
|
+
| Returns **exact source of one symbol** (not the file) | – | `gs_symbol` (tree-sitter ranges, docstring trimming) |
|
|
45
|
+
| One-call **context pack** for a task, under a token budget | – | `gs_pack` (graph-ranked, class skeletons, signatures) |
|
|
46
|
+
| Suppresses re-sending code the agent already has | – | per-session dedupe |
|
|
47
|
+
| Redirects broad `Read` / `grep` to the graph when it can answer | partial | PreToolUse hook with nudge / strict modes |
|
|
48
|
+
| Compresses noisy test/build output | – | `graphsnip run -- <cmd>` (exact savings) |
|
|
49
|
+
| **Measures** savings against a realistic baseline | corpus-vs-query only | per-call ledger, benchmark, dashboard |
|
|
50
|
+
| Installs for Claude Code, Copilot, Codex | skills / rules | MCP + hooks + guidance + subagent, idempotent and reversible |
|
|
51
|
+
|
|
52
|
+
## Measured results
|
|
53
|
+
|
|
54
|
+
Same eight questions per repo, priced as tokens an agent would put in context.
|
|
55
|
+
Baseline = *grep the question's terms, read the top 8 matching files in full* (what an agent does with no graph).
|
|
56
|
+
"Graphify + read" = Graphify `query`, then reading the whole files its top hits point to.
|
|
57
|
+
Token counts use the chars/4 estimate (install `graphsnip[accurate]` for tiktoken).
|
|
58
|
+
|
|
59
|
+
| Repo | grep + read | Graphify + read | graphsnip | vs grep + read | vs Graphify + read | answered with code |
|
|
60
|
+
|---|---:|---:|---:|---:|---:|---:|
|
|
61
|
+
| Flask (Python, 1,500 symbols) | 366,565 | 164,491 | 17,869 | **95.1%** | 89.1% | 8/8 |
|
|
62
|
+
| Express (JavaScript) | 165,832 | 58,553 | 8,955 | **94.6%** | 84.7% | 8/8 |
|
|
63
|
+
|
|
64
|
+
Graphify's bare `query` is cheaper still (about 13k and 18k tokens across the eight tasks) but returns a map with **no source code**, so the agent still has to read files afterwards. graphsnip returns the map *and* the code in the same step. A task counts as answered only if the expected symbol appears with its source.
|
|
65
|
+
|
|
66
|
+
Reproduce: `graphsnip bench` (tasks live in `.graphsnip/tasks.json`; replace them with your own questions).
|
|
67
|
+
|
|
68
|
+
## Install
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pipx install graphsnip # recommended
|
|
72
|
+
# or
|
|
73
|
+
uvx graphsnip init # run without installing
|
|
74
|
+
# or
|
|
75
|
+
npx graphsnip init # thin wrapper, needs Python 3.10+ and pipx/uv
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Requires Python 3.10+. Graphify is installed as a dependency (`graphifyy`).
|
|
79
|
+
|
|
80
|
+
## Commands
|
|
81
|
+
|
|
82
|
+
| Command | What it does |
|
|
83
|
+
|---|---|
|
|
84
|
+
| `graphsnip init` | build graph, install integrations, benchmark, write dashboard (`--dry-run` previews, writes nothing) |
|
|
85
|
+
| `graphsnip demo [--open] [--bundle DIR]` | graph + benchmark + dashboard in one go; `--bundle` makes a shareable folder |
|
|
86
|
+
| `graphsnip build [--force]` | build or refresh the Graphify graph (code only, no LLM) |
|
|
87
|
+
| `graphsnip pack "task"` | token-budgeted bundle of the code relevant to a task |
|
|
88
|
+
| `graphsnip find "question"` | budgeted map: where things live, how they connect |
|
|
89
|
+
| `graphsnip symbol Name` | one function/class: exact lines + callers + callees |
|
|
90
|
+
| `graphsnip impact Name` | what depends on a symbol |
|
|
91
|
+
| `graphsnip outline path` | symbols in a file with line numbers |
|
|
92
|
+
| `graphsnip run -- <cmd>` | run a command, compress its output, keep the exit code |
|
|
93
|
+
| `graphsnip stats` / `report` | savings in the terminal / the HTML dashboard |
|
|
94
|
+
| `graphsnip bench` | offline benchmark: grep+read vs Graphify vs graphsnip |
|
|
95
|
+
| `graphsnip install` / `uninstall` | per-client config (`--clients claude,copilot,codex`) |
|
|
96
|
+
| `graphsnip doctor` | check Python, Graphify, tree-sitter, graph freshness, client configs |
|
|
97
|
+
|
|
98
|
+
Every query command prints `~N tokens returned vs ~M for grep+read → saved P%` to stderr. That is the number to show live.
|
|
99
|
+
|
|
100
|
+
## MCP tools
|
|
101
|
+
|
|
102
|
+
| Tool | Use it for |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `gs_pack(task, budget)` | first call for "how does X work" or before a change |
|
|
105
|
+
| `gs_find(question, budget)` | locate things (map only) |
|
|
106
|
+
| `gs_symbol(name, max_lines, docs)` | read one definition instead of the file |
|
|
107
|
+
| `gs_impact(name, depth)` | blast radius before changing a signature |
|
|
108
|
+
| `gs_outline(path)` | symbols of a big file before opening it |
|
|
109
|
+
| `gs_savings()` | tokens saved so far |
|
|
110
|
+
|
|
111
|
+
The server is a small dependency-free stdio JSON-RPC implementation (it does not depend on the MCP SDK's changing API). It auto-refreshes a stale graph and records every call in `.graphsnip/ledger.jsonl`.
|
|
112
|
+
|
|
113
|
+
## What `install` writes
|
|
114
|
+
|
|
115
|
+
Everything is idempotent (run it twice, nothing changes) and reversible (`graphsnip uninstall`). Your existing content is preserved: text files get a marked block, JSON is merged.
|
|
116
|
+
|
|
117
|
+
| Client | Files |
|
|
118
|
+
|---|---|
|
|
119
|
+
| Claude Code | `.mcp.json`, `.claude/settings.json` (PreToolUse hook), `CLAUDE.md` block, `.claude/agents/graphsnip-explorer.md` (read-only Haiku subagent) |
|
|
120
|
+
| Copilot (VS Code) | `.vscode/mcp.json`, `.github/copilot-instructions.md` block |
|
|
121
|
+
| Codex | `.codex/config.toml` (or `~/.codex/config.toml` with `--codex-scope user`), `AGENTS.md` block |
|
|
122
|
+
|
|
123
|
+
Flags: `--allow-tools` pre-approves the read-only tools in Claude Code, `--portable` writes bare `graphsnip` instead of this machine's absolute path (use it before committing the configs), `--strict` sets hook mode to strict.
|
|
124
|
+
|
|
125
|
+
## Hooks (Claude Code)
|
|
126
|
+
|
|
127
|
+
Fail-open: any error means "do nothing". Configure in `.graphsnip/config.json` (or `GRAPHSNIP_MODE`).
|
|
128
|
+
|
|
129
|
+
| Mode | Behaviour |
|
|
130
|
+
|---|---|
|
|
131
|
+
| `nudge` (default) | adds context: the file's outline for big reads, `gs_symbol("X")` when a grep pattern is a known symbol. Blocks nothing |
|
|
132
|
+
| `strict` | denies those same calls with a reason that tells the agent what to call. Literal-string greps and reads with `offset`/`limit` are never blocked |
|
|
133
|
+
| `off` | nothing |
|
|
134
|
+
|
|
135
|
+
`shell_filter: true` additionally rewrites noisy test/build commands to run through `graphsnip run`. It is **off by default** because the rewrite returns an `allow` decision, which skips the permission prompt; it is limited to an allow-list and never touches pipelines or chained commands. POSIX shells only.
|
|
136
|
+
|
|
137
|
+
## How the numbers are measured (and what they are not)
|
|
138
|
+
|
|
139
|
+
- **Baseline per call.** `find`/`pack`: grep the question's terms, read the top 8 matching files in full. `symbol`: read the whole file. `impact`: grep the name, read matching files (cap 10). Deliberately far below "read the whole repo", the figure Graphify's own `benchmark` compares against.
|
|
140
|
+
- **Counted once.** In a real session, tokens that stay in context are re-sent every turn, so true savings compound. The dashboard does not claim that.
|
|
141
|
+
- **Shell savings are exact** (raw vs compressed output), not estimated.
|
|
142
|
+
- **Quality is checked**, not assumed (see `answered` above).
|
|
143
|
+
- **Cost** is `tokens saved × price per million input tokens` (default $3, set `price_per_mtok` in the config). It ignores caching discounts and output tokens.
|
|
144
|
+
|
|
145
|
+
## Known limits
|
|
146
|
+
|
|
147
|
+
- Hooks and the three client configs follow each tool's documented formats, but only the MCP server was verified against a real client in development (the official MCP Python client). Run `graphsnip doctor` and a short session in each client before relying on them.
|
|
148
|
+
- Symbol slicing is exact for the ~25 languages with tree-sitter grammars installed; elsewhere it falls back to indentation / brace matching.
|
|
149
|
+
- The graph only covers what Graphify extracts from code. Docs, PDFs and images need Graphify's semantic pass (needs an LLM key) and are not part of graphsnip's tools.
|
|
150
|
+
- Graphify's `graph.html` loads vis-network from a CDN; graphsnip caches it locally so the dashboard works offline (needs internet once).
|
|
151
|
+
|
|
152
|
+
## Development
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
pip install -e ".[dev]"
|
|
156
|
+
pytest -q
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Publishing
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
python -m build && twine upload dist/* # PyPI (name `graphsnip`)
|
|
163
|
+
cd npm && npm publish # npm wrapper (name `graphsnip`)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
Apache-2.0. graphsnip is a separate project that calls Graphify (also Apache-2.0) as a library; see `NOTICE`.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "graphsnip"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Token-saving layer on top of Graphify: symbol-level code slicing, context packs, a savings ledger with an honest baseline, hooks and MCP for Claude Code, Copilot and Codex."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
keywords = ["graphify", "knowledge-graph", "tokens", "claude-code", "copilot", "codex", "mcp", "tree-sitter"]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"graphifyy>=0.9",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[project.optional-dependencies]
|
|
19
|
+
accurate = ["tiktoken>=0.7"]
|
|
20
|
+
dev = ["pytest>=8"]
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
graphsnip = "graphsnip.cli:main"
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Repository = "https://github.com/naubadnithin7/codegraf"
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.packages.find]
|
|
29
|
+
where = ["src"]
|
|
30
|
+
|
|
31
|
+
[tool.setuptools.package-data]
|
|
32
|
+
graphsnip = ["py.typed"]
|
|
33
|
+
|
|
34
|
+
[tool.pytest.ini_options]
|
|
35
|
+
testpaths = ["tests"]
|