ctxgraph-code 0.6.0__py3-none-any.whl → 0.6.2__py3-none-any.whl

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_code/cli.py CHANGED
@@ -254,29 +254,22 @@ def _write_slash_command(slash_path: Path, path: Path):
254
254
 
255
255
  SLASH_COMMAND_TEMPLATE = """# ctxgraph-code: Code Relationship Graph
256
256
 
257
- **First time in this project?** Tell the user to run `ctxgraph-code setup` in their terminal.
258
-
259
- **Graph needs refresh?** Tell the user to run `ctxgraph-code build`.
260
-
261
257
  **Available graphs:** {available}
262
258
 
263
259
  **Commands:**
264
- - `ctxgraph-code query "terms"` -- Find relevant files, classes, and functions
265
- - `ctxgraph-code probe "question"` -- Search graph and read matching source code inline
266
- - `ctxgraph-code deps <path>` -- Show what a file imports and what calls it
267
- - `ctxgraph-code usedby <path>` -- Show what depends on a file
268
- - `ctxgraph-code overview --dir <name>` -- Show project structure for a specific graph
269
- - `ctxgraph-code symbols <path>` -- List classes/functions defined in a file
270
- - `ctxgraph-code context "task"` -- Generate a focused context summary
271
- - `ctxgraph-code subgraph "task"` -- Extract a focused subgraph with inline source for a task
272
- - `ctxgraph-code diff` -- Compare graph with filesystem to find new/removed/changed files
273
- - `ctxgraph-code mermaid --type classDiagram` -- Export graph as Mermaid diagram
274
- - `ctxgraph-code view --dir <name>` -- Visualize a graph interactively
275
- - `ctxgraph-code build-status` -- Show last build status and timing
276
- - `ctxgraph-code install-slash` -- (Re)install this slash command
277
-
278
- **Tip:** Use `--dir <name>` to scope queries to a per-directory graph.
279
- When passing a file path like `auth/login.py`, the correct graph is auto-detected.
260
+ - `ctxgraph-code query "terms"` -- Files, classes, functions
261
+ - `ctxgraph-code probe "question"` -- Search + read source inline
262
+ - `ctxgraph-code deps <path>` -- Dependencies of a file
263
+ - `ctxgraph-code usedby <path>` -- What depends on a file
264
+ - `ctxgraph-code overview --dir <name>` -- Project structure
265
+ - `ctxgraph-code symbols <path>` -- Classes/functions in a file
266
+ - `ctxgraph-code context "task"` -- Focused context summary
267
+ - `ctxgraph-code subgraph "task"` -- Focused subgraph with source
268
+ - `ctxgraph-code diff` -- Files changed since build
269
+ - `ctxgraph-code mermaid --type classDiagram` -- Mermaid diagram
270
+ - `ctxgraph-code view --dir <name>` -- Interactive D3.js graph
271
+
272
+ Use `--dir <name>` to scope queries. File paths auto-detect the graph dir.
280
273
  """
281
274
 
282
275
 
@@ -1110,7 +1103,7 @@ def version():
1110
1103
  try:
1111
1104
  ver = _v("ctxgraph-code")
1112
1105
  except Exception:
1113
- ver = "0.6.0"
1106
+ ver = "0.6.2"
1114
1107
  console.print(f"ctxgraph-code version [bold]{ver}[/bold]")
1115
1108
 
1116
1109
 
@@ -79,8 +79,6 @@ def uninstall_hooks(project_path: Path, local: bool = False) -> bool:
79
79
 
80
80
 
81
81
  def compute_hint_summary(repo_path: Path) -> Optional[str]:
82
- import hashlib
83
-
84
82
  avail = get_available_graphs(repo_path)
85
83
  if not avail["_combined"] and not avail["dirs"]:
86
84
  return None
@@ -100,8 +98,6 @@ def compute_hint_summary(repo_path: Path) -> Optional[str]:
100
98
  total_edges = stats.get("edges", 0)
101
99
  types = stats.get("types", {})
102
100
 
