ctxgraph 0.3.2__tar.gz → 0.5.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.
Files changed (56) hide show
  1. {ctxgraph-0.3.2/src/ctxgraph.egg-info → ctxgraph-0.5.0}/PKG-INFO +138 -10
  2. ctxgraph-0.3.2/PKG-INFO → ctxgraph-0.5.0/README.md +891 -792
  3. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/pyproject.toml +5 -2
  4. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/capsule/savings.py +26 -17
  5. ctxgraph-0.5.0/src/ctxgraph/chat.py +228 -0
  6. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/cli/main.py +239 -3
  7. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/config/settings.py +60 -8
  8. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/mcp/server.py +8 -1
  9. ctxgraph-0.5.0/src/ctxgraph/skills/field-guide.toml +12 -0
  10. ctxgraph-0.5.0/src/ctxgraph/skills/project-style.toml +15 -0
  11. ctxgraph-0.5.0/src/ctxgraph/skills/template.example.toml +43 -0
  12. ctxgraph-0.3.2/README.md → ctxgraph-0.5.0/src/ctxgraph.egg-info/PKG-INFO +920 -763
  13. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph.egg-info/SOURCES.txt +4 -0
  14. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/tests/test_config.py +68 -0
  15. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/tests/test_e2e.py +82 -4
  16. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/setup.cfg +0 -0
  17. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/__init__.py +0 -0
  18. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/analyzers/__init__.py +0 -0
  19. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/analyzers/python/__init__.py +0 -0
  20. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/analyzers/python/importer.py +0 -0
  21. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/analyzers/python/semantic.py +0 -0
  22. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/analyzers/python/symbols.py +0 -0
  23. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/capsule/__init__.py +0 -0
  24. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/capsule/renderer.py +0 -0
  25. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/cli/__init__.py +0 -0
  26. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/clients/__init__.py +0 -0
  27. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/clients/models.py +0 -0
  28. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/config/__init__.py +0 -0
  29. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/config/init.py +0 -0
  30. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/config/providers.py +0 -0
  31. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/exclude/__init__.py +0 -0
  32. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/exclude/patterns.py +0 -0
  33. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/graph/__init__.py +0 -0
  34. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/graph/builder.py +0 -0
  35. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/graph/models.py +0 -0
  36. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/graph/query.py +0 -0
  37. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/graph/storage.py +0 -0
  38. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/history.py +0 -0
  39. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/mcp/__init__.py +0 -0
  40. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/skills/__init__.py +0 -0
  41. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/view/__init__.py +0 -0
  42. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/view/visualizer.py +0 -0
  43. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/wrapper/__init__.py +0 -0
  44. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph/wrapper/claude.py +0 -0
  45. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph.egg-info/dependency_links.txt +0 -0
  46. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph.egg-info/entry_points.txt +0 -0
  47. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph.egg-info/requires.txt +0 -0
  48. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/src/ctxgraph.egg-info/top_level.txt +0 -0
  49. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/tests/test_analyzers.py +0 -0
  50. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/tests/test_benchmark.py +0 -0
  51. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/tests/test_capsule.py +0 -0
  52. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/tests/test_integration.py +0 -0
  53. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/tests/test_model_mode.py +0 -0
  54. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/tests/test_models.py +0 -0
  55. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/tests/test_query.py +0 -0
  56. {ctxgraph-0.3.2 → ctxgraph-0.5.0}/tests/test_storage.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ctxgraph
3
- Version: 0.3.2
4
- Summary: 97% cheaper AI coding. ctx init ctx build ctx ask. Knowledge graphs, token-efficient capsules, query history, skills, and multi-provider LLM answers (Ollama, Claude, OpenAI, Azure). Cut context costs from cents to fractions of a cent.
3
+ Version: 0.5.0
4
+ Summary: 97% cheaper AI coding. ctxgraph builds a knowledge graph of your Python codebase, then generates token-efficient context capsules for any AI tool. Or hook up Ollama/Claude/OpenAI and use it as a code-aware coding assistant like ChatGPT or Claude Code, but with built-in graph context. Cut token costs by 97%, work offline with just a graph, or connect your favorite LLM.
5
5
  Author: ctxgraph contributors
6
6
  License: MIT
7
7
  Keywords: code-graph,knowledge-graph,claude,code-analysis,ai-context,token-savings,ollama,openai,ctx,capsule
