ctxgraph 0.3.1__tar.gz → 0.4.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.1/src/ctxgraph.egg-info → ctxgraph-0.4.0}/PKG-INFO +123 -8
  2. ctxgraph-0.3.1/PKG-INFO → ctxgraph-0.4.0/README.md +876 -790
  3. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/pyproject.toml +6 -3
  4. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/capsule/savings.py +26 -17
  5. ctxgraph-0.4.0/src/ctxgraph/chat.py +228 -0
  6. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/cli/main.py +239 -3
  7. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/config/settings.py +38 -3
  8. ctxgraph-0.4.0/src/ctxgraph/skills/field-guide.toml +12 -0
  9. ctxgraph-0.4.0/src/ctxgraph/skills/project-style.toml +15 -0
  10. ctxgraph-0.4.0/src/ctxgraph/skills/template.example.toml +43 -0
  11. ctxgraph-0.3.1/README.md → ctxgraph-0.4.0/src/ctxgraph.egg-info/PKG-INFO +905 -761
  12. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph.egg-info/SOURCES.txt +4 -0
  13. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/tests/test_config.py +68 -0
  14. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/tests/test_e2e.py +82 -4
  15. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/setup.cfg +0 -0
  16. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/__init__.py +0 -0
  17. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/analyzers/__init__.py +0 -0
  18. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/analyzers/python/__init__.py +0 -0
  19. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/analyzers/python/importer.py +0 -0
  20. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/analyzers/python/semantic.py +0 -0
  21. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/analyzers/python/symbols.py +0 -0
  22. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/capsule/__init__.py +0 -0
  23. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/capsule/renderer.py +0 -0
  24. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/cli/__init__.py +0 -0
  25. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/clients/__init__.py +0 -0
  26. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/clients/models.py +0 -0
  27. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/config/__init__.py +0 -0
  28. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/config/init.py +0 -0
  29. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/config/providers.py +0 -0
  30. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/exclude/__init__.py +0 -0
  31. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/exclude/patterns.py +0 -0
  32. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/graph/__init__.py +0 -0
  33. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/graph/builder.py +0 -0
  34. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/graph/models.py +0 -0
  35. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/graph/query.py +0 -0
  36. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/graph/storage.py +0 -0
  37. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/history.py +0 -0
  38. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/mcp/__init__.py +0 -0
  39. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/mcp/server.py +0 -0
  40. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/skills/__init__.py +0 -0
  41. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/view/__init__.py +0 -0
  42. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/view/visualizer.py +0 -0
  43. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/wrapper/__init__.py +0 -0
  44. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph/wrapper/claude.py +0 -0
  45. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph.egg-info/dependency_links.txt +0 -0
  46. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph.egg-info/entry_points.txt +0 -0
  47. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph.egg-info/requires.txt +0 -0
  48. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/src/ctxgraph.egg-info/top_level.txt +0 -0
  49. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/tests/test_analyzers.py +0 -0
  50. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/tests/test_benchmark.py +0 -0
  51. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/tests/test_capsule.py +0 -0
  52. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/tests/test_integration.py +0 -0
  53. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/tests/test_model_mode.py +0 -0
  54. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/tests/test_models.py +0 -0
  55. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/tests/test_query.py +0 -0
  56. {ctxgraph-0.3.1 → ctxgraph-0.4.0}/tests/test_storage.py +0 -0
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ctxgraph
3
- Version: 0.3.1
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.
3
+ Version: 0.4.0
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.
5
5
  Author: ctxgraph contributors
6
6
  License: MIT
7
- Keywords: code-graph,knowledge-graph,claude,code-analysis,ai-context
7
+ Keywords: code-graph,knowledge-graph,claude,code-analysis,ai-context,token-savings,ollama,openai,ctx,capsule
8
8
  Classifier: Development Status :: 3 - Alpha
9
9
  Classifier: Intended Audience :: Developers
10
10
  Classifier: License :: OSI Approved :: MIT License
@@ -29,14 +29,17 @@ 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%.** ctxgraph builds a multi-layer knowledge graph from your Python codebase, then generates *compact context capsules* — delivering only what your AI needs, not every line of code.
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.
33
33
 
34
34
  ```bash
35
35
  pip install ctxgraph
36
36
 
37
- ctx build # Build knowledge graph
37
+ ctx init # Scaffold .ctxgraph with config + default skills
38
+ ctx build # Build knowledge graph (AST analysis → SQLite)
38
39
  ctx ask "how does JWT auth work" # Ask questions with automatic token savings
39
40
  ctx capsule "fix JWT expiry" # 92-99% fewer tokens vs raw code
41
+ ctx chat "refactor this module" # Multi-turn conversation with persistent sessions
42
+ ctx history --stats # Track total tokens saved across all queries
40
43
  ccg "fix the login redirect bug" # Launch Claude with context pre-loaded
41
44
  ctx view # Interactive D3.js visualization (or --svg for static)
42
45
  ```