103
- top_files = _get_top_files(storage, 5)
104
-
105
101
  file_count = types.get("file", 0)
106
102
  class_count = types.get("class", 0)
107
103
  func_count = types.get("function", 0)
@@ -112,55 +108,11 @@ def compute_hint_summary(repo_path: Path) -> Optional[str]:
112
108
  ]
113
109
  if file_count:
114
110
  lines.append(f"Files: {file_count} | Classes: {class_count} | Functions: {func_count}.")
115
- if top_files:
116
- lines.append(f"Key files: {', '.join(top_files)}.")
117
-
118
- # ── Tamper detection ──────────────────────────────────────
119
- hashes_json = storage.get_metadata("content_hashes")
120
- tampered: int = 0
121
- if hashes_json:
122
- try:
123
- stored_hashes = json.loads(hashes_json)
124
- for rel_path, stored_hash in stored_hashes.items():
125
- fp = repo_path / rel_path
126
- if not fp.is_file():
127
- tampered += 1
128
- continue
129
- try:
130
- actual = hashlib.sha256(
131
- fp.read_text(encoding="utf-8", errors="replace")
132
- .encode("utf-8")
133
- ).hexdigest()
134
- if actual != stored_hash:
135
- tampered += 1
136
- except OSError:
137
- tampered += 1
138
- except (json.JSONDecodeError, OSError):
139
- pass
140
- if tampered:
141
- lines.append(
142
- f"Warning: {tampered} file(s) have changed since graph was built. "
143
- "Run `ctxgraph-code build --incremental` to update."
144
- )
145
111
 
146
112
  lines.append(
147
- "Use `ctxgraph-code probe \"<question>\"`, "
148
- "`ctxgraph-code subgraph \"<task>\"`, or "
149
- "`/ctxgraph-code` for help."
113
+ "Use `ctxgraph-code probe` or `/ctxgraph-code` for help."
150
114
  )
151
115
 
152
116
  return "\n".join(lines)
153
117
  finally:
154
118
  storage.close()
155
-
156
-
157
- def _get_top_files(storage, limit: int = 5) -> list[str]:
158
- try:
159
- rows = storage.conn.execute(
160
- "SELECT path FROM nodes WHERE type = 'file' AND path IS NOT NULL "
161
- "ORDER BY size_bytes DESC LIMIT ?",
162
- (limit,),
163
- ).fetchall()
164
- return [r[0] for r in rows if r[0]]
165
- except Exception:
166
- return []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ctxgraph-code
3
- Version: 0.6.0
3
+ Version: 0.6.2
4
4
  Summary: Code knowledge graph for Claude Code. Build a relationship graph of your Python codebase and query it during coding sessions.
5
5
  Author: ctxgraph-code contributors
6
6
  License: MIT
@@ -26,7 +26,13 @@ Requires-Dist: pytest>=7.0; extra == "dev"
26
26
 
27
27
  # ctxgraph-code
28
28
 
