ctxgraph 0.3.0__tar.gz → 0.3.1__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.
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/PKG-INFO +284 -133
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/README.md +283 -132
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/pyproject.toml +1 -1
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph.egg-info/PKG-INFO +284 -133
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/setup.cfg +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/__init__.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/analyzers/__init__.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/analyzers/python/__init__.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/analyzers/python/importer.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/analyzers/python/semantic.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/analyzers/python/symbols.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/capsule/__init__.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/capsule/renderer.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/capsule/savings.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/cli/__init__.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/cli/main.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/clients/__init__.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/clients/models.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/config/__init__.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/config/init.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/config/providers.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/config/settings.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/exclude/__init__.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/exclude/patterns.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/graph/__init__.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/graph/builder.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/graph/models.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/graph/query.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/graph/storage.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/history.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/mcp/__init__.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/mcp/server.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/skills/__init__.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/view/__init__.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/view/visualizer.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/wrapper/__init__.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph/wrapper/claude.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph.egg-info/SOURCES.txt +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph.egg-info/dependency_links.txt +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph.egg-info/entry_points.txt +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph.egg-info/requires.txt +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/src/ctxgraph.egg-info/top_level.txt +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/tests/test_analyzers.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/tests/test_benchmark.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/tests/test_capsule.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/tests/test_config.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/tests/test_e2e.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/tests/test_integration.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/tests/test_model_mode.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/tests/test_models.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/tests/test_query.py +0 -0
- {ctxgraph-0.3.0 → ctxgraph-0.3.1}/tests/test_storage.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ctxgraph
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: AI context engine for Python — cuts LLM tokens 97% via code knowledge graphs. Build, query, and generate compact context capsules for Claude, OpenAI, Ollama.
|
|
5
5
|
Author: ctxgraph contributors
|
|
6
6
|
License: MIT
|
|
@@ -35,6 +35,7 @@ Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
|
35
35
|
pip install ctxgraph
|
|
36
36
|
|
|
37
37
|
ctx build # Build knowledge graph
|
|
38
|
+
ctx ask "how does JWT auth work" # Ask questions with automatic token savings
|
|
38
39
|
ctx capsule "fix JWT expiry" # 92-99% fewer tokens vs raw code
|
|
39
40
|
ccg "fix the login redirect bug" # Launch Claude with context pre-loaded
|
|
40
41
|
ctx view # Interactive D3.js visualization (or --svg for static)
|
|
@@ -44,6 +45,24 @@ ctx view # Interactive D3.js visualization (or --svg f
|
|
|
44
45
|
|
|
45
46
|
---
|
|
46
47
|
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# 1. Initialize project
|
|
52
|
+
ctx init # Creates .ctxgraph/config.toml + default skills
|
|
53
|
+
|
|
54
|
+
# 2. Build the knowledge graph
|
|
55
|
+
ctx build # AST analysis → SQLite graph
|
|
56
|
+
|
|
57
|
+
# 3. Ask questions (requires Ollama or other LLM provider)
|
|
58
|
+
ctx ask "how does authentication work"
|
|
59
|
+
|
|
60
|
+
# 4. Or generate a capsule for your AI tool
|
|
61
|
+
ctx capsule "fix login rate limiter" --savings
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
47
66
|
## Why ctxgraph?
|
|
48
67
|
|
|
49
68
|
Sending entire files to an AI is wasteful. ctxgraph analyzes your code with AST-based static analysis, stores the result in a queryable SQLite graph, and retrieves *only the relevant nodes* — compressed into a token-efficient DSL format.
|
|
@@ -83,35 +102,6 @@ Repository (.py files)
|
|
|
83
102
|
└─────────────────────────────────────────────────────────┘
|
|
84
103
|
```
|
|
85
104
|
|
|
86
|
-
### Architecture
|
|
87
|
-
|
|
88
|
-
```
|
|
89
|
-
┌─────────┐ ┌──────────────┐ ┌──────────────┐ ┌─────────────┐
|
|
90
|
-
│ CLI │───▶│ Analyzers │───▶│ SQLite DB │───▶│ Skills/Hist │
|
|
91
|
-
│ typer │ │ AST-based │ │ .ctxgraph/ │ │ .ctxgraph/ │
|
|
92
|
-
└────┬────┘ └──────────────┘ └──────┬───────┘ └─────────────┘
|
|
93
|
-
│ │
|
|
94
|
-
├── ctx build ──────────────────────▶│ Graph build
|
|
95
|
-
│ │
|
|
96
|
-
├── ctx capsule ◀───────────────────│ Query + BFS
|
|
97
|
-
│ │
|
|
98
|
-
├── ctx query ◀─────────────────────│ Keyword search
|
|
99
|
-
│ │
|
|
100
|
-
├── ctx ask ◀──────────────────────│ LLM query + savings
|
|
101
|
-
│ │
|
|
102
|
-
├── ctx view ◀──────────────────────│ D3.js viz
|
|
103
|
-
│ │
|
|
104
|
-
├── ctx serve ◀─────────────────────│ MCP server
|
|
105
|
-
│ │
|
|
106
|
-
├── ctx init ───────────────────────│ Scaffold project
|
|
107
|
-
│ │
|
|
108
|
-
├── ctx history ◀───────────────────│ Query log
|
|
109
|
-
│ │
|
|
110
|
-
└── ctx skill ◀─────────────────────│ Skill management
|
|
111
|
-
│ │
|
|
112
|
-
└── ccg wrapper ───▶ Claude Code ───┘ AI tool
|
|
113
|
-
```
|
|
114
|
-
|
|
115
105
|
---
|
|
116
106
|
|
|
117
107
|
## Token Efficiency
|
|
@@ -150,27 +140,8 @@ JSON: 426 tokens DSL: 143 tokens
|
|
|
150
140
|
|
|
151
141
|
> **97.0% average token reduction** across 4 projects, 42 benchmark runs. The larger the project, the greater the savings.
|
|
152
142
|
|
|
153
|
-
### With Graph vs Without (Ollama)
|
|
154
|
-
|
|
155
|
-
| Query | No Context | With ctxgraph | Δ |
|
|
156
|
-
|-------|:----------:|:-------------:|:-:|
|
|
157
|
-
| Calculator expression parsing | 100% | 100% | — |
|
|
158
|
-
| Plugin registration system | 33% | **100%** | **+67pp** |
|
|
159
|
-
| JWT authentication (web_api) | 75% | **100%** | **+25pp** |
|
|
160
|
-
| Middleware pipeline (web_api) | 100% | 100% | — |
|
|
161
|
-
| Circuit breaker (microsvc) | 75% | 75% | — |
|
|
162
|
-
| Services & communication | 50% | **100%** | **+50pp** |
|
|
163
|
-
| PipelineBuilder pattern | 100% | 75% | -25pp* |
|
|
164
|
-
| Processor registration | 33% | **67%** | **+34pp** |
|
|
165
|
-
| Event bus & error handling | 100% | 100% | — |
|
|
166
|
-
> \* Without context the model gave a generic answer matching all keywords; with context it focused on actual code — more honest, more useful.
|
|
167
|
-
|
|
168
|
-
**+16.7pp average coverage improvement** — better answers, concrete file names, real code structure.
|
|
169
|
-
|
|
170
143
|
### Token Savings Display
|
|
171
144
|
|
|
172
|
-
Use `--savings` to see how many tokens each capsule saves:
|
|
173
|
-
|
|
174
145
|
```bash
|
|
175
146
|
ctx capsule "user authentication" --savings
|
|
176
147
|
# ┌──────────────────────────┬──────────────┐
|
|
@@ -184,37 +155,95 @@ ctx capsule "user authentication" --savings
|
|
|
184
155
|
# └──────────────────────────┴──────────────┘
|
|
185
156
|
```
|
|
186
157
|
|
|
187
|
-
`ctx ask` shows this automatically on every query.
|
|
158
|
+
`ctx ask` shows this automatically on every query. See how many tokens you save with each question.
|
|
188
159
|
|
|
189
160
|
---
|
|
190
161
|
|
|
191
162
|
## Commands
|
|
192
163
|
|
|
193
164
|
### `ctx init` — Scaffold project
|
|
165
|
+
|
|
194
166
|
```bash
|
|
195
|
-
ctx init
|
|
196
|
-
|
|
167
|
+
ctx init # Default: current directory
|
|
168
|
+
ctx init /path/to/project # Specific path
|
|
197
169
|
```
|
|
198
|
-
|
|
170
|
+
|
|
171
|
+
Creates a `.ctxgraph/` directory with everything you need:
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
.ctxgraph/
|
|
175
|
+
├── config.toml # API provider, model, context settings
|
|
176
|
+
├── history.jsonl # Query history (auto-created, auto-pruned to 1000)
|
|
177
|
+
└── skills/
|
|
178
|
+
├── project-style.toml # Default skill: project conventions
|
|
179
|
+
└── field-guide.toml # Default skill: field guide
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Idempotent — safe to run on existing projects. Existing files are never overwritten.
|
|
199
183
|
|
|
200
184
|
### `ctx build` — Build knowledge graph
|
|
185
|
+
|
|
201
186
|
```bash
|
|
202
187
|
ctx build # Current directory
|
|
203
188
|
ctx build /path/to/project # Specific repo
|
|
204
189
|
ctx build --exclude "vendor/*" # Custom exclude patterns
|
|
190
|
+
ctx build --provider claude # Set LLM provider for later use
|
|
191
|
+
ctx build --model gpt-4o # Set LLM model for later use
|
|
205
192
|
```
|
|
206
193
|
|
|
207
194
|
### `ctx ask <query>` — Ask questions via LLM
|
|
195
|
+
|
|
196
|
+
The marquee command. Generates a context capsule, sends it to your LLM provider, and shows token savings.
|
|
197
|
+
|
|
208
198
|
```bash
|
|
209
|
-
ctx ask "how does JWT auth work"
|
|
199
|
+
ctx ask "how does JWT auth work" # Uses configured provider (default: Ollama)
|
|
210
200
|
ctx ask "fix login bug" --provider claude --model claude-sonnet-4-20250514
|
|
211
|
-
ctx ask "refactor payment flow" --skill project-style
|
|
212
|
-
ctx ask "find auth code" --graph
|
|
213
|
-
ctx ask "deep dive" --mode deep
|
|
201
|
+
ctx ask "refactor payment flow" --skill project-style # Activate a skill as system prompt
|
|
202
|
+
ctx ask "find auth code" --graph # Show graph search results table
|
|
203
|
+
ctx ask "deep dive" --mode deep # Use deep graph context (40 nodes)
|
|
204
|
+
ctx ask "explain" --skill field-guide --graph # Combine skill + graph results
|
|
214
205
|
```
|
|
215
|
-
Shows token savings automatically. Requires a running Ollama instance (or other configured provider).
|
|
216
206
|
|
|
217
|
-
|
|
207
|
+
**Flags:**
|
|
208
|
+
|
|
209
|
+
| Flag | Description |
|
|
210
|
+
|------|-------------|
|
|
211
|
+
| `--provider` | LLM provider: `ollama`, `claude`, `openai`, `azure`, `custom` |
|
|
212
|
+
| `--model` | Model name (e.g. `gpt-4o`, `claude-sonnet-4-20250514`) |
|
|
213
|
+
| `--skill` | Skill name to activate (e.g. `project-style`, `field-guide`) |
|
|
214
|
+
| `--graph` | Show ranked graph search results alongside the answer |
|
|
215
|
+
| `--mode` | Graph context mode: `fast`, `balanced` (default), `deep` |
|
|
216
|
+
|
|
217
|
+
**Requirements:**
|
|
218
|
+
- A built graph (run `ctx build` first)
|
|
219
|
+
- A running LLM provider (Ollama by default at `http://localhost:11434`)
|
|
220
|
+
|
|
221
|
+
**Example output:**
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
$ ctx ask "how does the greeting system work"
|
|
225
|
+
|
|
226
|
+
# (Token savings table shown automatically)
|
|
227
|
+
┌──────────────────────────┬──────────────┐
|
|
228
|
+
│ Metric │ Value │
|
|
229
|
+
├──────────────────────────┼──────────────┤
|
|
230
|
+
│ Raw Project .py Files │ 1,234 tokens │
|
|
231
|
+
│ Capsule DSL │ 45 tokens │
|
|
232
|
+
│ JSON Equivalent │ 180 tokens │
|
|
233
|
+
│ Savings vs Raw │ 96.4% │
|
|
234
|
+
│ DSL vs JSON │ 75.0% │
|
|
235
|
+
└──────────────────────────┴──────────────┘
|
|
236
|
+
|
|
237
|
+
Answer:
|
|
238
|
+
The greeting system is implemented in `src/greet.py`. The `greet()` function takes a name
|
|
239
|
+
and returns a formatted greeting string. The `Greeter` class extends this with a configurable
|
|
240
|
+
prefix. Both use type hints and follow the project conventions.
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### `ctx capsule <query>` — Generate context capsule
|
|
244
|
+
|
|
245
|
+
Generate a token-efficient DSL capsule for use with any AI tool.
|
|
246
|
+
|
|
218
247
|
```bash
|
|
219
248
|
ctx capsule "fix JWT token validation" # Balanced (default: 20 nodes, depth 2)
|
|
220
249
|
ctx capsule "fix JWT token validation" --mode fast # Fast (10 nodes, depth 1)
|
|
@@ -231,55 +260,127 @@ ctx capsule "fix auth" --skill project-style # Prepends skill context
|
|
|
231
260
|
| `deep` | 40 | 3 | Complex refactoring, architecture |
|
|
232
261
|
|
|
233
262
|
### `ctx query <search>` — Search graph
|
|
263
|
+
|
|
234
264
|
```bash
|
|
235
265
|
ctx query "user auth"
|
|
236
266
|
ctx query "payment gateway" --mode deep
|
|
237
267
|
```
|
|
238
|
-
|
|
268
|
+
|
|
269
|
+
Returns ranked nodes with relevance scores, displaying type, name, path, and score.
|
|
239
270
|
|
|
240
271
|
### `ctx view` — Visualize graph
|
|
272
|
+
|
|
241
273
|
```bash
|
|
242
|
-
ctx view
|
|
243
|
-
ctx view --output graph.html
|
|
244
|
-
ctx view --
|
|
274
|
+
ctx view # Opens interactive D3.js HTML in browser
|
|
275
|
+
ctx view --output graph.html # Save to custom path
|
|
276
|
+
ctx view --svg # Generate static SVG
|
|
277
|
+
ctx view --no-open # Generate without opening browser
|
|
245
278
|
```
|
|
246
|
-
Interactive D3.js force-directed HTML — no JS build tools needed.
|
|
247
279
|
|
|
248
|
-
### `ctx
|
|
280
|
+
### `ctx history` — Query history
|
|
281
|
+
|
|
282
|
+
Review past questions, token savings, and provider usage.
|
|
283
|
+
|
|
249
284
|
```bash
|
|
250
|
-
|
|
251
|
-
ctx
|
|
285
|
+
ctx history # Last 10 queries
|
|
286
|
+
ctx history -n 20 # Last 20
|
|
287
|
+
ctx history --filter "auth" # Filter by keyword in query text
|
|
288
|
+
ctx history --stats # Aggregate statistics
|
|
252
289
|
```
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
290
|
+
|
|
291
|
+
**Example output:**
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
$ ctx history
|
|
295
|
+
┌────────────┬──────────────────────────────────────────────────┬─────────┬──────────┬──────────┐
|
|
296
|
+
│ Time │ Query │ Savings │ Provider │ Skill │
|
|
297
|
+
├────────────┼──────────────────────────────────────────────────┼─────────┼──────────┼──────────┤
|
|
298
|
+
│ 2026-06-06 │ how does the greeting system work │ 96.4% │ ollama │ - │
|
|
299
|
+
│ 2026-06-06 │ fix login rate limiter │ 97.1% │ ollama │ - │
|
|
300
|
+
│ 2026-06-06 │ refactor payment module with proper error handl… │ 95.8% │ claude │ project-style │
|
|
301
|
+
└────────────┴──────────────────────────────────────────────────┴─────────┴──────────┴──────────┘
|
|
302
|
+
|
|
303
|
+
$ ctx history --stats
|
|
304
|
+
┌──────────────────────┬───────────┐
|
|
305
|
+
│ Metric │ Value │
|
|
306
|
+
├──────────────────────┼───────────┤
|
|
307
|
+
│ Total Queries │ 24 │
|
|
308
|
+
│ Total Raw Tokens │ 254,088 │
|
|
309
|
+
│ Total Tokens Saved │ 246,465 │
|
|
310
|
+
│ Avg Savings │ 96.5% │
|
|
311
|
+
│ Provider: ollama │ 18 │
|
|
312
|
+
│ Provider: claude │ 6 │
|
|
313
|
+
└──────────────────────┴───────────┘
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
History is stored as JSONL in `.ctxgraph/history.jsonl`. Auto-prunes to 1000 entries (oldest dropped).
|
|
317
|
+
|
|
318
|
+
### `ctx skill` — Manage skills
|
|
319
|
+
|
|
320
|
+
Skills are reusable system prompts that prepend project knowledge to your capsule context.
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
ctx skill list # Show all available skills
|
|
324
|
+
ctx skill show project-style # Display a skill's contents
|
|
263
325
|
```
|
|
264
|
-
Tools: `search_graph`, `get_context_capsule`, `get_file_dependencies`, `get_project_overview`.
|
|
265
326
|
|
|
266
|
-
|
|
327
|
+
**Example:**
|
|
328
|
+
|
|
267
329
|
```bash
|
|
268
|
-
ctx
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
330
|
+
$ ctx skill list
|
|
331
|
+
┌─────────┬─────────────────┬────────────────────────────────────────────────────┐
|
|
332
|
+
│ Source │ Name │ Preview │
|
|
333
|
+
├─────────┼─────────────────┼────────────────────────────────────────────────────┤
|
|
334
|
+
│ builtin │ project-style │ # Project Style Guide — default ctxgraph skill │
|
|
335
|
+
│ builtin │ field-guide │ # Project Field Guide — default ctxgraph skill │
|
|
336
|
+
└─────────┴─────────────────┴────────────────────────────────────────────────────┘
|
|
337
|
+
|
|
338
|
+
$ ctx skill show project-style
|
|
339
|
+
Skill: project-style
|
|
340
|
+
|
|
341
|
+
# Project Style Guide — default ctxgraph skill
|
|
342
|
+
# Activate with: ctx ask --skill project-style "..."
|
|
343
|
+
|
|
344
|
+
[about]
|
|
345
|
+
name = "Project Style Guide"
|
|
346
|
+
description = "Enforces project conventions, code style, and naming patterns"
|
|
347
|
+
|
|
348
|
+
[rules]
|
|
349
|
+
import_style = "absolute imports, grouped: stdlib, third-party, local"
|
|
350
|
+
naming = "snake_case for functions/variables, PascalCase for classes, UPPER_CASE for constants"
|
|
351
|
+
...
|
|
272
352
|
```
|
|
273
|
-
History stored in JSONL format at `.ctxgraph/history.jsonl`. Auto-prunes to 1000 entries.
|
|
274
353
|
|
|
275
|
-
|
|
354
|
+
**Activating a skill:**
|
|
355
|
+
|
|
276
356
|
```bash
|
|
277
|
-
ctx
|
|
278
|
-
ctx
|
|
357
|
+
ctx ask "refactor payment flow" --skill project-style
|
|
358
|
+
ctx capsule "fix auth" --skill field-guide
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
When activated, the skill contents are prepended as a `## Project Knowledge` section before the capsule DSL.
|
|
362
|
+
|
|
363
|
+
**Creating your own skills:**
|
|
364
|
+
|
|
365
|
+
Skills are TOML files in `.ctxgraph/skills/`. Create a new file:
|
|
366
|
+
|
|
367
|
+
```toml
|
|
368
|
+
# .ctxgraph/skills/my-team-rules.toml
|
|
369
|
+
|
|
370
|
+
[about]
|
|
371
|
+
name = "Team Conventions"
|
|
372
|
+
description = "Custom team coding conventions"
|
|
373
|
+
|
|
374
|
+
[rules]
|
|
375
|
+
testing = "must write pytest tests for all new functions"
|
|
376
|
+
documentation = "every public API needs a docstring with Args and Returns"
|
|
377
|
+
branching = "prefer early returns over nested if-else"
|
|
279
378
|
```
|
|
280
|
-
|
|
379
|
+
|
|
380
|
+
Now it appears in `ctx skill list` and can be activated with `--skill my-team-rules`.
|
|
281
381
|
|
|
282
382
|
### `ctx info` — Graph statistics
|
|
383
|
+
|
|
283
384
|
```bash
|
|
284
385
|
ctx info
|
|
285
386
|
# ┌────────────────────┬───────┐
|
|
@@ -291,10 +392,34 @@ ctx info
|
|
|
291
392
|
# └────────────────────┴───────┘
|
|
292
393
|
```
|
|
293
394
|
|
|
395
|
+
### `ctx serve` — MCP server
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
pip install ctxgraph[mcp]
|
|
399
|
+
ctx serve
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
Claude Desktop config:
|
|
403
|
+
|
|
404
|
+
```json
|
|
405
|
+
{
|
|
406
|
+
"mcpServers": {
|
|
407
|
+
"ctxgraph": {
|
|
408
|
+
"command": "ctx",
|
|
409
|
+
"args": ["serve"]
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
Tools: `search_graph`, `get_context_capsule`, `get_file_dependencies`, `get_project_overview`.
|
|
416
|
+
|
|
294
417
|
---
|
|
295
418
|
|
|
296
419
|
## Claude Wrapper (`ccg`)
|
|
297
420
|
|
|
421
|
+
The `ccg` command launches Claude Code with ctxgraph context pre-loaded:
|
|
422
|
+
|
|
298
423
|
```bash
|
|
299
424
|
ccg "fix the JWT expiry bug in auth module" # Single-shot
|
|
300
425
|
ccg --chat "refactor the payment flow" # Interactive session
|
|
@@ -306,7 +431,8 @@ ccg --mode deep "redesign the database schema" # Deep mode
|
|
|
306
431
|
|
|
307
432
|
## Configuration
|
|
308
433
|
|
|
309
|
-
`.ctxgraph/config.toml`:
|
|
434
|
+
`.ctxgraph/config.toml` is auto-created by `ctx init`:
|
|
435
|
+
|
|
310
436
|
```toml
|
|
311
437
|
[graph]
|
|
312
438
|
exclude = ["legacy/*", "vendor/*"]
|
|
@@ -315,6 +441,7 @@ exclude = ["legacy/*", "vendor/*"]
|
|
|
315
441
|
provider = "ollama" # ollama, claude, openai, azure, custom
|
|
316
442
|
model = "qwen2.5-coder:7b"
|
|
317
443
|
endpoint = "http://localhost:11434"
|
|
444
|
+
api_key = ""
|
|
318
445
|
|
|
319
446
|
[context]
|
|
320
447
|
mode = "balanced"
|
|
@@ -322,45 +449,46 @@ max_nodes = 20
|
|
|
322
449
|
max_depth = 2
|
|
323
450
|
```
|
|
324
451
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
|
328
|
-
|
|
329
|
-
| `
|
|
330
|
-
| `
|
|
331
|
-
| `
|
|
332
|
-
| `
|
|
452
|
+
### Environment variables
|
|
453
|
+
|
|
454
|
+
| Variable | Overrides | Required For |
|
|
455
|
+
|----------|-----------|-------------|
|
|
456
|
+
| `CTXGRAPH_PROVIDER` | `ai.provider` | — |
|
|
457
|
+
| `CTXGRAPH_MODEL` | `ai.model` | — |
|
|
458
|
+
| `CTXGRAPH_ENDPOINT` | `ai.endpoint` | — |
|
|
459
|
+
| `ANTHROPIC_API_KEY` | `ai.api_key` | Claude provider |
|
|
460
|
+
| `OPENAI_API_KEY` | `ai.api_key` | OpenAI provider |
|
|
461
|
+
| `AZURE_OPENAI_API_KEY` | `ai.api_key` | Azure provider |
|
|
462
|
+
|
|
463
|
+
### Provider examples
|
|
333
464
|
|
|
334
465
|
```bash
|
|
335
466
|
# Ollama (default — no env vars needed)
|
|
336
|
-
ctx
|
|
467
|
+
ctx ask "how does auth work"
|
|
337
468
|
|
|
338
469
|
# Claude
|
|
339
|
-
CTXGRAPH_PROVIDER=claude CTXGRAPH_MODEL=claude-sonnet-4-20250514 ctx
|
|
470
|
+
CTXGRAPH_PROVIDER=claude CTXGRAPH_MODEL=claude-sonnet-4-20250514 ctx ask "explain the architecture"
|
|
340
471
|
|
|
341
472
|
# OpenAI
|
|
342
|
-
CTXGRAPH_PROVIDER=openai CTXGRAPH_MODEL=gpt-4o ctx
|
|
473
|
+
CTXGRAPH_PROVIDER=openai CTXGRAPH_MODEL=gpt-4o ctx ask "find the bug"
|
|
343
474
|
|
|
344
475
|
# Azure OpenAI
|
|
345
476
|
CTXGRAPH_PROVIDER=azure \
|
|
346
477
|
CTXGRAPH_MODEL=gpt-4o \
|
|
347
478
|
CTXGRAPH_ENDPOINT=https://my-resource.openai.azure.com \
|
|
348
479
|
AZURE_OPENAI_API_KEY=sk-... \
|
|
349
|
-
ctx
|
|
480
|
+
ctx ask "refactor this"
|
|
350
481
|
|
|
351
482
|
# Custom (OpenAI-compatible)
|
|
352
|
-
CTXGRAPH_PROVIDER=custom CTXGRAPH_ENDPOINT=http://my-api/v1 ctx
|
|
483
|
+
CTXGRAPH_PROVIDER=custom CTXGRAPH_ENDPOINT=http://my-api/v1 ctx ask "explain"
|
|
484
|
+
|
|
485
|
+
# Per-command override (overrides both config and env vars)
|
|
486
|
+
ctx ask "how does this work" --provider claude --model claude-sonnet-4-20250514
|
|
353
487
|
```
|
|
354
488
|
|
|
355
489
|
> **Windows (PowerShell):** Use `$env:` prefix instead:
|
|
356
490
|
> ```powershell
|
|
357
|
-
> $env:CTXGRAPH_PROVIDER = "azure"; $env:CTXGRAPH_MODEL = "gpt-4o"; ctx
|
|
358
|
-
> ```
|
|
359
|
-
> Or set them once per session:
|
|
360
|
-
> ```powershell
|
|
361
|
-
> $env:CTXGRAPH_PROVIDER = "azure"
|
|
362
|
-
> $env:AZURE_OPENAI_API_KEY = "sk-..."
|
|
363
|
-
> ctx capsule "query"
|
|
491
|
+
> $env:CTXGRAPH_PROVIDER = "azure"; $env:CTXGRAPH_MODEL = "gpt-4o"; ctx ask "query"
|
|
364
492
|
> ```
|
|
365
493
|
|
|
366
494
|
---
|
|
@@ -368,6 +496,7 @@ CTXGRAPH_PROVIDER=custom CTXGRAPH_ENDPOINT=http://my-api/v1 ctx capsule "query"
|
|
|
368
496
|
## Use Cases
|
|
369
497
|
|
|
370
498
|
### Debug a failing test
|
|
499
|
+
|
|
371
500
|
```bash
|
|
372
501
|
ctx build
|
|
373
502
|
ctx capsule "test_user_login is failing with auth error" --mode deep
|
|
@@ -375,17 +504,35 @@ ctx capsule "test_user_login is failing with auth error" --mode deep
|
|
|
375
504
|
# [F]src/auth/login.py
|
|
376
505
|
# [C]AuthService
|
|
377
506
|
# [DEP] auth/login.py → core/database.py, auth/session.py
|
|
507
|
+
|
|
508
|
+
# Or ask directly:
|
|
509
|
+
ctx ask "test_user_login is failing" --mode deep
|
|
510
|
+
# → Explains the issue with file references and suggests fixes
|
|
378
511
|
```
|
|
379
512
|
|
|
380
513
|
### Understand a new codebase
|
|
514
|
+
|
|
381
515
|
```bash
|
|
516
|
+
ctx build
|
|
382
517
|
ctx capsule "project architecture" --overview
|
|
383
518
|
ccg --chat "explain the overall architecture and data flow"
|
|
519
|
+
|
|
520
|
+
# Or explore with skills active:
|
|
521
|
+
ctx ask "explain the architecture" --skill field-guide
|
|
384
522
|
```
|
|
385
523
|
|
|
386
524
|
### Refactor across modules
|
|
525
|
+
|
|
387
526
|
```bash
|
|
388
527
|
ctx capsule "extract payment processing into separate module" --mode deep
|
|
528
|
+
ctx ask "plan the payment module extraction" --skill project-style --mode deep
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
### Track your LLM usage
|
|
532
|
+
|
|
533
|
+
```bash
|
|
534
|
+
ctx history --stats
|
|
535
|
+
# Shows total queries, tokens saved, avg savings, provider breakdown
|
|
389
536
|
```
|
|
390
537
|
|
|
391
538
|
---
|
|
@@ -433,6 +580,27 @@ for node, score in results:
|
|
|
433
580
|
|
|
434
581
|
> **Tip:** `build_graph` is a one-time setup. In production, run `ctx build` during CI/deployment and let your app code only call `get_storage` + `render_capsule`.
|
|
435
582
|
|
|
583
|
+
### Compose with skill context
|
|
584
|
+
|
|
585
|
+
```python
|
|
586
|
+
from ctxgraph.skills import load_skill
|
|
587
|
+
|
|
588
|
+
storage = get_storage(Path("./my_project"))
|
|
589
|
+
skill_text = load_skill(Path("./my_project"), "project-style")
|
|
590
|
+
capsule = render_capsule(storage, "fix auth", max_nodes=20, skill_context=skill_text)
|
|
591
|
+
# Capsule now has "## Project Knowledge" section prepended
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
### Compute token savings
|
|
595
|
+
|
|
596
|
+
```python
|
|
597
|
+
from ctxgraph.capsule.savings import compute_savings
|
|
598
|
+
|
|
599
|
+
savings = compute_savings(Path("./my_project"), capsule_text)
|
|
600
|
+
print(f"Saved {savings['savings_pct']}% tokens")
|
|
601
|
+
print(f"DSL is {savings['dsl_vs_json']}% more efficient than JSON")
|
|
602
|
+
```
|
|
603
|
+
|
|
436
604
|
### LangChain
|
|
437
605
|
|
|
438
606
|
Pass the capsule as context in your prompt template. The LLM gets exactly the files, classes, and dependencies it needs — no token waste.
|
|
@@ -441,13 +609,10 @@ Pass the capsule as context in your prompt template. The LLM gets exactly the fi
|
|
|
441
609
|
from pathlib import Path
|
|
442
610
|
from langchain_openai import ChatOpenAI
|
|
443
611
|
from langchain_core.prompts import ChatPromptTemplate
|
|
444
|
-
from ctxgraph.graph.builder import get_storage
|
|
612
|
+
from ctxgraph.graph.builder import get_storage
|
|
445
613
|
from ctxgraph.capsule.renderer import render_capsule
|
|
446
614
|
|
|
447
|
-
# Load existing graph (zero build time)
|
|
448
615
|
storage = get_storage(Path("./my_project"))
|
|
449
|
-
|
|
450
|
-
# Generate capsule for the question
|
|
451
616
|
context = render_capsule(storage, "login rate limiter", max_nodes=15)
|
|
452
617
|
|
|
453
618
|
prompt = ChatPromptTemplate.from_messages([
|
|
@@ -462,13 +627,11 @@ print(response.invoke({
|
|
|
462
627
|
"context": context,
|
|
463
628
|
"question": "Where is the rate limiter applied in the login flow?",
|
|
464
629
|
}))
|
|
465
|
-
# → "The rate limiter is in src/auth/middleware.py at line 42.
|
|
466
|
-
# It wraps the login endpoint with a 5req/min limit per IP."
|
|
467
630
|
```
|
|
468
631
|
|
|
469
632
|
### LangGraph
|
|
470
633
|
|
|
471
|
-
Expose ctxgraph as a tool the agent calls on-demand.
|
|
634
|
+
Expose ctxgraph as a tool the agent calls on-demand.
|
|
472
635
|
|
|
473
636
|
```python
|
|
474
637
|
from pathlib import Path
|
|
@@ -479,17 +642,13 @@ from langchain_core.tools import tool
|
|
|
479
642
|
from ctxgraph.graph.builder import get_storage
|
|
480
643
|
from ctxgraph.capsule.renderer import render_capsule
|
|
481
644
|
|
|
482
|
-
# Pre-built graph — loaded instantly
|
|
483
645
|
_storage = get_storage(Path("./my_project"))
|
|
484
646
|
|
|
485
647
|
@tool
|
|
486
648
|
def code_context(task: str) -> str:
|
|
487
|
-
"""Fetch relevant source code for a development task.
|
|
488
|
-
Use this whenever the user asks about implementation details,
|
|
489
|
-
bug fixes, or architecture in the codebase."""
|
|
649
|
+
"""Fetch relevant source code for a development task."""
|
|
490
650
|
return render_capsule(_storage, task, max_nodes=20)
|
|
491
651
|
|
|
492
|
-
# --- Build LangGraph ---
|
|
493
652
|
tools = [code_context]
|
|
494
653
|
model = ChatOpenAI(model="gpt-4o", temperature=0).bind_tools(tools)
|
|
495
654
|
|
|
@@ -508,7 +667,6 @@ graph.add_edge("tools", "agent")
|
|
|
508
667
|
|
|
509
668
|
app = graph.compile()
|
|
510
669
|
|
|
511
|
-
# --- Run ---
|
|
512
670
|
for chunk in app.stream({"messages": [("user", "How does payment retry work?")]}):
|
|
513
671
|
for node, vals in chunk.items():
|
|
514
672
|
msg = vals["messages"][0]
|
|
@@ -516,12 +674,8 @@ for chunk in app.stream({"messages": [("user", "How does payment retry work?")]}
|
|
|
516
674
|
print(f"[{node}]: {msg.content[:300]}")
|
|
517
675
|
```
|
|
518
676
|
|
|
519
|
-
When the user asks about code, the agent calls `code_context("payment retry")`, gets back a capsule with `[F]src/payment/retry.py`, `[F]src/payment/processor.py`, and their dependency edges, then answers with those files in context.
|
|
520
|
-
|
|
521
677
|
### OpenAI Agents SDK
|
|
522
678
|
|
|
523
|
-
Same pattern — ctxgraph is a function tool the agent invokes.
|
|
524
|
-
|
|
525
679
|
```python
|
|
526
680
|
from pathlib import Path
|
|
527
681
|
from agents import Agent, Runner, function_tool
|
|
@@ -532,8 +686,7 @@ _storage = get_storage(Path("./my_project"))
|
|
|
532
686
|
|
|
533
687
|
@function_tool
|
|
534
688
|
def fetch_code_context(task_description: str) -> str:
|
|
535
|
-
"""Retrieve code context from the project's knowledge graph.
|
|
536
|
-
Provide a task description like 'JWT auth middleware' or 'payment processor'."""
|
|
689
|
+
"""Retrieve code context from the project's knowledge graph."""
|
|
537
690
|
return render_capsule(_storage, task_description, max_nodes=20)
|
|
538
691
|
|
|
539
692
|
agent = Agent(
|
|
@@ -549,8 +702,6 @@ print(result.final_output)
|
|
|
549
702
|
|
|
550
703
|
### Azure OpenAI (direct client)
|
|
551
704
|
|
|
552
|
-
For Azure OpenAI or any OpenAI-compatible endpoint, inject the capsule directly into the system message.
|
|
553
|
-
|
|
554
705
|
```python
|
|
555
706
|
import os
|
|
556
707
|
from openai import AzureOpenAI
|
|
@@ -568,7 +719,7 @@ client = AzureOpenAI(
|
|
|
568
719
|
)
|
|
569
720
|
|
|
570
721
|
response = client.chat.completions.create(
|
|
571
|
-
model="gpt-4o",
|
|
722
|
+
model="gpt-4o",
|
|
572
723
|
messages=[
|
|
573
724
|
{"role": "system", "content": f"You are a senior developer. Code context:\n\n{context}"},
|
|
574
725
|
{"role": "user", "content": "How do I add a new event handler?"},
|
|
@@ -585,12 +736,13 @@ print(response.choices[0].message.content)
|
|
|
585
736
|
git clone https://github.com/shashi3070/ctxgraph.git
|
|
586
737
|
cd ctxgraph
|
|
587
738
|
pip install -e ".[dev]"
|
|
588
|
-
pytest
|
|
739
|
+
pytest # 88+ tests
|
|
589
740
|
python benchmarks/run_benchmarks.py
|
|
590
741
|
python benchmarks/run_ollama_comparison.py # Requires local Ollama
|
|
591
742
|
```
|
|
592
743
|
|
|
593
744
|
### Project Structure
|
|
745
|
+
|
|
594
746
|
```
|
|
595
747
|
src/ctxgraph/
|
|
596
748
|
├── cli/main.py — Typer CLI (9 commands)
|
|
@@ -607,7 +759,6 @@ src/ctxgraph/
|
|
|
607
759
|
│ ├── symbols.py — AST class/function/method analysis
|
|
608
760
|
│ └── semantic.py — Docstring summarization
|
|
609
761
|
├── config/
|
|
610
|
-
│ ├── __init__.py
|
|
611
762
|
│ ├── init.py — Project scaffold (.ctxgraph dir)
|
|
612
763
|
│ ├── settings.py — TOML/JSON/env config loading
|
|
613
764
|
│ └── providers.py — Ollama, Claude, OpenAI clients
|