@@ -29,15 +29,26 @@ Requires-Dist: ruff>=0.1.0; extra == "dev"
29
29
 
30
30
  # ctxgraph — AI Context Engine for Python
31
31
 
32
- **Slash your LLM token costs by 97%.** Stop dumping entire files into AI context. ctxgraph builds a multi-layer knowledge graph from your Python codebase and generates *compact context capsules* — delivering only what your AI needs, not every line of code.
32
+ ## What is ctxgraph?
33
+
34
+ ctxgraph is a **knowledge graph engine** that makes AI coding assistants **97% cheaper** and **smarter**.
35
+
36
+ It analyzes your Python codebase using AST-based static analysis, builds a searchable dependency graph, and delivers *only the code that matters* to your AI — not every line in your project.
37
+
38
+ ### Two ways to use it:
39
+
40
+ **🔧 As a token-saving context engine** — Output compact DSL capsules for any AI tool (Claude, ChatGPT, Cursor, etc.). Cut context costs from dollars to fractions of a cent.
41
+
42
+ **🤖 As a full AI coding assistant** — Hook up Ollama (free, local), Claude, or OpenAI, and ask questions, refactor code, debug issues, or explore architecture through `ctx ask` or `ctx chat` — just like ChatGPT or Claude Code, but with built-in codebase awareness.
33
43
 
34
44
  ```bash
35
45
  pip install ctxgraph
36
46
 
37
47
  ctx init # Scaffold .ctxgraph with config + default skills
38
48
  ctx build # Build knowledge graph (AST analysis → SQLite)
39
- ctx ask "how does JWT auth work" # Ask questions with automatic token savings
40
- ctx capsule "fix JWT expiry" # 92-99% fewer tokens vs raw code
49
+ ctx ask "how does JWT auth work" # Ask questions with automatic token savings (needs LLM)
50
+ ctx capsule "fix JWT expiry" # 92-99% fewer tokens vs raw code (no LLM needed)
51
+ ctx chat "refactor this module" # Multi-turn conversation with persistent sessions
41
52
  ctx history --stats # Track total tokens saved across all queries
42
53
  ccg "fix the login redirect bug" # Launch Claude with context pre-loaded
43
54
  ctx view # Interactive D3.js visualization (or --svg for static)
@@ -56,11 +67,14 @@ ctx init # Creates .ctxgraph/config.toml + default ski
56
67
  # 2. Build the knowledge graph
57
68
  ctx build # AST analysis → SQLite graph
58
69
 
59
- # 3. Ask questions (requires Ollama or other LLM provider)
70
+ # 3a. Ask questions (requires Ollama or other LLM provider — free with Ollama)
60
71
  ctx ask "how does authentication work"
61
72
 
62
- # 4. Or generate a capsule for your AI tool
73
+ # 3b. Or just generate a capsule for your AI tool (no LLM needed)
63
74
  ctx capsule "fix login rate limiter" --savings
75
+
76
+ # 4. Explore interactively
77
+ ctx chat # Multi-turn REPL with persistent sessions
64
78
  ```
65
79
 
66
80
  ---
@@ -69,6 +83,8 @@ ctx capsule "fix login rate limiter" --savings
69
83
 
70
84
  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.
71
85
 
86
+ **No LLM? No problem.** ctxgraph's core features (graph building, capsule generation, search, visualization) work entirely offline. You only need an LLM provider when you want to ask questions via `ctx ask` or chat via `ctx chat`.
87
+
72
88
  | Without ctxgraph | With ctxgraph | Savings |
73
89
  |:---|---:|:---:|
74
90
  | All files dumped to context | Targeted capsule (10-40 nodes) | **97% fewer tokens** |
@@ -157,7 +173,7 @@ ctx capsule "user authentication" --savings
157
173
  # └──────────────────────────┴──────────────┘
158
174
  ```
159
175
 
160
- `ctx ask` shows this automatically on every query. See how many tokens you save with each question.
176
+ `ctx ask` and `ctx chat` show this automatically. See how many tokens you save with each interaction.
161
177
 
162
178
  ---
163
179
 
@@ -242,6 +258,85 @@ and returns a formatted greeting string. The `Greeter` class extends this with a
242
258
  prefix. Both use type hints and follow the project conventions.
243
259
  ```
244
260
 