29
- **Code knowledge graph for Claude Code.** Build a relationship graph of your codebase (Python, JavaScript, TypeScript, C, Go, Rust, and more) so Claude Code understands imports, class hierarchies, function calls, and cross-file dependencies without reading every file.
29
+ **How do we give AI the right context without sending the entire codebase every time?**
30
+
31
+ `ctxgraph-code` answers that question. Instead of dumping files into the context window, it builds a **relationship graph** of your codebase using static AST analysis, stores it in a local SQLite database, and retrieves only the relevant symbols and dependencies when Claude Code needs to understand your code.
32
+
33
+ **Result:** One codebase question drops from ~25,000 tokens to ~800 tokens — a **95% reduction** in context usage. A full 30-question benchmark showed **90% fewer tokens** than traditional file reading, and **16% fewer than graph-based alternatives**.
34
+
35
+ ![Product Overview](https://raw.githubusercontent.com/shashi3070/ctxgraph-code/master/docs/benchmark2.jpg)
30
36
 
31
37
  ```bash
32
38
  pip install ctxgraph-code
@@ -67,6 +73,29 @@ ctxgraph-code setup
67
73
  # /ctxgraph-code
68
74
  ```
69
75
 
76
+ ## How It Works (At a Glance)
77
+
78
+ ```
79
+ Your Codebase
80
+
81
+
82
+ 1. Static AST Analysis ──► Extract imports, classes, functions, calls, relationships
83
+
84
+
85
+ 2. Knowledge Graph ──► Store everything in local SQLite (files, symbols, edges)
86
+
87
+
88
+ 3. Query Engine ──► Search graph by relevance, expand to neighbors via BFS
89
+
90
+
91
+ 4. Context Retrieval ──► Only the relevant snippets, not whole files
92
+
93
+
94
+ 5. Claude Code ──► Receives focused context → Better answers, fewer tokens, less noise
95
+ ```
96
+
97
+ No huge graph-building prompts sent to the LLM. The graph is built locally with Python's AST parser — zero LLM calls, zero API costs.
98
+
70
99
  ## Commands
71
100
 
72
101
  ### `setup` (recommended)
@@ -113,6 +142,37 @@ ctxgraph-code init
113
142
 
114
143
  Creates the `.ctxgraph/` directory with a default `config.toml`.
115
144
 
145
+ ### `subgraph`
146
+
147
+ ```bash
148
+ ctxgraph-code subgraph "add pagination to the users endpoint"
149
+ ```
150
+
151
+ Extracts a **focused subgraph** relevant to a task description — returns matching nodes, their relationships, and inline source code in a single compact response. Saves 1-2 tool calls by combining graph search, dependency resolution, and file reading.
152
+
153
+ - `--max-nodes` / `-n` — max nodes in subgraph (default: 10)
154
+
155
+ ### `diff`
156
+
157
+ ```bash
158
+ ctxgraph-code diff
159
+ ctxgraph-code diff --ref main
160
+ ```
161
+
162
+ Compares the graph with the filesystem. Shows files that have been **added, removed, or changed** since the graph was built. Use `--ref` for a git-aware diff against a branch. Essential for knowing when to run `ctxgraph-code build --incremental`.
163
+
164
+ ### `mermaid`
165
+
166
+ ```bash
167
+ ctxgraph-code mermaid classDiagram
168
+ ctxgraph-code mermaid flowchart --output diagram.md
169
+ ```
170
+
171
+ Exports the graph as a **Mermaid diagram** for embedding in documentation or PRs. Supported types: `classDiagram`, `flowchart`, `sequence`.
172
+
173
+ - `--output` / `-o` — save to file instead of stdout
174
+ - `--max-nodes` / `-n` — maximum nodes in diagram (default: 50)
175
+
116
176
  ### `build`
117
177
 
118
178
  ```bash
@@ -348,6 +408,105 @@ This catches the common case where you edit a file after building the graph and
348
408
 
349
409
  ---
350
410
 
411
+ ## Benchmark Results
412
+
413
+ Real-world benchmarks against a production Python/UI codebase. Three approaches compared across 30 code understanding questions.
414
+
415
+ ### Repository Profile
416
+
417
+ | Metric | Value |
418
+ |---|---|
419
+ | Backend Python LOC | 45,570 |
420
+ | UI Source LOC | 37,317 |
421
+ | Documentation LOC | 9,120 |
422
+ | Source Files | 143 |
423
+ | Raw Tokens | ~140,000 |
424
+
425
+ ### Three Retrieval Methods Compared
426
+
427
+ | Approach | How It Works |
428
+ |---|---|
429
+ | **Baseline** (File Reading) | `grep` → read entire files → answer. Every question repeatedly loads large source files. |
430
+ | **Graphify** (Knowledge Graph) | Build full graph → compressed node summaries → answer. Incurs large upfront graph-building cost. |
431
+ | **CtxGraph-Code** (Symbol Graph) | Local AST → SQLite symbol graph → retrieve only relevant files → answer. Only targeted files opened. |
432
+
433
+ ### Combined Results (30 Questions)
434
+
435
+ | Approach | Total Tokens | Avg/Question | Reduction |
436
+ |---|---|---|---|
437
+ | Baseline (File Reading) | 203,590 | 6,786 | — |
438
+ | Graphify | 25,100 | 837 | 88% |
439
+ | **CtxGraph-Code** | **21,120** | **704** | **90%** |
440
+
441
+ CtxGraph-Code is **9.6× more efficient** than reading raw files, and uses **16% fewer tokens** than Graphify.
442
+
443
+ ![Benchmark Comparison](https://raw.githubusercontent.com/shashi3070/ctxgraph-code/master/docs/Benchmark%20Vs%20Graphify.jpg)
444
+
445
+ ### Per-Suite Breakdown
446
+
447
+ | Suite | Baseline | Graphify | CtxGraph-Code | Winner |
448
+ |---|---|---|---|---|
449
+ | BM1: Architecture | 73,500 | 12,100 | 10,150 | CtxGraph-Code |
450
+ | BM2: Data Flow & UI Logic | 130,090 | 13,000 | 10,970 | CtxGraph-Code |
451
+ | **Combined** | **203,590** | **25,100** | **21,120** | **CtxGraph-Code** |
452
+
453
+ ### Biggest Win: File Comparison
454
+
455
+ Question: *"How does tasks_fixed.py differ from tasks.py?"*
456
+
457
+ - `tasks.py`: 2,372 lines
458
+ - `tasks_fixed.py`: 1,512 lines
459
+
460
+ | Approach | Tokens |
461
+ |---|---|
462
+ | Baseline | 31,070 |
463
+ | Graphify | 1,400 |
464
+ | **CtxGraph-Code** | **1,150 (96% savings)** |
465
+
466
+ Instead of reading both files completely, CtxGraph-Code compares symbols and retrieves only relevant differences.
467
+
468
+ ### Context Window Longevity
469
+
470
+ With a 200K token context window:
471
+
472
+ | Approach | Tokens/Question | Questions Before Exhaustion |
473
+ |---|---|---|
474
+ | Baseline | 6,786 | ~29 |
475
+ | Graphify | 837 | ~239 |
476
+ | **CtxGraph-Code** | **704** | **~284 (10× longer sessions)** |
477
+
478
+ ### Graphify vs CtxGraph-Code: Detailed Comparison
479
+
480
+ ![Phase-by-Phase Comparison](https://raw.githubusercontent.com/shashi3070/ctxgraph-code/master/docs/Benchmark%20Vs%20Graphify.jpg)
481
+
482
+ | Metric | Graphify | CtxGraph-Code |
483
+ |---|---|---|
484
+ | **Build approach** | Full knowledge graph first | Local symbol graph via AST + SQLite |
485
+ | **Upfront LLM cost** | ~141,728 input tokens | ~0 tokens (local AST parse, ~246s) |
486
+ | **Total input tokens** | ~157,728 | ~22,500 (**85.7% fewer**) |
487
+ | **Output tokens** | ~12,000 | ~3,500 (**70.8% fewer**) |
488
+ | **Query speed** | Moderate (BFS/DFS traversal) | Fast (SQLite indexed lookup) |
489
+ | **Strengths** | Architecture visualization, community detection, cross-file relationship discovery | Inline source retrieval, indexed search, symbol resolution, implementation-focused answers |
490
+ | **Weaknesses** | No implementation snippets; often requires opening source files after | Less visualization; relationship discovery less deep |
491
+ | **Best for** | Architecture discovery, planning, cross-cutting concerns | Code navigation, execution flow, symbol lookup, implementation questions |
492
+
493
+ **Bottom line:** Use CtxGraph-Code for fast code search and implementation answers. Use Graphify when you need architecture visualization and cross-file relationship discovery.
494
+
495
+ ### Real-World Example Results
496
+
497
+ | Question | Without | With CtxGraph-Code | Savings |
498
+ |---|---|---|---|
499
+ | Learning Mode | 9,498 | 3,267 | 66% |
500
+ | Planner Node | 13,166 | 7,043 | 47% |
501
+ | Dashboard Embedding | 5,180 | 2,840 | 45% |
502
+ | Authentication | 9,498 | 3,267 | 66% |
503
+ | Deep Learning Mode | 25,000 | 800 | 95% |
504
+ | **Overall (30 questions)** | **203,590** | **21,120** | **90%** |
505
+
506
+ ![Detailed Benchmark Results](https://raw.githubusercontent.com/shashi3070/ctxgraph-code/master/docs/benchmark1.jpg)
507
+
508
+ ---
509
+
351
510
  ## Using with Claude Code
352
511
 
353
512
  After `ctxgraph-code setup`, the `/ctxgraph-code` slash command is installed globally by default — it works in every Claude Code session. Claude sees:
@@ -367,6 +526,9 @@ After `ctxgraph-code setup`, the `/ctxgraph-code` slash command is installed glo
367
526
  - `ctxgraph-code overview --dir <name>` -- Show project structure for a specific graph
368
527
  - `ctxgraph-code symbols <path>` -- List classes/functions defined in a file
369
528
  - `ctxgraph-code context "task"` -- Generate a focused context summary
529
+ - `ctxgraph-code subgraph "task"` -- Focused subgraph with inline source
530
+ - `ctxgraph-code diff` -- Files changed since build
531
+ - `ctxgraph-code mermaid --type classDiagram` -- Export as Mermaid diagram
370
532
  - `ctxgraph-code view --dir <name>` -- Visualize a graph interactively
371
533
  ```
372
534
 
@@ -404,13 +566,30 @@ Built-in default exclusion patterns (always applied): `__pycache__`, `*.pyc`, `.
404
566
 
405
567
  ---
406
568
 
569
+ ## Where It Helps
570
+
571
+ `ctxgraph-code` delivers the most value when working with **existing codebases built over months or years**:
572
+
573
+ | Helps Most | Helps Less |
574
+ |---|---|
575
+ | 🐛 Debugging production issues | Tiny projects (2–3 files) |
576
+ | 🏗 Understanding architecture | Throwaway scripts |
577
+ | 🔍 Tracing dependencies | Greenfield projects created entirely in the same Claude session |
578
+ | 🔄 Safe refactoring | Short experiments |
579
+ | 📚 Onboarding into large existing codebases | |
580
+ | 🧩 Multi-module repositories | |
581
+
582
+ The biggest gains come when AI needs to understand **existing code written over months or years**, not when starting from scratch.
583
+
584
+ ---
585
+
407
586
  ## Differences from `ctxgraph`
408
587
 
409
588
  `ctxgraph-code` is a **focused subset** of [ctxgraph](https://github.com/shashi3070/ctxgraph) designed specifically for Claude Code.
410
589
 
411
590
  | Feature | ctxgraph | ctxgraph-code |
412
591
  |---------|----------|---------------|
413
- | CLI commands | 9+ | 17 (init, build, query, deps, usedby, overview, symbols, context, setup, view, info, install-slash, build-status, probe, install-hooks, uninstall-hooks, version) |
592
+ | CLI commands | 9+ | 20 (init, build, query, deps, usedby, overview, symbols, context, subgraph, diff, mermaid, setup, view, info, install-slash, build-status, probe, install-hooks, uninstall-hooks, version) |
414
593
  | LLM integration | Built-in (Ollama, Claude, OpenAI, Azure) | None (delegates to Claude Code) |
415
594
  | Chat sessions | Yes | No |
416
595
  | Visualizer | D3.js HTML + SVG | D3.js HTML (`view` opens in browser, `--tree` for text) |
@@ -1,6 +1,6 @@
1
1
  ctxgraph_code/__init__.py,sha256=8Bo3TpyB49uJs6QpQMTWpUR2hJhqEpbkK_E_GW7tYpU,5
2
2
  ctxgraph_code/__main__.py,sha256=AfV3Onj_9FoL9W8B5jOWOeIyYF2MwX6S4-wyF9U90wM,41
3
- ctxgraph_code/cli.py,sha256=N2-39jCTs_P3yRVhWTN6jRFbTaQ68c5QTpYpPfAGEB4,52164
3
+ ctxgraph_code/cli.py,sha256=Tlx5FWctV_fPtzQ5lXXWx75lE5CrchvIiDFcNotK9fk,51574
4
4
  ctxgraph_code/analyzers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  ctxgraph_code/analyzers/python/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  ctxgraph_code/analyzers/python/importer.py,sha256=_5WV-RHK9IzbjCaVi_-1rWCYSuJIu0jHj5bW4uPQViY,4688
@@ -12,7 +12,7 @@ ctxgraph_code/analyzers/treesitter/languages.py,sha256=fnX9KEXYQUfHZcmW46Fi6Y4jL
12
12
  ctxgraph_code/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  ctxgraph_code/config/build_status.py,sha256=e2tdNc34oJd-iDAi4aFEi-TkY9lIhkicCjmSj6VpvHY,2754
14
14
  ctxgraph_code/config/global_paths.py,sha256=amCTdTiaNcB-0P4LHtl6yaHv84ReXpOtCsb2ofIR-9M,183
15
- ctxgraph_code/config/hooks.py,sha256=hqQKCexlXsmXa_MOXJZoJEpbwmsJNo0_cOJ0-sQJsro,5198
15
+ ctxgraph_code/config/hooks.py,sha256=vvPMztr5heNY4haLj386yq1tNE7A9wX8JHpIuY6BWis,3354
16
16
  ctxgraph_code/config/init.py,sha256=tXVcDTPAJGVbzPavABRfnCXUsf9Pt-VzDUgV5YX09Tc,501
17
17
  ctxgraph_code/config/settings.py,sha256=H_-8UtIX2GwN-BCpg-fusoghhaZHFjkE1HSe2AcwxkM,5302
18
18
  ctxgraph_code/exclude/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -27,8 +27,8 @@ ctxgraph_code/render/_text.py,sha256=zic5X5gKfuqZSL0sAxsAOCkZcHnac0eta2FXO_DNaHQ
27
27
  ctxgraph_code/render/mermaid.py,sha256=5TE4wdBBBgK_GRHri48Z0k6_17jtnMKKvyKXGLC0L8M,4719
28
28
  ctxgraph_code/view/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
29
  ctxgraph_code/view/visualizer.py,sha256=xvPn9eSDYAk_HICpL6Nt7CQ_5FOKX0EXpZGM6wwyv9s,10555
30
- ctxgraph_code-0.6.0.dist-info/METADATA,sha256=DGgXYp6Uu5L44pQTT1NG1MyA4_Gu5awGEQ9jW16KbhM,18040
31
- ctxgraph_code-0.6.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
32
- ctxgraph_code-0.6.0.dist-info/entry_points.txt,sha256=Q6poS8LApu1uGl_T9hjoZ7VMC8-iXZFCMslDx6OjlRo,56
33
- ctxgraph_code-0.6.0.dist-info/top_level.txt,sha256=ZOmow7lPtFHkcRJhLFOP5DVbt_SVaFrzsgXsawzMsq8,14
34
- ctxgraph_code-0.6.0.dist-info/RECORD,,
30
+ ctxgraph_code-0.6.2.dist-info/METADATA,sha256=Pf50A0tVNBznh3DVaVphbwRMSzYXEy3vwVs283-CmfI,25511
31
+ ctxgraph_code-0.6.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
32
+ ctxgraph_code-0.6.2.dist-info/entry_points.txt,sha256=Q6poS8LApu1uGl_T9hjoZ7VMC8-iXZFCMslDx6OjlRo,56
33
+ ctxgraph_code-0.6.2.dist-info/top_level.txt,sha256=ZOmow7lPtFHkcRJhLFOP5DVbt_SVaFrzsgXsawzMsq8,14
34
+ ctxgraph_code-0.6.2.dist-info/RECORD,,