graphsnip 0.2.0__tar.gz → 0.3.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.2.0/src/graphsnip.egg-info → graphsnip-0.3.0}/PKG-INFO +203 -2
- {graphsnip-0.2.0 → graphsnip-0.3.0}/README.md +201 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/pyproject.toml +2 -2
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/__init__.py +1 -1
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/cli.py +21 -1
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/dashboard.py +126 -6
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/engine.py +58 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/ledger.py +17 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/mcp_server.py +146 -0
- graphsnip-0.3.0/src/graphsnip/memory_client.py +66 -0
- graphsnip-0.3.0/src/graphsnip/memory_eval.py +51 -0
- graphsnip-0.3.0/src/graphsnip/probe.py +83 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0/src/graphsnip.egg-info}/PKG-INFO +203 -2
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip.egg-info/SOURCES.txt +7 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/tests/test_integrations.py +30 -0
- graphsnip-0.3.0/tests/test_memory_client.py +45 -0
- graphsnip-0.3.0/tests/test_memory_cross_runtime.py +86 -0
- graphsnip-0.3.0/tests/test_memory_eval.py +20 -0
- graphsnip-0.3.0/tests/test_memory_integration.py +35 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/LICENSE +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/NOTICE +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/setup.cfg +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/__main__.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/ab.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/baseline.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/bench.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/hooks.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/installer.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/project.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/py.typed +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/retrieval.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/router.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/semantic.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/shellfilter.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/slicer.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/tokens.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip/usage.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip.egg-info/dependency_links.txt +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip.egg-info/entry_points.txt +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip.egg-info/requires.txt +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/src/graphsnip.egg-info/top_level.txt +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/tests/test_core.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/tests/test_refresh.py +0 -0
- {graphsnip-0.2.0 → graphsnip-0.3.0}/tests/test_semantic.py +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: graphsnip
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
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
5
|
License-Expression: Apache-2.0
|
|
6
|
-
Project-URL: Repository, https://github.com/
|
|
6
|
+
Project-URL: Repository, https://github.com/naubadnithinkumar/graphsnip
|
|
7
7
|
Keywords: graphify,knowledge-graph,tokens,claude-code,copilot,codex,mcp,tree-sitter
|
|
8
8
|
Requires-Python: >=3.10
|
|
9
9
|
Description-Content-Type: text/markdown
|
|
@@ -81,10 +81,210 @@ No LLM key needed. Everything runs locally: Graphify parses with tree-sitter, gr
|
|
|
81
81
|
|
|
82
82
|
Want a one-command demo on any repo? `graphsnip demo --open` builds the graph, runs a benchmark and opens the dashboard.
|
|
83
83
|
|
|
84
|
+
## Memory Engine: learn from previous coding tasks (optional)
|
|
85
|
+
|
|
86
|
+
GraphSnip integrates with the independent, open-source [Memory Engine](https://github.com/naubadnithinkumar/memory-engine). The graph describes the current code; memory captures evidence-backed lessons from previous work; approved skills capture reusable procedures. Memory is local, project-scoped and opt-in. No model API key is needed for this walkthrough.
|
|
87
|
+
|
|
88
|
+
```mermaid
|
|
89
|
+
flowchart LR
|
|
90
|
+
A[Previous coding task] --> B[Candidate memory]
|
|
91
|
+
B --> C[Independent test and review]
|
|
92
|
+
C --> D[Verified memory]
|
|
93
|
+
D --> E[Corroborated skill proposal]
|
|
94
|
+
E --> F[Independent approval]
|
|
95
|
+
G[Current code graph] --> H[gs_pack]
|
|
96
|
+
D --> H
|
|
97
|
+
F --> H
|
|
98
|
+
H --> I[Budgeted agent context]
|
|
99
|
+
H --> J[Memory usage dashboard]
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 1. Install the integration
|
|
103
|
+
|
|
104
|
+
Use Python 3.10+ and Node.js 22.13+. The following POSIX shell commands install the current GraphSnip source and the exact Memory Engine revision used by the interoperability CI. The new integration is not assumed to be available in an older registry release.
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
pipx install 'git+https://github.com/naubadnithinkumar/graphsnip.git'
|
|
108
|
+
npm install -g https://github.com/naubadnithinkumar/memory-engine/archive/befb5607a7109d8bcc8160a1947878de09a3d807.tar.gz
|
|
109
|
+
command -v graphsnip
|
|
110
|
+
command -v memory-engine
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
If GraphSnip is already installed via pipx, use a separate development environment or explicitly replace that installation. The Memory Engine executable must also be on the PATH of your IDE/MCP server, not just your interactive shell.
|
|
114
|
+
|
|
115
|
+
### 2. Create a disposable demonstration project
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
DEMO=$(mktemp -d)
|
|
119
|
+
cd "$DEMO"
|
|
120
|
+
cat > validators.py <<'PY'
|
|
121
|
+
def validate_email(email):
|
|
122
|
+
return bool(email and "@" in email)
|
|
123
|
+
|
|
124
|
+
def persist_email(email, records):
|
|
125
|
+
if not validate_email(email):
|
|
126
|
+
raise ValueError("Invalid email")
|
|
127
|
+
records.append(email)
|
|
128
|
+
PY
|
|
129
|
+
cat > test_demo.py <<'PY'
|
|
130
|
+
import unittest
|
|
131
|
+
from validators import persist_email
|
|
132
|
+
|
|
133
|
+
class EmailTests(unittest.TestCase):
|
|
134
|
+
def test_email(self):
|
|
135
|
+
records = []
|
|
136
|
+
persist_email("demo@example.com", records)
|
|
137
|
+
self.assertEqual(records, ["demo@example.com"])
|
|
138
|
+
|
|
139
|
+
def test_missing_at(self):
|
|
140
|
+
records = []
|
|
141
|
+
with self.assertRaises(ValueError):
|
|
142
|
+
persist_email("invalid", records)
|
|
143
|
+
self.assertEqual(records, [])
|
|
144
|
+
|
|
145
|
+
def test_empty(self):
|
|
146
|
+
records = []
|
|
147
|
+
with self.assertRaises(ValueError):
|
|
148
|
+
persist_email("", records)
|
|
149
|
+
self.assertEqual(records, [])
|
|
150
|
+
PY
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
This tiny fixture demonstrates the workflow, not a production-grade email validator. Stop if any test fails; the verification and approval commands below assume you have reviewed the corresponding passing tests.
|
|
154
|
+
|
|
155
|
+
### 3. Record and verify a learning
|
|
156
|
+
|
|
157
|
+
The CLI accepts one version-1 JSON request on stdin and returns a JSON envelope containing `ok` and `result`. Each invocation opens the database for the current working directory.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
mem() { printf '%s\n' "$1" | memory-engine; }
|
|
161
|
+
|
|
162
|
+
FIRST=$(mem '{"version":1,"operation":"record","params":{"value":{"type":"corrective","title":"Validate email","learning":"Validate email before persisting.","evidence":["test:email"]}}}' | python3 -c 'import json,sys; print(json.load(sys.stdin)["result"]["id"])')
|
|
163
|
+
|
|
164
|
+
mem '{"version":1,"operation":"retrieve","params":{"query":"validate email","context":"project","adapter":"coding"}}'
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Expected: an empty result array, because a newly recorded memory is a candidate. Run the demonstration test and review its result before verifying:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
python3 -m unittest test_demo.EmailTests.test_email
|
|
171
|
+
mem "{\"version\":1,\"operation\":\"verify\",\"params\":{\"id\":\"$FIRST\",\"evidence\":{\"adapter\":\"coding\",\"test\":\"email\",\"evidenceId\":\"test:email\",\"context\":\"project\",\"result\":\"passed\",\"reviewed\":true}}}"
|
|
172
|
+
mem '{"version":1,"operation":"retrieve","params":{"query":"validate email","context":"project","adapter":"coding"}}'
|
|
173
|
+
mem '{"version":1,"operation":"stats"}'
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Expected: the verified record is now returned, including its ID and learning. A different context returns no match. The evidence receipt is supplied by the reviewer; Memory Engine does not run or independently authenticate the test.
|
|
177
|
+
|
|
178
|
+
### 4. Turn corroborated memories into an approved skill
|
|
179
|
+
|
|
180
|
+
Run and review a second test before recording the same lesson with distinct evidence. A single verified record is insufficient to propose a skill.
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
python3 -m unittest test_demo.EmailTests.test_missing_at
|
|
184
|
+
SECOND=$(mem '{"version":1,"operation":"record","params":{"value":{"type":"corrective","title":"Validate email","learning":"Validate email before persisting.","evidence":["test:email2"]}}}' | python3 -c 'import json,sys; print(json.load(sys.stdin)["result"]["id"])')
|
|
185
|
+
mem "{\"version\":1,\"operation\":\"verify\",\"params\":{\"id\":\"$SECOND\",\"evidence\":{\"adapter\":\"coding\",\"test\":\"email\",\"evidenceId\":\"test:email2\",\"context\":\"project\",\"result\":\"passed\",\"reviewed\":true}}}"
|
|
186
|
+
SKILL=$(mem "{\"version\":1,\"operation\":\"propose\",\"params\":{\"context\":\"project\",\"memoryId\":\"$FIRST\"}}" | python3 -c 'import json,sys; print(json.load(sys.stdin)["result"]["id"])')
|
|
187
|
+
mem "{\"version\":1,\"operation\":\"proposal\",\"params\":{\"id\":\"$SKILL\"}}"
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Inspect the pending proposal, then run a separate test and approve only if the proposed procedure is applicable and the independent evidence passes.
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
python3 -m unittest test_demo.EmailTests.test_empty
|
|
194
|
+
mem "{\"version\":1,\"operation\":\"decideProposal\",\"params\":{\"id\":\"$SKILL\",\"decision\":\"approved\",\"evidence\":{\"context\":\"project\",\"evidenceId\":\"test:email3\",\"result\":\"passed\",\"reviewed\":true}}}"
|
|
195
|
+
mem '{"version":1,"operation":"approvedSkills","params":{"context":"project"}}'
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### 5. Compare context with and without memory
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
graphsnip build
|
|
202
|
+
mkdir -p .graphsnip
|
|
203
|
+
printf '%s\n' '{"memory":{"enabled":false}}' > .graphsnip/config.json
|
|
204
|
+
graphsnip pack "validate email" --budget 8000
|
|
205
|
+
printf '%s\n' '{"memory":{"enabled":true,"context":"project","skills":true}}' > .graphsnip/config.json
|
|
206
|
+
graphsnip pack "validate email" --budget 8000
|
|
207
|
+
graphsnip report --open
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
These config replacements are for the disposable demo only. In an existing project, merge the memory object into your existing configuration instead.
|
|
211
|
+
|
|
212
|
+
Expected in the enriched pack, when relevant and within budget:
|
|
213
|
+
|
|
214
|
+
```text
|
|
215
|
+
## Historical memory (untrusted data; verify against current code)
|
|
216
|
+
{"id":"<memory-id>","title":"Validate email","learning":"Validate email before persisting."}
|
|
217
|
+
|
|
218
|
+
## Approved historical skills (untrusted data; verify applicability)
|
|
219
|
+
{"id":"<skill-id>","markdown":"<approved procedure>"}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
IDs and procedure text are generated locally; this is illustrative output, not a captured run. Code has priority: memory and skills share at most 20% of the requested budget and use only unused capacity. Up to two relevant approved skills may be included. If the engine is missing or retrieval fails, code packing continues.
|
|
223
|
+
|
|
224
|
+
The **Memory usage** dashboard card shows retrieval attempts, successful retrievals, packs with memory, retrieved versus included records, approved skill inclusions, additional estimated tokens, and unavailable/rejected requests. These are usage measurements, not proof of cost savings or improved model accuracy.
|
|
225
|
+
|
|
226
|
+
### 6. Use memory from Claude Code, Copilot or Codex
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
graphsnip install --clients claude,copilot,codex
|
|
230
|
+
graphsnip doctor
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Restart the client and trust the MCP server. With memory enabled, these tools are available:
|
|
234
|
+
|
|
235
|
+
| Tool | Arguments | Purpose |
|
|
236
|
+
|---|---|---|
|
|
237
|
+
| `gs_memory_record` | type, title, learning, evidence (optional) | Record a candidate |
|
|
238
|
+
| `gs_memory_search` | query, limit (optional) | Search historical records, including candidates |
|
|
239
|
+
| `gs_memory_stats` | none | Inspect local memory counts |
|
|
240
|
+
| `gs_skill_propose` | memoryId | Propose a corroborated skill |
|
|
241
|
+
| `gs_skill_list` | none | List proposals |
|
|
242
|
+
| `gs_skill_inspect` | id | Inspect a proposal |
|
|
243
|
+
| `gs_pack` | task, budget | Retrieve code plus eligible memory and skills |
|
|
244
|
+
|
|
245
|
+
Example agent request: “Use gs_pack to locate email validation. After the change and tests, record any reusable correction as a candidate with gs_memory_record. Do not mark your own work verified.”
|
|
246
|
+
|
|
247
|
+
Verification and approval are intentionally not exposed as GraphSnip MCP tools. Automatic learning from every execution is not yet an end-to-end feature.
|
|
248
|
+
|
|
249
|
+
### 7. Invalidate stale learning and check isolation
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
mem "{\"version\":1,\"operation\":\"archive\",\"params\":{\"id\":\"$FIRST\"}}"
|
|
253
|
+
mem '{"version":1,"operation":"approvedSkills","params":{"context":"project"}}'
|
|
254
|
+
(cd "$(mktemp -d)" && mem "{\"version\":1,\"operation\":\"get\",\"params\":{\"id\":\"$FIRST\"}}")
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Expected: the skill is no longer eligible because one of its verified sources was archived; the other project returns null for the original record. The second verified memory may still be retrieved in the original project.
|
|
258
|
+
|
|
259
|
+
Storage is under `.memory-engine/memory/memory.db` in the project root. Keep that directory out of version control and do not store credentials or confidential customer data. Local retrieval does not imply that downstream agent providers keep the retrieved text local: context supplied to an external model may leave your machine.
|
|
260
|
+
|
|
261
|
+
### 8. Run the automated interoperability tests
|
|
262
|
+
|
|
263
|
+
From a GraphSnip source checkout, with the pinned Memory Engine installed:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
python3 -m venv .venv
|
|
267
|
+
source .venv/bin/activate
|
|
268
|
+
python -m pip install '.[dev]'
|
|
269
|
+
GRAPHSNIP_TEST_MEMORY_ENGINE=1 python -m pytest -v \
|
|
270
|
+
tests/test_memory_cross_runtime.py tests/test_memory_client.py \
|
|
271
|
+
tests/test_memory_integration.py tests/test_memory_eval.py
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
See [Memory evaluation](docs/memory-evaluation.md) for the four-arm comparison (baseline, graph, memory, combined) and the offline analyzer:
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
python -m graphsnip.memory_eval results.jsonl
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
The analyzer requires actual externally collected trial results; it does not execute model trials. The existing two-arm `graphsnip ab` is not a four-arm memory benchmark. No measured memory-specific effectiveness claim is made here.
|
|
281
|
+
|
|
282
|
+
|
|
84
283
|
## What you get
|
|
85
284
|
|
|
86
285
|
| | |
|
|
87
286
|
|---|---|
|
|
287
|
+
| **Verified memory and approved skills (optional)** | Reuse evidence-backed lessons in context packs with the standalone Memory Engine. |
|
|
88
288
|
| **Exact symbol, not the file** | `gs_symbol` returns one function or class with its callers and callees. Docstrings trimmed, big classes shown as skeletons. |
|
|
89
289
|
| **Context packs** | `gs_pack` bundles the ranked code for a whole task under a token budget in one call. |
|
|
90
290
|
| **No repeats** | Code the agent already has in this session comes back as a one-line pointer. |
|
|
@@ -283,6 +483,7 @@ Every query command prints `~N tokens returned vs ~M for grep+read → saved P%`
|
|
|
283
483
|
| `gs_outline(path)` | symbols of a big file before opening it |
|
|
284
484
|
| `gs_route(task, running_tier)` | which model tier this task needs |
|
|
285
485
|
| `gs_savings()` | tokens saved so far |
|
|
486
|
+
| `gs_memory_*` / `gs_skill_*` | optional memory and skill tools; see the [Memory Engine walkthrough](#memory-engine-learn-from-previous-coding-tasks-optional) |
|
|
286
487
|
|
|
287
488
|
A small dependency-free stdio JSON-RPC server (it does not depend on the MCP SDK's changing API). It refreshes a stale graph and records every call in `.graphsnip/ledger.jsonl`.
|
|
288
489
|
</details>
|
|
@@ -60,10 +60,210 @@ No LLM key needed. Everything runs locally: Graphify parses with tree-sitter, gr
|
|
|
60
60
|
|
|
61
61
|
Want a one-command demo on any repo? `graphsnip demo --open` builds the graph, runs a benchmark and opens the dashboard.
|
|
62
62
|
|
|
63
|
+
## Memory Engine: learn from previous coding tasks (optional)
|
|
64
|
+
|
|
65
|
+
GraphSnip integrates with the independent, open-source [Memory Engine](https://github.com/naubadnithinkumar/memory-engine). The graph describes the current code; memory captures evidence-backed lessons from previous work; approved skills capture reusable procedures. Memory is local, project-scoped and opt-in. No model API key is needed for this walkthrough.
|
|
66
|
+
|
|
67
|
+
```mermaid
|
|
68
|
+
flowchart LR
|
|
69
|
+
A[Previous coding task] --> B[Candidate memory]
|
|
70
|
+
B --> C[Independent test and review]
|
|
71
|
+
C --> D[Verified memory]
|
|
72
|
+
D --> E[Corroborated skill proposal]
|
|
73
|
+
E --> F[Independent approval]
|
|
74
|
+
G[Current code graph] --> H[gs_pack]
|
|
75
|
+
D --> H
|
|
76
|
+
F --> H
|
|
77
|
+
H --> I[Budgeted agent context]
|
|
78
|
+
H --> J[Memory usage dashboard]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 1. Install the integration
|
|
82
|
+
|
|
83
|
+
Use Python 3.10+ and Node.js 22.13+. The following POSIX shell commands install the current GraphSnip source and the exact Memory Engine revision used by the interoperability CI. The new integration is not assumed to be available in an older registry release.
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pipx install 'git+https://github.com/naubadnithinkumar/graphsnip.git'
|
|
87
|
+
npm install -g https://github.com/naubadnithinkumar/memory-engine/archive/befb5607a7109d8bcc8160a1947878de09a3d807.tar.gz
|
|
88
|
+
command -v graphsnip
|
|
89
|
+
command -v memory-engine
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
If GraphSnip is already installed via pipx, use a separate development environment or explicitly replace that installation. The Memory Engine executable must also be on the PATH of your IDE/MCP server, not just your interactive shell.
|
|
93
|
+
|
|
94
|
+
### 2. Create a disposable demonstration project
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
DEMO=$(mktemp -d)
|
|
98
|
+
cd "$DEMO"
|
|
99
|
+
cat > validators.py <<'PY'
|
|
100
|
+
def validate_email(email):
|
|
101
|
+
return bool(email and "@" in email)
|
|
102
|
+
|
|
103
|
+
def persist_email(email, records):
|
|
104
|
+
if not validate_email(email):
|
|
105
|
+
raise ValueError("Invalid email")
|
|
106
|
+
records.append(email)
|
|
107
|
+
PY
|
|
108
|
+
cat > test_demo.py <<'PY'
|
|
109
|
+
import unittest
|
|
110
|
+
from validators import persist_email
|
|
111
|
+
|
|
112
|
+
class EmailTests(unittest.TestCase):
|
|
113
|
+
def test_email(self):
|
|
114
|
+
records = []
|
|
115
|
+
persist_email("demo@example.com", records)
|
|
116
|
+
self.assertEqual(records, ["demo@example.com"])
|
|
117
|
+
|
|
118
|
+
def test_missing_at(self):
|
|
119
|
+
records = []
|
|
120
|
+
with self.assertRaises(ValueError):
|
|
121
|
+
persist_email("invalid", records)
|
|
122
|
+
self.assertEqual(records, [])
|
|
123
|
+
|
|
124
|
+
def test_empty(self):
|
|
125
|
+
records = []
|
|
126
|
+
with self.assertRaises(ValueError):
|
|
127
|
+
persist_email("", records)
|
|
128
|
+
self.assertEqual(records, [])
|
|
129
|
+
PY
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
This tiny fixture demonstrates the workflow, not a production-grade email validator. Stop if any test fails; the verification and approval commands below assume you have reviewed the corresponding passing tests.
|
|
133
|
+
|
|
134
|
+
### 3. Record and verify a learning
|
|
135
|
+
|
|
136
|
+
The CLI accepts one version-1 JSON request on stdin and returns a JSON envelope containing `ok` and `result`. Each invocation opens the database for the current working directory.
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
mem() { printf '%s\n' "$1" | memory-engine; }
|
|
140
|
+
|
|
141
|
+
FIRST=$(mem '{"version":1,"operation":"record","params":{"value":{"type":"corrective","title":"Validate email","learning":"Validate email before persisting.","evidence":["test:email"]}}}' | python3 -c 'import json,sys; print(json.load(sys.stdin)["result"]["id"])')
|
|
142
|
+
|
|
143
|
+
mem '{"version":1,"operation":"retrieve","params":{"query":"validate email","context":"project","adapter":"coding"}}'
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Expected: an empty result array, because a newly recorded memory is a candidate. Run the demonstration test and review its result before verifying:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
python3 -m unittest test_demo.EmailTests.test_email
|
|
150
|
+
mem "{\"version\":1,\"operation\":\"verify\",\"params\":{\"id\":\"$FIRST\",\"evidence\":{\"adapter\":\"coding\",\"test\":\"email\",\"evidenceId\":\"test:email\",\"context\":\"project\",\"result\":\"passed\",\"reviewed\":true}}}"
|
|
151
|
+
mem '{"version":1,"operation":"retrieve","params":{"query":"validate email","context":"project","adapter":"coding"}}'
|
|
152
|
+
mem '{"version":1,"operation":"stats"}'
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Expected: the verified record is now returned, including its ID and learning. A different context returns no match. The evidence receipt is supplied by the reviewer; Memory Engine does not run or independently authenticate the test.
|
|
156
|
+
|
|
157
|
+
### 4. Turn corroborated memories into an approved skill
|
|
158
|
+
|
|
159
|
+
Run and review a second test before recording the same lesson with distinct evidence. A single verified record is insufficient to propose a skill.
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
python3 -m unittest test_demo.EmailTests.test_missing_at
|
|
163
|
+
SECOND=$(mem '{"version":1,"operation":"record","params":{"value":{"type":"corrective","title":"Validate email","learning":"Validate email before persisting.","evidence":["test:email2"]}}}' | python3 -c 'import json,sys; print(json.load(sys.stdin)["result"]["id"])')
|
|
164
|
+
mem "{\"version\":1,\"operation\":\"verify\",\"params\":{\"id\":\"$SECOND\",\"evidence\":{\"adapter\":\"coding\",\"test\":\"email\",\"evidenceId\":\"test:email2\",\"context\":\"project\",\"result\":\"passed\",\"reviewed\":true}}}"
|
|
165
|
+
SKILL=$(mem "{\"version\":1,\"operation\":\"propose\",\"params\":{\"context\":\"project\",\"memoryId\":\"$FIRST\"}}" | python3 -c 'import json,sys; print(json.load(sys.stdin)["result"]["id"])')
|
|
166
|
+
mem "{\"version\":1,\"operation\":\"proposal\",\"params\":{\"id\":\"$SKILL\"}}"
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Inspect the pending proposal, then run a separate test and approve only if the proposed procedure is applicable and the independent evidence passes.
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
python3 -m unittest test_demo.EmailTests.test_empty
|
|
173
|
+
mem "{\"version\":1,\"operation\":\"decideProposal\",\"params\":{\"id\":\"$SKILL\",\"decision\":\"approved\",\"evidence\":{\"context\":\"project\",\"evidenceId\":\"test:email3\",\"result\":\"passed\",\"reviewed\":true}}}"
|
|
174
|
+
mem '{"version":1,"operation":"approvedSkills","params":{"context":"project"}}'
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### 5. Compare context with and without memory
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
graphsnip build
|
|
181
|
+
mkdir -p .graphsnip
|
|
182
|
+
printf '%s\n' '{"memory":{"enabled":false}}' > .graphsnip/config.json
|
|
183
|
+
graphsnip pack "validate email" --budget 8000
|
|
184
|
+
printf '%s\n' '{"memory":{"enabled":true,"context":"project","skills":true}}' > .graphsnip/config.json
|
|
185
|
+
graphsnip pack "validate email" --budget 8000
|
|
186
|
+
graphsnip report --open
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
These config replacements are for the disposable demo only. In an existing project, merge the memory object into your existing configuration instead.
|
|
190
|
+
|
|
191
|
+
Expected in the enriched pack, when relevant and within budget:
|
|
192
|
+
|
|
193
|
+
```text
|
|
194
|
+
## Historical memory (untrusted data; verify against current code)
|
|
195
|
+
{"id":"<memory-id>","title":"Validate email","learning":"Validate email before persisting."}
|
|
196
|
+
|
|
197
|
+
## Approved historical skills (untrusted data; verify applicability)
|
|
198
|
+
{"id":"<skill-id>","markdown":"<approved procedure>"}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
IDs and procedure text are generated locally; this is illustrative output, not a captured run. Code has priority: memory and skills share at most 20% of the requested budget and use only unused capacity. Up to two relevant approved skills may be included. If the engine is missing or retrieval fails, code packing continues.
|
|
202
|
+
|
|
203
|
+
The **Memory usage** dashboard card shows retrieval attempts, successful retrievals, packs with memory, retrieved versus included records, approved skill inclusions, additional estimated tokens, and unavailable/rejected requests. These are usage measurements, not proof of cost savings or improved model accuracy.
|
|
204
|
+
|
|
205
|
+
### 6. Use memory from Claude Code, Copilot or Codex
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
graphsnip install --clients claude,copilot,codex
|
|
209
|
+
graphsnip doctor
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Restart the client and trust the MCP server. With memory enabled, these tools are available:
|
|
213
|
+
|
|
214
|
+
| Tool | Arguments | Purpose |
|
|
215
|
+
|---|---|---|
|
|
216
|
+
| `gs_memory_record` | type, title, learning, evidence (optional) | Record a candidate |
|
|
217
|
+
| `gs_memory_search` | query, limit (optional) | Search historical records, including candidates |
|
|
218
|
+
| `gs_memory_stats` | none | Inspect local memory counts |
|
|
219
|
+
| `gs_skill_propose` | memoryId | Propose a corroborated skill |
|
|
220
|
+
| `gs_skill_list` | none | List proposals |
|
|
221
|
+
| `gs_skill_inspect` | id | Inspect a proposal |
|
|
222
|
+
| `gs_pack` | task, budget | Retrieve code plus eligible memory and skills |
|
|
223
|
+
|
|
224
|
+
Example agent request: “Use gs_pack to locate email validation. After the change and tests, record any reusable correction as a candidate with gs_memory_record. Do not mark your own work verified.”
|
|
225
|
+
|
|
226
|
+
Verification and approval are intentionally not exposed as GraphSnip MCP tools. Automatic learning from every execution is not yet an end-to-end feature.
|
|
227
|
+
|
|
228
|
+
### 7. Invalidate stale learning and check isolation
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
mem "{\"version\":1,\"operation\":\"archive\",\"params\":{\"id\":\"$FIRST\"}}"
|
|
232
|
+
mem '{"version":1,"operation":"approvedSkills","params":{"context":"project"}}'
|
|
233
|
+
(cd "$(mktemp -d)" && mem "{\"version\":1,\"operation\":\"get\",\"params\":{\"id\":\"$FIRST\"}}")
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Expected: the skill is no longer eligible because one of its verified sources was archived; the other project returns null for the original record. The second verified memory may still be retrieved in the original project.
|
|
237
|
+
|
|
238
|
+
Storage is under `.memory-engine/memory/memory.db` in the project root. Keep that directory out of version control and do not store credentials or confidential customer data. Local retrieval does not imply that downstream agent providers keep the retrieved text local: context supplied to an external model may leave your machine.
|
|
239
|
+
|
|
240
|
+
### 8. Run the automated interoperability tests
|
|
241
|
+
|
|
242
|
+
From a GraphSnip source checkout, with the pinned Memory Engine installed:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
python3 -m venv .venv
|
|
246
|
+
source .venv/bin/activate
|
|
247
|
+
python -m pip install '.[dev]'
|
|
248
|
+
GRAPHSNIP_TEST_MEMORY_ENGINE=1 python -m pytest -v \
|
|
249
|
+
tests/test_memory_cross_runtime.py tests/test_memory_client.py \
|
|
250
|
+
tests/test_memory_integration.py tests/test_memory_eval.py
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
See [Memory evaluation](docs/memory-evaluation.md) for the four-arm comparison (baseline, graph, memory, combined) and the offline analyzer:
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
python -m graphsnip.memory_eval results.jsonl
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
The analyzer requires actual externally collected trial results; it does not execute model trials. The existing two-arm `graphsnip ab` is not a four-arm memory benchmark. No measured memory-specific effectiveness claim is made here.
|
|
260
|
+
|
|
261
|
+
|
|
63
262
|
## What you get
|
|
64
263
|
|
|
65
264
|
| | |
|
|
66
265
|
|---|---|
|
|
266
|
+
| **Verified memory and approved skills (optional)** | Reuse evidence-backed lessons in context packs with the standalone Memory Engine. |
|
|
67
267
|
| **Exact symbol, not the file** | `gs_symbol` returns one function or class with its callers and callees. Docstrings trimmed, big classes shown as skeletons. |
|
|
68
268
|
| **Context packs** | `gs_pack` bundles the ranked code for a whole task under a token budget in one call. |
|
|
69
269
|
| **No repeats** | Code the agent already has in this session comes back as a one-line pointer. |
|
|
@@ -262,6 +462,7 @@ Every query command prints `~N tokens returned vs ~M for grep+read → saved P%`
|
|
|
262
462
|
| `gs_outline(path)` | symbols of a big file before opening it |
|
|
263
463
|
| `gs_route(task, running_tier)` | which model tier this task needs |
|
|
264
464
|
| `gs_savings()` | tokens saved so far |
|
|
465
|
+
| `gs_memory_*` / `gs_skill_*` | optional memory and skill tools; see the [Memory Engine walkthrough](#memory-engine-learn-from-previous-coding-tasks-optional) |
|
|
265
466
|
|
|
266
467
|
A small dependency-free stdio JSON-RPC server (it does not depend on the MCP SDK's changing API). It refreshes a stale graph and records every call in `.graphsnip/ledger.jsonl`.
|
|
267
468
|
</details>
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "graphsnip"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
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
9
|
readme = "README.md"
|
|
10
10
|
license = "Apache-2.0"
|
|
@@ -24,7 +24,7 @@ dev = ["pytest>=8"]
|
|
|
24
24
|
graphsnip = "graphsnip.cli:main"
|
|
25
25
|
|
|
26
26
|
[project.urls]
|
|
27
|
-
Repository = "https://github.com/
|
|
27
|
+
Repository = "https://github.com/naubadnithinkumar/graphsnip"
|
|
28
28
|
|
|
29
29
|
[tool.setuptools.packages.find]
|
|
30
30
|
where = ["src"]
|
|
@@ -444,6 +444,25 @@ def cmd_doctor(a) -> int:
|
|
|
444
444
|
f"Re-run `graphsnip install` (without --portable) to write the full path.")
|
|
445
445
|
elif not os.path.exists(c):
|
|
446
446
|
print(f"! {label}: server command {c} does not exist; re-run `graphsnip install`.")
|
|
447
|
+
if not getattr(a, "no_probe", False):
|
|
448
|
+
from graphsnip.probe import probe_mcp
|
|
449
|
+
|
|
450
|
+
for label, f, key in (("claude", mcp_claude, "mcpServers"), ("copilot", p.root / ".vscode" / "mcp.json", "servers")):
|
|
451
|
+
try:
|
|
452
|
+
ent = json.loads(f.read_text(encoding="utf-8")).get(key, {}).get("graphsnip")
|
|
453
|
+
except Exception:
|
|
454
|
+
ent = None
|
|
455
|
+
if not ent:
|
|
456
|
+
continue
|
|
457
|
+
r = probe_mcp(str(ent.get("command", "")), [str(x) for x in ent.get("args", [])], str(p.root))
|
|
458
|
+
if r["ok"]:
|
|
459
|
+
line(True, f"{label}: the MCP server starts and lists {len(r['tools'])} tools ({r['seconds']}s)")
|
|
460
|
+
else:
|
|
461
|
+
line(False, f"{label}: the MCP server does NOT work: {r['error']}", "fix the command in the config, then reload the app")
|
|
462
|
+
if r["stderr"]:
|
|
463
|
+
print(" server said: " + r["stderr"].replace("\n", "\n "))
|
|
464
|
+
print(" If every server above starts but the assistant still has no graphsnip tools, the app has not started or trusted it:")
|
|
465
|
+
print(" Claude Code: run /mcp and approve it. VS Code: Command Palette > 'MCP: List Servers' > start/trust graphsnip, then 'Configure Tools'.")
|
|
447
466
|
hook_on = st.exists() and HOOK_MARK in st.read_text(encoding="utf-8", errors="ignore")
|
|
448
467
|
print(f"{'✓' if hook_on else '·'} claude hook: {'installed' if hook_on else 'not installed'} (mode: {p.config()['mode']})")
|
|
449
468
|
print("\nAll good." if ok else "\nSome checks failed; see arrows above.")
|
|
@@ -550,7 +569,8 @@ def main(argv=None) -> int:
|
|
|
550
569
|
sp = add("uninstall", cmd_uninstall, "remove everything install added")
|
|
551
570
|
sp.add_argument("--clients", default="all")
|
|
552
571
|
sp.add_argument("--codex-scope", choices=["project", "user"], default="project")
|
|
553
|
-
add("doctor", cmd_doctor, "check the setup")
|
|
572
|
+
sp = add("doctor", cmd_doctor, "check the setup (also starts the configured MCP servers to prove they work)")
|
|
573
|
+
sp.add_argument("--no-probe", action="store_true", help="skip starting the MCP servers")
|
|
554
574
|
|
|
555
575
|
args = ap.parse_args(argv)
|
|
556
576
|
if not getattr(args, "fn", None):
|