@@ -155,7 +158,7 @@ ctx capsule "user authentication" --savings
155
158
  # └──────────────────────────┴──────────────┘
156
159
  ```
157
160
 
158
- `ctx ask` shows this automatically on every query. See how many tokens you save with each question.
161
+ `ctx ask` and `ctx chat` show this automatically. See how many tokens you save with each interaction.
159
162
 
160
163
  ---
161
164
 
@@ -240,6 +243,85 @@ and returns a formatted greeting string. The `Greeter` class extends this with a
240
243
  prefix. Both use type hints and follow the project conventions.
241
244
  ```
242
245
 
246
+ ### `ctx chat [message]` — Interactive multi-turn conversation
247
+
248
+ Chat mode maintains a persistent session across turns. Sessions are saved to `.ctxgraph/chats/` and survive CLI restart.
249
+
250
+ #### Single-shot mode
251
+
252
+ ```bash
253
+ ctx chat "how does the auth system work" # Start or continue a session
254
+ ctx chat "what about the JWT tokens" # Follow-up question — stays in REPL
255
+ ctx chat --new "explain the payment flow" # Start a fresh session
256
+ ```
257
+
258
+ #### Interactive REPL mode
259
+
260
+ Run `ctx chat` without a message to enter interactive mode. No session is created until you send your first message.
261
+
262
+ ```bash
263
+ $ ctx chat
264
+ Chat Commands:
265
+ /resume Select and resume a previous session
266
+ /compact Compact current session (summarize oldest messages)
267
+ /new Start a fresh session
268
+ /list List all chat sessions
269
+ /show Show current session context
270
+ /help Show this help message
271
+ /exit Exit chat mode
272
+
273
+ Or type any message to send it to the LLM.
274
+
275
+ > how does the auth system work?
276
+ Started new session: a1b2c3d4
277
+
278
+ # (LLM answer + token savings table)
279
+ Session a1b2c3d4: 625/200,000 tokens used
280
+
281
+ > and the refresh tokens?
282
+ # (Continues same session — sends capsule + history)
283
+ Session a1b2c3d4: 1,234/200,000 tokens used
284
+
285
+ > /resume
286
+ # Use ↑/↓ to select a previous session, Enter to confirm
287
+ # (Resume session e5f6g7h8)
288
+
289
+ > /compact
290
+ Session compacted.
291
+
292
+ > /exit
293
+ ```
294
+
295
+ #### Session picker (`/resume`)
296
+
297
+ Use the up/down arrow keys to navigate, Enter to select, Esc to cancel:
298
+
299
+ ```
300
+ ┌─────────────────────────────────────────────────────────────┐
301
+ │ Chat Sessions (↑/↓ select, Enter confirm, Esc cancel) │
302
+ ├─────┬──────────┬───────┬────────┬───────────────────────────┤
303
+ │ # │ ID │ Turns │ Tokens │ Last │
304
+ ├─────┼──────────┼───────┼────────┼───────────────────────────┤
305
+ │ 1 │ a1b2c3d4 │ 5 │ 1,234 │ how does the auth system… │
306
+ │ 2 │ e5f6g7h8 │ 2 │ 456 │ fix the login redirect… │
307
+ └─────┴──────────┴───────┴────────┴───────────────────────────┘
308
+ ```
309
+
310
+ #### Session management
311
+
312
+ - Sessions auto-compact when approaching the token limit (`max_session_tokens` in config, default 200k)
313
+ - Oldest turns are summarized into a compact system note; latest turns preserved
314
+ - Each session shows token usage at the end of every turn
315
+
316
+ **Flags:**
317
+
318
+ | Flag | Description |
319
+ |------|-------------|
320
+ | `--new` | Start a fresh session (discard previous context) |
321
+ | `--list`, `-l` | List all sessions with turn/token counts |
322
+ | `--show <id>` | View a session's transcript |
323
+ | `--compact`, `-c` | Manually trigger compaction |
324
+
243
325
  ### `ctx capsule <query>` — Generate context capsule
244
326
 
245
327
  Generate a token-efficient DSL capsule for use with any AI tool.
@@ -379,6 +461,23 @@ branching = "prefer early returns over nested if-else"
379
461
 
380
462
  Now it appears in `ctx skill list` and can be activated with `--skill my-team-rules`.
381
463
 