261
+ ### `ctx chat [message]` — Interactive multi-turn conversation
262
+
263
+ Chat mode maintains a persistent session across turns. Sessions are saved to `.ctxgraph/chats/` and survive CLI restart.
264
+
265
+ #### Single-shot mode
266
+
267
+ ```bash
268
+ ctx chat "how does the auth system work" # Start or continue a session
269
+ ctx chat "what about the JWT tokens" # Follow-up question — stays in REPL
270
+ ctx chat --new "explain the payment flow" # Start a fresh session
271
+ ```
272
+
273
+ #### Interactive REPL mode
274
+
275
+ Run `ctx chat` without a message to enter interactive mode. No session is created until you send your first message.
276
+
277
+ ```bash
278
+ $ ctx chat
279
+ Chat Commands:
280
+ /resume Select and resume a previous session
281
+ /compact Compact current session (summarize oldest messages)
282
+ /new Start a fresh session
283
+ /list List all chat sessions
284
+ /show Show current session context
285
+ /help Show this help message
286
+ /exit Exit chat mode
287
+
288
+ Or type any message to send it to the LLM.
289
+
290
+ > how does the auth system work?
291
+ Started new session: a1b2c3d4
292
+
293
+ # (LLM answer + token savings table)
294
+ Session a1b2c3d4: 625/200,000 tokens used
295
+
296
+ > and the refresh tokens?
297
+ # (Continues same session — sends capsule + history)
298
+ Session a1b2c3d4: 1,234/200,000 tokens used
299
+
300
+ > /resume
301
+ # Use ↑/↓ to select a previous session, Enter to confirm
302
+ # (Resume session e5f6g7h8)
303
+
304
+ > /compact
305
+ Session compacted.
306
+
307
+ > /exit
308
+ ```
309
+
310
+ #### Session picker (`/resume`)
311
+
312
+ Use the up/down arrow keys to navigate, Enter to select, Esc to cancel:
313
+
314
+ ```
315
+ ┌─────────────────────────────────────────────────────────────┐
316
+ │ Chat Sessions (↑/↓ select, Enter confirm, Esc cancel) │
317
+ ├─────┬──────────┬───────┬────────┬───────────────────────────┤
318
+ │ # │ ID │ Turns │ Tokens │ Last │
319
+ ├─────┼──────────┼───────┼────────┼───────────────────────────┤
320
+ │ 1 │ a1b2c3d4 │ 5 │ 1,234 │ how does the auth system… │
321
+ │ 2 │ e5f6g7h8 │ 2 │ 456 │ fix the login redirect… │
322
+ └─────┴──────────┴───────┴────────┴───────────────────────────┘
323
+ ```
324
+
325
+ #### Session management
326
+
327
+ - Sessions auto-compact when approaching the token limit (`max_session_tokens` in config, default 200k)
328
+ - Oldest turns are summarized into a compact system note; latest turns preserved
329
+ - Each session shows token usage at the end of every turn
330
+
331
+ **Flags:**
332
+
333
+ | Flag | Description |
334
+ |------|-------------|
335
+ | `--new` | Start a fresh session (discard previous context) |
336
+ | `--list`, `-l` | List all sessions with turn/token counts |
337
+ | `--show <id>` | View a session's transcript |
338
+ | `--compact`, `-c` | Manually trigger compaction |
339
+
245
340
  ### `ctx capsule <query>` — Generate context capsule
246
341
 
247
342
  Generate a token-efficient DSL capsule for use with any AI tool.
@@ -381,6 +476,23 @@ branching = "prefer early returns over nested if-else"
381
476
 
382
477
  Now it appears in `ctx skill list` and can be activated with `--skill my-team-rules`.
383
478
 
479
+ **Skill template:**
480
+
481
+ `ctx init` ships a fully-commented skill template at `.ctxgraph/skills/template.example.toml`. It shows every available section and their options:
482
+
483
+ ```toml
484
+ # .ctxgraph/skills/template.example.toml (commented reference)
485
+ #
486
+ # [about] — REQUIRED: name and description
487
+ # [rules] — REQUIRED: instruction key/value pairs
488
+ # [context] — OPTIONAL: file filters and limits
489
+ # [response] — OPTIONAL: output formatting controls
490
+ # [output] — OPTIONAL: save-to-file behavior
491
+ # [meta] — OPTIONAL: author, version, requirements
492
+ ```
493
+
494
+ To create a new skill, copy the file (remove `.example` from the name) and uncomment the sections you need.
495
+
384
496
  ### `ctx info` — Graph statistics
