ctxgraph 0.3.2__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.2/src/ctxgraph.egg-info → ctxgraph-0.4.0}/PKG-INFO +117 -4
  2. ctxgraph-0.3.2/PKG-INFO → ctxgraph-0.4.0/README.md +876 -792
  3. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/pyproject.toml +4 -1
  4. {ctxgraph-0.3.2 → 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.2 → ctxgraph-0.4.0}/src/ctxgraph/cli/main.py +239 -3
  7. {ctxgraph-0.3.2 → 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.2/README.md → ctxgraph-0.4.0/src/ctxgraph.egg-info/PKG-INFO +905 -763
  12. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph.egg-info/SOURCES.txt +4 -0
  13. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/tests/test_config.py +68 -0
  14. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/tests/test_e2e.py +82 -4
  15. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/setup.cfg +0 -0
  16. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/__init__.py +0 -0
  17. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/analyzers/__init__.py +0 -0
  18. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/analyzers/python/__init__.py +0 -0
  19. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/analyzers/python/importer.py +0 -0
  20. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/analyzers/python/semantic.py +0 -0
  21. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/analyzers/python/symbols.py +0 -0
  22. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/capsule/__init__.py +0 -0
  23. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/capsule/renderer.py +0 -0
  24. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/cli/__init__.py +0 -0
  25. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/clients/__init__.py +0 -0
  26. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/clients/models.py +0 -0
  27. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/config/__init__.py +0 -0
  28. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/config/init.py +0 -0
  29. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/config/providers.py +0 -0
  30. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/exclude/__init__.py +0 -0
  31. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/exclude/patterns.py +0 -0
  32. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/graph/__init__.py +0 -0
  33. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/graph/builder.py +0 -0
  34. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/graph/models.py +0 -0
  35. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/graph/query.py +0 -0
  36. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/graph/storage.py +0 -0
  37. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/history.py +0 -0
  38. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/mcp/__init__.py +0 -0
  39. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/mcp/server.py +0 -0
  40. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/skills/__init__.py +0 -0
  41. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/view/__init__.py +0 -0
  42. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/view/visualizer.py +0 -0
  43. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/wrapper/__init__.py +0 -0
  44. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph/wrapper/claude.py +0 -0
  45. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph.egg-info/dependency_links.txt +0 -0
  46. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph.egg-info/entry_points.txt +0 -0
  47. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph.egg-info/requires.txt +0 -0
  48. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/src/ctxgraph.egg-info/top_level.txt +0 -0
  49. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/tests/test_analyzers.py +0 -0
  50. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/tests/test_benchmark.py +0 -0
  51. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/tests/test_capsule.py +0 -0
  52. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/tests/test_integration.py +0 -0
  53. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/tests/test_model_mode.py +0 -0
  54. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/tests/test_models.py +0 -0
  55. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/tests/test_query.py +0 -0
  56. {ctxgraph-0.3.2 → ctxgraph-0.4.0}/tests/test_storage.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ctxgraph
3
- Version: 0.3.2
3
+ Version: 0.4.0
4
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
@@ -38,6 +38,7 @@ ctx init # Scaffold .ctxgraph with config + default sk
38
38
  ctx build # Build knowledge graph (AST analysis → SQLite)
39
39
  ctx ask "how does JWT auth work" # Ask questions with automatic token savings
40
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
41
42
  ctx history --stats # Track total tokens saved across all queries
42
43
  ccg "fix the login redirect bug" # Launch Claude with context pre-loaded
43
44
  ctx view # Interactive D3.js visualization (or --svg for static)
@@ -157,7 +158,7 @@ ctx capsule "user authentication" --savings
157
158
  # └──────────────────────────┴──────────────┘
158
159
  ```
159
160
 
160
- `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.
161
162
 
162
163
  ---
163
164
 
@@ -242,6 +243,85 @@ and returns a formatted greeting string. The `Greeter` class extends this with a
242
243
  prefix. Both use type hints and follow the project conventions.
243
244
  ```
244
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
+
245
325
  ### `ctx capsule <query>` — Generate context capsule
246
326
 
247
327
  Generate a token-efficient DSL capsule for use with any AI tool.
@@ -381,6 +461,23 @@ branching = "prefer early returns over nested if-else"
381
461
 
382
462
  Now it appears in `ctx skill list` and can be activated with `--skill my-team-rules`.
383
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
+
384
481
  ### `ctx info` — Graph statistics
385
482
 
386
483
  ```bash
@@ -444,11 +541,18 @@ provider = "ollama" # ollama, claude, openai, azure, custom
444
541
  model = "qwen2.5-coder:7b"
445
542
  endpoint = "http://localhost:11434"
446
543
  api_key = ""
544
+ # For Azure provider, uncomment and set:
545
+ # azure_deployment = "my-gpt-4o-deployment"
546
+ # api_version = "2024-08-01-preview"
447
547
 
448
548
  [context]
449
549
  mode = "balanced"
450
550
  max_nodes = 20
451
551
  max_depth = 2
552
+
553
+ [chat]
554
+ # Max tokens per chat session before auto-compact
555
+ max_session_tokens = 200000
452
556
  ```
453
557
 
454
558
  ### Environment variables
@@ -461,6 +565,8 @@ max_depth = 2
461
565
  | `ANTHROPIC_API_KEY` | `ai.api_key` | Claude provider |
462
566
  | `OPENAI_API_KEY` | `ai.api_key` | OpenAI provider |
463
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 |
464
570
 
465
571
  ### Provider examples
466
572
 
@@ -475,11 +581,16 @@ CTXGRAPH_PROVIDER=claude CTXGRAPH_MODEL=claude-sonnet-4-20250514 ctx ask "explai
475
581
  CTXGRAPH_PROVIDER=openai CTXGRAPH_MODEL=gpt-4o ctx ask "find the bug"
476
582
 
477
583
  # Azure OpenAI
584
+ # Uses `api-key` header (not Bearer), requires `azure_deployment` and `api_version`
478
585
  CTXGRAPH_PROVIDER=azure \
479
586
  CTXGRAPH_MODEL=gpt-4o \
480
587
  CTXGRAPH_ENDPOINT=https://my-resource.openai.azure.com \
481
588
  AZURE_OPENAI_API_KEY=sk-... \
589
+ AZURE_OPENAI_DEPLOYMENT=my-gpt-4o-deployment \
590
+ AZURE_OPENAI_API_VERSION=2024-08-01-preview \
482
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}
483
594
 
484
595
  # Custom (OpenAI-compatible)
485
596
  CTXGRAPH_PROVIDER=custom CTXGRAPH_ENDPOINT=http://my-api/v1 ctx ask "explain"
@@ -600,7 +711,7 @@ from ctxgraph.capsule.savings import compute_savings
600
711
 
601
712
  savings = compute_savings(Path("./my_project"), capsule_text)
602
713
  print(f"Saved {savings['savings_pct']}% tokens")
603
- 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")
604
715
  ```
605
716
 
606
717
  ### LangChain
@@ -764,6 +875,7 @@ src/ctxgraph/
764
875
  │ ├── init.py — Project scaffold (.ctxgraph dir)
765
876
  │ ├── settings.py — TOML/JSON/env config loading
766
877
  │ └── providers.py — Ollama, Claude, OpenAI clients
878
+ ├── chat.py — Chat session management (multi-turn, compaction)
767
879
  ├── clients/models.py — Mode enum (fast/balanced/deep)
768
880
  ├── exclude/patterns.py — Exclusion pattern matching
769
881
  ├── view/visualizer.py — D3.js HTML graph generator
@@ -772,7 +884,8 @@ src/ctxgraph/
772
884
  ├── skills/
773
885
  │ ├── __init__.py — Skill discovery + loading
774
886
  │ ├── project-style.toml — Default skill: project conventions
775
- └── field-guide.toml — Default skill: field guide
887
+ ├── field-guide.toml — Default skill: field guide
888
+ │ └── template.example.toml — Commented skill template reference
776
889
  └── history.py — JSONL history append/query/stats
777
890
  ```
778
891