464
+ **Skill template:**
465
+
466
+ `ctx init` ships a fully-commented skill template at `.ctxgraph/skills/template.example.toml`. It shows every available section and their options:
467
+
468
+ ```toml
469
+ # .ctxgraph/skills/template.example.toml (commented reference)
470
+ #
471
+ # [about] — REQUIRED: name and description
472
+ # [rules] — REQUIRED: instruction key/value pairs
473
+ # [context] — OPTIONAL: file filters and limits
474
+ # [response] — OPTIONAL: output formatting controls
475
+ # [output] — OPTIONAL: save-to-file behavior
476
+ # [meta] — OPTIONAL: author, version, requirements
477
+ ```
478
+
479
+ To create a new skill, copy the file (remove `.example` from the name) and uncomment the sections you need.
480
+
382
481
  ### `ctx info` — Graph statistics
383
482
 
384
483
  ```bash
@@ -442,11 +541,18 @@ provider = "ollama" # ollama, claude, openai, azure, custom
442
541
  model = "qwen2.5-coder:7b"
443
542
  endpoint = "http://localhost:11434"
444
543
  api_key = ""
544
+ # For Azure provider, uncomment and set:
545
+ # azure_deployment = "my-gpt-4o-deployment"
546
+ # api_version = "2024-08-01-preview"
445
547
 
446
548
  [context]
447
549
  mode = "balanced"
448
550
  max_nodes = 20
449
551
  max_depth = 2
552
+
553
+ [chat]
554
+ # Max tokens per chat session before auto-compact
555
+ max_session_tokens = 200000
450
556
  ```
451
557
 
452
558
  ### Environment variables
@@ -459,6 +565,8 @@ max_depth = 2
459
565
  | `ANTHROPIC_API_KEY` | `ai.api_key` | Claude provider |
460
566
  | `OPENAI_API_KEY` | `ai.api_key` | OpenAI provider |
461
567
  | `AZURE_OPENAI_API_KEY` | `ai.api_key` | Azure provider |
568
+ | `AZURE_OPENAI_DEPLOYMENT` | `ai.azure_deployment` | Azure deployment name |
569
+ | `AZURE_OPENAI_API_VERSION` | `ai.api_version` | Azure API version |
462
570
 
463
571
  ### Provider examples
464
572
 
@@ -473,11 +581,16 @@ CTXGRAPH_PROVIDER=claude CTXGRAPH_MODEL=claude-sonnet-4-20250514 ctx ask "explai
473
581
  CTXGRAPH_PROVIDER=openai CTXGRAPH_MODEL=gpt-4o ctx ask "find the bug"
474
582
 
475
583
  # Azure OpenAI
584
+ # Uses `api-key` header (not Bearer), requires `azure_deployment` and `api_version`
476
585
  CTXGRAPH_PROVIDER=azure \
477
586
  CTXGRAPH_MODEL=gpt-4o \
478
587
  CTXGRAPH_ENDPOINT=https://my-resource.openai.azure.com \
479
588
  AZURE_OPENAI_API_KEY=sk-... \
589
+ AZURE_OPENAI_DEPLOYMENT=my-gpt-4o-deployment \
590
+ AZURE_OPENAI_API_VERSION=2024-08-01-preview \
480
591
  ctx ask "refactor this"
592
+ # The endpoint is your resource URL. The chat URL becomes:
593
+ # /openai/deployments/{azure_deployment}/chat/completions?api-version={api_version}
481
594
 
482
595
  # Custom (OpenAI-compatible)
483
596
  CTXGRAPH_PROVIDER=custom CTXGRAPH_ENDPOINT=http://my-api/v1 ctx ask "explain"
@@ -598,7 +711,7 @@ from ctxgraph.capsule.savings import compute_savings
598
711
 
599
712
  savings = compute_savings(Path("./my_project"), capsule_text)
600
713
  print(f"Saved {savings['savings_pct']}% tokens")
601
- print(f"DSL is {savings['dsl_vs_json']}% more efficient than JSON")
714
+ print(f"DSL is {savings['dsl_vs_json_pct']}% more efficient than JSON")
602
715
  ```
603
716
 
604
717
  ### LangChain
@@ -762,6 +875,7 @@ src/ctxgraph/
762
875
  │ ├── init.py — Project scaffold (.ctxgraph dir)
763
876
  │ ├── settings.py — TOML/JSON/env config loading
764
877
  │ └── providers.py — Ollama, Claude, OpenAI clients
878
+ ├── chat.py — Chat session management (multi-turn, compaction)
765
879
  ├── clients/models.py — Mode enum (fast/balanced/deep)
766
880
  ├── exclude/patterns.py — Exclusion pattern matching
767
881
  ├── view/visualizer.py — D3.js HTML graph generator
@@ -770,7 +884,8 @@ src/ctxgraph/
770
884
  ├── skills/
771
885
  │ ├── __init__.py — Skill discovery + loading
772
886
  │ ├── project-style.toml — Default skill: project conventions
773
- └── field-guide.toml — Default skill: field guide
887
+ ├── field-guide.toml — Default skill: field guide
888
+ │ └── template.example.toml — Commented skill template reference
774
889
  └── history.py — JSONL history append/query/stats
775
890
  ```
776
891