385
497
 
386
498
  ```bash
@@ -444,11 +556,18 @@ provider = "ollama" # ollama, claude, openai, azure, custom
444
556
  model = "qwen2.5-coder:7b"
445
557
  endpoint = "http://localhost:11434"
446
558
  api_key = ""
559
+ # For Azure provider, uncomment and set:
560
+ # azure_deployment = "my-gpt-4o-deployment"
561
+ # api_version = "2024-08-01-preview"
447
562
 
448
563
  [context]
449
564
  mode = "balanced"
450
565
  max_nodes = 20
451
566
  max_depth = 2
567
+
568
+ [chat]
569
+ # Max tokens per chat session before auto-compact
570
+ max_session_tokens = 200000
452
571
  ```
453
572
 
454
573
  ### Environment variables
@@ -461,6 +580,8 @@ max_depth = 2
461
580
  | `ANTHROPIC_API_KEY` | `ai.api_key` | Claude provider |
462
581
  | `OPENAI_API_KEY` | `ai.api_key` | OpenAI provider |
463
582
  | `AZURE_OPENAI_API_KEY` | `ai.api_key` | Azure provider |
583
+ | `AZURE_OPENAI_DEPLOYMENT` | `ai.azure_deployment` | Azure deployment name |
584
+ | `AZURE_OPENAI_API_VERSION` | `ai.api_version` | Azure API version |
464
585
 
465
586
  ### Provider examples
466
587
 
@@ -475,11 +596,16 @@ CTXGRAPH_PROVIDER=claude CTXGRAPH_MODEL=claude-sonnet-4-20250514 ctx ask "explai
475
596
  CTXGRAPH_PROVIDER=openai CTXGRAPH_MODEL=gpt-4o ctx ask "find the bug"
476
597
 
477
598
  # Azure OpenAI
599
+ # Uses `api-key` header (not Bearer), requires `azure_deployment` and `api_version`
478
600
  CTXGRAPH_PROVIDER=azure \
479
601
  CTXGRAPH_MODEL=gpt-4o \
480
602
  CTXGRAPH_ENDPOINT=https://my-resource.openai.azure.com \
481
603
  AZURE_OPENAI_API_KEY=sk-... \
604
+ AZURE_OPENAI_DEPLOYMENT=my-gpt-4o-deployment \
605
+ AZURE_OPENAI_API_VERSION=2024-08-01-preview \
482
606
  ctx ask "refactor this"
607
+ # The endpoint is your resource URL. The chat URL becomes:
608
+ # /openai/deployments/{azure_deployment}/chat/completions?api-version={api_version}
483
609
 
484
610
  # Custom (OpenAI-compatible)
485
611
  CTXGRAPH_PROVIDER=custom CTXGRAPH_ENDPOINT=http://my-api/v1 ctx ask "explain"
@@ -600,7 +726,7 @@ from ctxgraph.capsule.savings import compute_savings
600
726
 
601
727
  savings = compute_savings(Path("./my_project"), capsule_text)
602
728
  print(f"Saved {savings['savings_pct']}% tokens")
603
- print(f"DSL is {savings['dsl_vs_json']}% more efficient than JSON")
729
+ print(f"DSL is {savings['dsl_vs_json_pct']}% more efficient than JSON")
604
730
  ```
605
731
 
606
732
  ### LangChain
@@ -764,6 +890,7 @@ src/ctxgraph/
764
890
  │ ├── init.py — Project scaffold (.ctxgraph dir)
765
891
  │ ├── settings.py — TOML/JSON/env config loading
766
892
  │ └── providers.py — Ollama, Claude, OpenAI clients
893
+ ├── chat.py — Chat session management (multi-turn, compaction)
767
894
  ├── clients/models.py — Mode enum (fast/balanced/deep)
768
895
  ├── exclude/patterns.py — Exclusion pattern matching
769
896
  ├── view/visualizer.py — D3.js HTML graph generator
@@ -772,7 +899,8 @@ src/ctxgraph/
772
899
  ├── skills/
773
900
  │ ├── __init__.py — Skill discovery + loading
774
901
  │ ├── project-style.toml — Default skill: project conventions
775
- └── field-guide.toml — Default skill: field guide
902
+ ├── field-guide.toml — Default skill: field guide
903
+ │ └── template.example.toml — Commented skill template reference
776
904
  └── history.py — JSONL history append/query/stats
777
905
  ```
778
906