crispllm 1.1.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 (34) hide show
  1. crispllm-1.1.0/PKG-INFO +317 -0
  2. crispllm-1.1.0/README.md +275 -0
  3. crispllm-1.1.0/pyproject.toml +77 -0
  4. crispllm-1.1.0/pyproject.toml.orig +76 -0
  5. crispllm-1.1.0/src/crispllm/__init__.py +9 -0
  6. crispllm-1.1.0/src/crispllm/cli.py +588 -0
  7. crispllm-1.1.0/src/crispllm/config.py +629 -0
  8. crispllm-1.1.0/src/crispllm/memory/__init__.py +21 -0
  9. crispllm-1.1.0/src/crispllm/memory/consolidator.py +452 -0
  10. crispllm-1.1.0/src/crispllm/memory/extractor.py +321 -0
  11. crispllm-1.1.0/src/crispllm/memory/store.py +775 -0
  12. crispllm-1.1.0/src/crispllm/privacy/__init__.py +23 -0
  13. crispllm-1.1.0/src/crispllm/privacy/redactor.py +351 -0
  14. crispllm-1.1.0/src/crispllm/privacy/stream_restorer.py +83 -0
  15. crispllm-1.1.0/src/crispllm/proxy/__init__.py +0 -0
  16. crispllm-1.1.0/src/crispllm/proxy/app.py +1166 -0
  17. crispllm-1.1.0/src/crispllm/proxy/auth.py +122 -0
  18. crispllm-1.1.0/src/crispllm/proxy/budgeter.py +164 -0
  19. crispllm-1.1.0/src/crispllm/proxy/classifier.py +128 -0
  20. crispllm-1.1.0/src/crispllm/proxy/mcp_server.py +413 -0
  21. crispllm-1.1.0/src/crispllm/proxy/middleware.py +570 -0
  22. crispllm-1.1.0/src/crispllm/proxy/router.py +237 -0
  23. crispllm-1.1.0/src/crispllm/proxy/speculative.py +489 -0
  24. crispllm-1.1.0/src/crispllm/proxy/streaming.py +236 -0
  25. crispllm-1.1.0/src/crispllm/proxy/sysinfo.py +250 -0
  26. crispllm-1.1.0/src/crispllm/proxy/telemetry.py +323 -0
  27. crispllm-1.1.0/src/crispllm/proxy/unloader.py +114 -0
  28. crispllm-1.1.0/src/crispllm/proxy/watchdog.py +105 -0
  29. crispllm-1.1.0/src/crispllm/slicer/__init__.py +34 -0
  30. crispllm-1.1.0/src/crispllm/slicer/cache.py +579 -0
  31. crispllm-1.1.0/src/crispllm/slicer/pagerank.py +294 -0
  32. crispllm-1.1.0/src/crispllm/slicer/repomap.py +778 -0
  33. crispllm-1.1.0/src/crispllm/slicer/symbols.py +419 -0
  34. crispllm-1.1.0/src/crispllm/slicer/tags.py +431 -0
@@ -0,0 +1,317 @@
1
+ Metadata-Version: 2.4
2
+ Name: crispllm
3
+ Version: 1.1.0
4
+ Summary: Lightweight unified memory & context proxy for AI coding on weak hardware
5
+ Keywords: llm,memory,proxy,local-llm,ast-slicing,speculative-decoding,mcp,llama-cpp
6
+ Author: Dhanush Veerla
7
+ Author-email: Dhanush Veerla <dhanushveerla@gmail.com>
8
+ License-Expression: MIT
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Classifier: Operating System :: MacOS
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Dist: click>=8.1.0
22
+ Requires-Dist: fastapi>=0.165.0
23
+ Requires-Dist: grep-ast>=0.9.0
24
+ Requires-Dist: httpx>=0.28.1
25
+ Requires-Dist: mcp>=2.3.0
26
+ Requires-Dist: networkx>=3.6.1
27
+ Requires-Dist: platformdirs>=4.14.7
28
+ Requires-Dist: psutil>=7.2.2
29
+ Requires-Dist: pydantic>=2.0
30
+ Requires-Dist: pydantic-settings>=2.16.3
31
+ Requires-Dist: tiktoken>=0.14.0
32
+ Requires-Dist: tomli-w>=1.2.0
33
+ Requires-Dist: tree-sitter-language-pack>=1.25.2
34
+ Requires-Dist: uvicorn>=0.54.0
35
+ Requires-Python: >=3.11
36
+ Project-URL: Homepage, https://github.com/dhanushveerla/crispllm
37
+ Project-URL: Repository, https://github.com/dhanushveerla/crispllm
38
+ Project-URL: Documentation, https://github.com/dhanushveerla/crispllm#readme
39
+ Project-URL: Bug Tracker, https://github.com/dhanushveerla/crispllm/issues
40
+ Project-URL: Changelog, https://github.com/dhanushveerla/crispllm/blob/master/CHANGELOG.md
41
+ Description-Content-Type: text/markdown
42
+
43
+ # CrispLLM
44
+
45
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
46
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
47
+ [![CI](https://github.com/dhanushveerla/crispllm/actions/workflows/ci.yml/badge.svg)](https://github.com/dhanushveerla/crispllm/actions/workflows/ci.yml)
48
+ [![PyPI version](https://img.shields.io/badge/pypi-v1.1.0-orange.svg)](https://pypi.org/project/crispllm/)
49
+
50
+ > **Local-first LLM memory, AST slicing, RAM-aware routing, and speculative decoding proxy built for 8 GB laptops (Linux, macOS, Windows).**
51
+
52
+ CrispLLM is a lightweight, zero-bloat OpenAI-compatible `/v1` proxy and Model Context Protocol (MCP) server. It equips local coding models (`llama-server`, Ollama, vLLM) and cloud APIs with tiered architectural memory, 1-hop AST symbol slicing, dynamic context budgeting, and speculative acceleration — maintaining a **steady-state proxy RSS under 85 MB with zero vector databases, zero embedding models, and zero extra LLM calls** on the request hot path.
53
+
54
+ ---
55
+
56
+ ## Quickstart (60 Seconds)
57
+
58
+ ### 1. Installation
59
+
60
+ ```bash
61
+ # Run instantly with uvx (no install needed):
62
+ uvx crispllm --help
63
+
64
+ # Or install via pip / uv:
65
+ pip install crispllm
66
+ # or: uv pip install crispllm
67
+ ```
68
+
69
+ <details>
70
+ <summary>Source installation from git</summary>
71
+
72
+ ```bash
73
+ git clone https://github.com/dhanushveerla/crispllm.git
74
+ cd crispllm
75
+ uv sync
76
+ uv run pytest -q
77
+ ```
78
+ </details>
79
+
80
+ ### 2. Initialize and Start
81
+
82
+ ```bash
83
+ # Generate default crispllm.toml in current directory or ~/.config/crispllm/
84
+ crispllm init
85
+
86
+ # Start proxy on http://127.0.0.1:8080 (OpenAI /v1 proxy + Streamable HTTP /mcp server)
87
+ crispllm serve
88
+ ```
89
+
90
+ ### 3. Connect Any Client
91
+
92
+ **Python (OpenAI SDK):**
93
+ ```python
94
+ from openai import OpenAI
95
+
96
+ client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="sk-local")
97
+ response = client.chat.completions.create(
98
+ model="crispllm-local",
99
+ messages=[{"role": "user", "content": "Explain calculate_settlement in ledger/calculator.py"}],
100
+ )
101
+ print(response.choices[0].message.content)
102
+ ```
103
+
104
+ **Cursor / Windsurf / Continue:**
105
+ - Override OpenAI Base URL: `http://127.0.0.1:8080/v1`
106
+ - API Key: `sk-local` (or any string)
107
+ - Model: `crispllm-local` (or your local model name)
108
+
109
+ ---
110
+
111
+ ## Architecture
112
+
113
+ ```mermaid
114
+ flowchart LR
115
+ Client["Client<br/>(Cursor / Agent / SDK)"]
116
+
117
+ subgraph CrispLLMProxy ["CrispLLM Proxy (:8080) — &lt; 85 MB RSS"]
118
+ direction TB
119
+ Slicer["1-Hop AST Slicer<br/>(Tree-sitter PageRank + Call Graph)"]
120
+ Memory["3-Tier SQLite Memory<br/>(Core + Episodic + Archival FTS5)"]
121
+ Assembler["Prefix-Stable Prompt Assembler<br/>(Byte-stable Core + User Episodic)"]
122
+ WatchdogRouter["RAM Watchdog &amp; Task Router<br/>(ContextBudgeter + fast/balanced/deep)"]
123
+ Speculative["Speculative Layer<br/>(Cloud Predictions + llama-server Presets)"]
124
+ Redactor["Reversible Secret Redactor<br/>(Zero-leak gate + SSE Stream Restorer)"]
125
+ end
126
+
127
+ LocalRuntime["Local Runtime<br/>(llama-server / Ollama)"]
128
+ CloudRuntime["Cloud Fallback<br/>(OpenAI / OpenRouter / NIM)"]
129
+
130
+ Client -->|POST /v1/chat/completions| Slicer
131
+ Slicer --> Memory
132
+ Memory --> Assembler
133
+ Assembler --> WatchdogRouter
134
+ WatchdogRouter --> Speculative
135
+ Speculative -->|Local Fast Path| LocalRuntime
136
+ Speculative -->|Escalation / Fallback| Redactor
137
+ Redactor -->|Sanitized Prompt| CloudRuntime
138
+ LocalRuntime -->|Direct SSE Stream| Client
139
+ CloudRuntime -->|Restored Secret Stream| Client
140
+ ```
141
+
142
+ ---
143
+
144
+ ## Verified Hardware Benchmarks
145
+
146
+ All metrics measured empirically on physical test hardware using `bench/run_bench.py` and committed in `bench/baselines/` and `docs/ROADMAP.md`.
147
+
148
+ **Test Hardware Platform (Lenovo LOQ `83FQ`):**
149
+ - **CPU:** Intel Core i5-12450HX (8 cores / 12 threads)
150
+ - **Host RAM:** 7.7 GB usable DDR5
151
+ - **Discrete GPU:** Intel Arc A530M (4 GB VRAM)
152
+ - **Operating System:** Windows 11 Home 64-bit (build 26100)
153
+ - **Model Checkpoint:** `Qwen2.5-Coder-3B Q4_K_M` (GGUF)
154
+
155
+ ### Table 1: Memory Ceiling & Active RAM Reduction (Phase 1.1.2)
156
+
157
+ Target budget: total system peak RSS `<= 3.0 GB` on 8 GB laptops, keeping `>= 800 MB` free for OS and IDE buffers.
158
+
159
+ | Configuration | Execution Target | Context Window (`-c`) | Peak System RSS | Host RAM Left Free | CrispLLM Proxy RSS |
160
+ |---|---|---|---|---|---|
161
+ | Unbudgeted Baseline | CPU (Ollama unconstrained) | 8192 | 4,180.0 MB | ~3.5 GB (breached) | — |
162
+ | **T1-Budgeted (Watchdog + Bucketing)** | **2-Thread CPU** | **2048** | **2,129.7 MB** | **846.0 MB OS Free** | **80.4 MB** |
163
+ | **T2-Vulkan (Arc A530M Offload)** | **Arc A530M (Vulkan)** | **4096** | **2,174.2 MB** | **1.82 GB VRAM used** | **81.2 MB** |
164
+ | **Steady-State Idle (Post-Unload)** | **Background Worker** | — | **Baseline Restored** | **Fully Reclaimed (2.1s)** | **79.7 MB** |
165
+
166
+ ### Table 2: Prefix-Cache Multi-Turn TTFT & AST Slicing (Phase 1.1.3)
167
+
168
+ Multi-turn latency reduction via byte-stable system prompt ordering and 1-hop AST call-graph extraction.
169
+
170
+ | Measurement Dimension | Baseline Turn 1 | Cached Turn 2+ | Improvement / Delta | Cache Evidence |
171
+ |---|---|---|---|---|
172
+ | **T1-CPU Multi-Turn TTFT** | 2,441.0 ms | **800.2 ms** | **3.05x speedup (-67.2%)** | `cache_n` 139 -> 814 tokens |
173
+ | **T2-Vulkan Multi-Turn TTFT** | 2,469.5 ms | **773.4 ms** | **3.19x speedup (-68.7%)** | `cache_n` 139 -> 812 tokens (3/3 hits) |
174
+ | **1-Hop AST Slicer (`slice_symbol`)** | 240,660 tokens (full repo) | **800 tokens** (symbol slice) | **99.7% token reduction** | **47 ms warm lookup**, 0 false callees |
175
+
176
+ ### Table 3: Zero-RAM Local Speculative Decode (Phase 1.1.4)
177
+
178
+ Evaluation on `n=3` deterministic code-edit tasks (`temperature=0.0`, `max_tokens=512`) using current `llama-server` `b12631+` preset engine.
179
+
180
+ | Hardware Target | Preset Engine | Generation Speed | Wall-Clock Time | Wall Reduction | Draft Acceptance | Extra RAM |
181
+ |---|---|---|---|---|---|---|
182
+ | **T1-CPU (`-c 2048`)** | Baseline (`none`) | 11.64 tok/s | 36,670.2 ms | — | — | 0 MB |
183
+ | **T1-CPU (`-c 2048`)** | `ngram-simple` | **35.71 tok/s** | **13,234.0 ms** | **-63.9% (3.07x)** | **84.4%** (1,015 / 1,202) | **0 MB** |
184
+ | **T1-CPU (`-c 2048`)** | `ngram-mod` | 34.64 tok/s | 13,295.3 ms | -63.7% (2.98x) | 85.2% (982 / 1,152) | 16 MB |
185
+ | **T2-Vulkan (`Arc A530M`)** | Baseline (`none`) | 29.02 tok/s | 15,342.7 ms | — | — | 0 MB |
186
+ | **T2-Vulkan (`Arc A530M`)** | `ngram-simple` | **82.52 tok/s** | **6,264.5 ms** | **-59.2% (2.84x)** | **84.3%** (1,001 / 1,188) | **0 MB** |
187
+ | **T2-Vulkan (`Arc A530M`)** | `ngram-mod` | 77.30 tok/s | 6,574.7 ms | -57.1% (2.66x) | 85.0% (963 / 1,133) | 16 MB |
188
+
189
+ *Reproduce via:* `python bench/run_bench.py --tasks-file bench/stress_tasks.json --dry-run` or generate optimized llama.cpp server commands with `crispllm llama-cmd --profile t2-vulkan --preset ngram-simple`.
190
+
191
+ ---
192
+
193
+ ## Core Capabilities
194
+
195
+ | Capability | Module | Description | Technical Implementation |
196
+ |---|---|---|---|
197
+ | **Synthetic Memory** | `crispllm.memory` | Tiered memory hierarchy: Core (pinned invariants), Episodic (recency decay), and Archival. | SQLite WAL mode, BM25 FTS5 indexing, salience-decay pruning, async consolidation worker. |
198
+ | **RAM Watchdog** | `crispllm.proxy.watchdog` | 3-OS memory watchdog (`normal`, `soft`, `hard`) capping local context before OOM occurs. | Native `/proc/meminfo` (Linux), `sysctl` (macOS), Win32 `GlobalMemoryStatusEx` (Windows). |
199
+ | **ContextBudgeter** | `crispllm.proxy.budgeter` | Unified ADR-03 dynamic context window controller. | Bucketed `num_ctx` (`[2048, 4096, 8192]`) with derived prompt escalation threshold. |
200
+ | **1-Hop AST Slicing** | `crispllm.slicer` | Focuses code context on a target symbol, its callers, and its imported callees. | Tree-sitter AST parsing, NetworkX call graphs, `mtime`-cached symbols, generic callee pruning. |
201
+ | **Task-Tier Routing** | `crispllm.proxy.classifier` | Zero-LLM heuristic classification into `fast`, `balanced`, or `deep`. | Regex syntax diff/traceback checks, context length thresholds (< 0.1 ms latency, 0 LLM calls). |
202
+ | **Speculative Decoding** | `crispllm.proxy.speculative` | Accelerates code edits locally and via cloud predicted outputs. | Cloud Predicted Outputs + fail-open circuit breaker; llama.cpp `ngram-simple` / `draft` presets. |
203
+ | **Reversible Redactor** | `crispllm.privacy` | Deterministic secret & PII masking gate. | High-entropy regex masking before cloud dispatch; live SSE stream chunk placeholder restoration. |
204
+ | **Model Context Protocol** | `crispllm.proxy.mcp_server` | Streamable HTTP MCP server at `/mcp`. | Exposes `crispllm_remember`, `crispllm_recall`, `crispllm_repo_map` (with `focus_symbol`). |
205
+
206
+ ---
207
+
208
+ ## Honest Limitations
209
+
210
+ CrispLLM is engineered specifically for local execution on resource-constrained devices. By design, it makes deliberate engineering trade-offs:
211
+ - **No Dense Vector Databases or Embedding Models:** CrispLLM does not run background embedding models or vector databases. Retrieval relies on exact-match AST symbol graphs and deterministic SQLite FTS5 BM25 search.
212
+ - **Zero-LLM Heuristic Classification:** Request task tiers (`fast`, `balanced`, `deep`) are assigned via deterministic lexical heuristics in < 0.1 ms. While fast and zero-cost, heuristics cannot infer semantic intent on ambiguous, unformatted user turns.
213
+ - **Speculative Decoding Scope:** The zero-RAM `ngram-simple` preset accelerates repetitive syntax, boilerplate, and code edits (84%+ draft acceptance). For open-ended creative writing or novel greenfield prose, draft acceptance decreases.
214
+ - **Cloud Predicted Outputs Availability:** Cloud predicted outputs require a supporting provider endpoint (e.g. OpenAI). When a provider rejects prediction parameters with HTTP 400/422, CrispLLM automatically fails open, strips the prediction payload, and retries the request without failing the user turn.
215
+
216
+ ---
217
+
218
+ ## Configuration & References
219
+
220
+ <details>
221
+ <summary><b>Configuration Reference (crispllm.toml)</b></summary>
222
+
223
+ ```toml
224
+ [proxy]
225
+ host = "127.0.0.1"
226
+ port = 8080
227
+ auth_token = "sk-local"
228
+ cors_origins = ["*"]
229
+
230
+ [memory]
231
+ enabled = true
232
+ db_path = ".crispllm/memory.db"
233
+ max_injected_tokens = 500
234
+ inject_constraints = true
235
+ compact_middle_turns = true
236
+ compact_min_turn_tokens = 40
237
+ keep_recent_turns = 2
238
+ auto_extract = true
239
+
240
+ [resources]
241
+ enabled = true
242
+ local_backend = "llama_server" # "llama_server" or "ollama"
243
+ ram_threshold_soft_mb = 1024.0
244
+ ram_threshold_hard_mb = 512.0
245
+ watchdog_poll_s = 2.0
246
+ ctx_buckets = [2048, 4096, 8192]
247
+ max_local_ctx = 8192
248
+ idle_unload_s = 300.0
249
+
250
+ [speculative]
251
+ predicted_outputs_enabled = true
252
+ min_prediction_chars = 40
253
+ max_prediction_chars = 30000
254
+ min_prediction_lines = 3
255
+ llama_preset = "ngram-simple"
256
+ draft_model_path = ""
257
+
258
+ [router]
259
+ local_base_url = "http://127.0.0.1:8081/v1"
260
+ local_model = "Qwen2.5-Coder-3B"
261
+ cloud_base_url = "https://api.openai.com/v1"
262
+ cloud_model = "gpt-4o"
263
+ cloud_api_key_env = "OPENAI_API_KEY"
264
+
265
+ [privacy]
266
+ enabled = true
267
+ redact_secrets = true
268
+ redact_emails = true
269
+ redact_ips = false
270
+ ```
271
+ </details>
272
+
273
+ <details>
274
+ <summary><b>CLI Command Reference</b></summary>
275
+
276
+ CrispLLM provides a unified command-line interface:
277
+
278
+ - `crispllm init`: Create an annotated `crispllm.toml` configuration file.
279
+ - `crispllm serve [--host HOST] [--port PORT]`: Start the proxy and MCP server.
280
+ - `crispllm status`: Inspect proxy status, memory fact counts, watchdog pressure, and cache telemetry.
281
+ - `crispllm slice PATH [--symbol SYMBOL] [--tokens TOKENS]`: Generate an AST repository map or 1-hop symbol slice.
282
+ - `crispllm llama-cmd --model PATH [--profile t1-cpu|t2-vulkan|t2-gpu] [--preset ngram-simple|ngram-mod|draft]`: Build an optimized `llama-server` execution command.
283
+ - `crispllm memory list [--session ID] [--kind constraint|constant|file|note]`: List stored synthetic facts.
284
+ - `crispllm memory search QUERY`: Search stored facts using SQLite BM25 FTS5.
285
+ - `crispllm memory delete KEY [--session ID]`: Delete or supersede a memory entry.
286
+ - `crispllm memory clear [--session ID]`: Clear session or global memory records.
287
+ - `crispllm doctor`: Check system environment, Tree-sitter parsers, SQLite FTS5 support, and hardware specs.
288
+ </details>
289
+
290
+ <details>
291
+ <summary><b>MCP Client Configuration</b></summary>
292
+
293
+ Add CrispLLM as an MCP server in your client configuration:
294
+
295
+ **Claude Desktop (`claude_desktop_config.json`):**
296
+ ```json
297
+ {
298
+ "mcpServers": {
299
+ "crispllm": {
300
+ "command": "uvx",
301
+ "args": ["crispllm", "serve"]
302
+ }
303
+ }
304
+ }
305
+ ```
306
+
307
+ **Remote / Streamable HTTP MCP (Cursor, Continue, Claude Code):**
308
+ - **Transport:** Streamable HTTP (SSE)
309
+ - **URL:** `http://127.0.0.1:8080/mcp`
310
+ - **Headers:** `{"Authorization": "Bearer sk-local"}`
311
+ </details>
312
+
313
+ ---
314
+
315
+ ## License
316
+
317
+ CrispLLM is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,275 @@
1
+ # CrispLLM
2
+
3
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
5
+ [![CI](https://github.com/dhanushveerla/crispllm/actions/workflows/ci.yml/badge.svg)](https://github.com/dhanushveerla/crispllm/actions/workflows/ci.yml)
6
+ [![PyPI version](https://img.shields.io/badge/pypi-v1.1.0-orange.svg)](https://pypi.org/project/crispllm/)
7
+
8
+ > **Local-first LLM memory, AST slicing, RAM-aware routing, and speculative decoding proxy built for 8 GB laptops (Linux, macOS, Windows).**
9
+
10
+ CrispLLM is a lightweight, zero-bloat OpenAI-compatible `/v1` proxy and Model Context Protocol (MCP) server. It equips local coding models (`llama-server`, Ollama, vLLM) and cloud APIs with tiered architectural memory, 1-hop AST symbol slicing, dynamic context budgeting, and speculative acceleration — maintaining a **steady-state proxy RSS under 85 MB with zero vector databases, zero embedding models, and zero extra LLM calls** on the request hot path.
11
+
12
+ ---
13
+
14
+ ## Quickstart (60 Seconds)
15
+
16
+ ### 1. Installation
17
+
18
+ ```bash
19
+ # Run instantly with uvx (no install needed):
20
+ uvx crispllm --help
21
+
22
+ # Or install via pip / uv:
23
+ pip install crispllm
24
+ # or: uv pip install crispllm
25
+ ```
26
+
27
+ <details>
28
+ <summary>Source installation from git</summary>
29
+
30
+ ```bash
31
+ git clone https://github.com/dhanushveerla/crispllm.git
32
+ cd crispllm
33
+ uv sync
34
+ uv run pytest -q
35
+ ```
36
+ </details>
37
+
38
+ ### 2. Initialize and Start
39
+
40
+ ```bash
41
+ # Generate default crispllm.toml in current directory or ~/.config/crispllm/
42
+ crispllm init
43
+
44
+ # Start proxy on http://127.0.0.1:8080 (OpenAI /v1 proxy + Streamable HTTP /mcp server)
45
+ crispllm serve
46
+ ```
47
+
48
+ ### 3. Connect Any Client
49
+
50
+ **Python (OpenAI SDK):**
51
+ ```python
52
+ from openai import OpenAI
53
+
54
+ client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="sk-local")
55
+ response = client.chat.completions.create(
56
+ model="crispllm-local",
57
+ messages=[{"role": "user", "content": "Explain calculate_settlement in ledger/calculator.py"}],
58
+ )
59
+ print(response.choices[0].message.content)
60
+ ```
61
+
62
+ **Cursor / Windsurf / Continue:**
63
+ - Override OpenAI Base URL: `http://127.0.0.1:8080/v1`
64
+ - API Key: `sk-local` (or any string)
65
+ - Model: `crispllm-local` (or your local model name)
66
+
67
+ ---
68
+
69
+ ## Architecture
70
+
71
+ ```mermaid
72
+ flowchart LR
73
+ Client["Client<br/>(Cursor / Agent / SDK)"]
74
+
75
+ subgraph CrispLLMProxy ["CrispLLM Proxy (:8080) — &lt; 85 MB RSS"]
76
+ direction TB
77
+ Slicer["1-Hop AST Slicer<br/>(Tree-sitter PageRank + Call Graph)"]
78
+ Memory["3-Tier SQLite Memory<br/>(Core + Episodic + Archival FTS5)"]
79
+ Assembler["Prefix-Stable Prompt Assembler<br/>(Byte-stable Core + User Episodic)"]
80
+ WatchdogRouter["RAM Watchdog &amp; Task Router<br/>(ContextBudgeter + fast/balanced/deep)"]
81
+ Speculative["Speculative Layer<br/>(Cloud Predictions + llama-server Presets)"]
82
+ Redactor["Reversible Secret Redactor<br/>(Zero-leak gate + SSE Stream Restorer)"]
83
+ end
84
+
85
+ LocalRuntime["Local Runtime<br/>(llama-server / Ollama)"]
86
+ CloudRuntime["Cloud Fallback<br/>(OpenAI / OpenRouter / NIM)"]
87
+
88
+ Client -->|POST /v1/chat/completions| Slicer
89
+ Slicer --> Memory
90
+ Memory --> Assembler
91
+ Assembler --> WatchdogRouter
92
+ WatchdogRouter --> Speculative
93
+ Speculative -->|Local Fast Path| LocalRuntime
94
+ Speculative -->|Escalation / Fallback| Redactor
95
+ Redactor -->|Sanitized Prompt| CloudRuntime
96
+ LocalRuntime -->|Direct SSE Stream| Client
97
+ CloudRuntime -->|Restored Secret Stream| Client
98
+ ```
99
+
100
+ ---
101
+
102
+ ## Verified Hardware Benchmarks
103
+
104
+ All metrics measured empirically on physical test hardware using `bench/run_bench.py` and committed in `bench/baselines/` and `docs/ROADMAP.md`.
105
+
106
+ **Test Hardware Platform (Lenovo LOQ `83FQ`):**
107
+ - **CPU:** Intel Core i5-12450HX (8 cores / 12 threads)
108
+ - **Host RAM:** 7.7 GB usable DDR5
109
+ - **Discrete GPU:** Intel Arc A530M (4 GB VRAM)
110
+ - **Operating System:** Windows 11 Home 64-bit (build 26100)
111
+ - **Model Checkpoint:** `Qwen2.5-Coder-3B Q4_K_M` (GGUF)
112
+
113
+ ### Table 1: Memory Ceiling & Active RAM Reduction (Phase 1.1.2)
114
+
115
+ Target budget: total system peak RSS `<= 3.0 GB` on 8 GB laptops, keeping `>= 800 MB` free for OS and IDE buffers.
116
+
117
+ | Configuration | Execution Target | Context Window (`-c`) | Peak System RSS | Host RAM Left Free | CrispLLM Proxy RSS |
118
+ |---|---|---|---|---|---|
119
+ | Unbudgeted Baseline | CPU (Ollama unconstrained) | 8192 | 4,180.0 MB | ~3.5 GB (breached) | — |
120
+ | **T1-Budgeted (Watchdog + Bucketing)** | **2-Thread CPU** | **2048** | **2,129.7 MB** | **846.0 MB OS Free** | **80.4 MB** |
121
+ | **T2-Vulkan (Arc A530M Offload)** | **Arc A530M (Vulkan)** | **4096** | **2,174.2 MB** | **1.82 GB VRAM used** | **81.2 MB** |
122
+ | **Steady-State Idle (Post-Unload)** | **Background Worker** | — | **Baseline Restored** | **Fully Reclaimed (2.1s)** | **79.7 MB** |
123
+
124
+ ### Table 2: Prefix-Cache Multi-Turn TTFT & AST Slicing (Phase 1.1.3)
125
+
126
+ Multi-turn latency reduction via byte-stable system prompt ordering and 1-hop AST call-graph extraction.
127
+
128
+ | Measurement Dimension | Baseline Turn 1 | Cached Turn 2+ | Improvement / Delta | Cache Evidence |
129
+ |---|---|---|---|---|
130
+ | **T1-CPU Multi-Turn TTFT** | 2,441.0 ms | **800.2 ms** | **3.05x speedup (-67.2%)** | `cache_n` 139 -> 814 tokens |
131
+ | **T2-Vulkan Multi-Turn TTFT** | 2,469.5 ms | **773.4 ms** | **3.19x speedup (-68.7%)** | `cache_n` 139 -> 812 tokens (3/3 hits) |
132
+ | **1-Hop AST Slicer (`slice_symbol`)** | 240,660 tokens (full repo) | **800 tokens** (symbol slice) | **99.7% token reduction** | **47 ms warm lookup**, 0 false callees |
133
+
134
+ ### Table 3: Zero-RAM Local Speculative Decode (Phase 1.1.4)
135
+
136
+ Evaluation on `n=3` deterministic code-edit tasks (`temperature=0.0`, `max_tokens=512`) using current `llama-server` `b12631+` preset engine.
137
+
138
+ | Hardware Target | Preset Engine | Generation Speed | Wall-Clock Time | Wall Reduction | Draft Acceptance | Extra RAM |
139
+ |---|---|---|---|---|---|---|
140
+ | **T1-CPU (`-c 2048`)** | Baseline (`none`) | 11.64 tok/s | 36,670.2 ms | — | — | 0 MB |
141
+ | **T1-CPU (`-c 2048`)** | `ngram-simple` | **35.71 tok/s** | **13,234.0 ms** | **-63.9% (3.07x)** | **84.4%** (1,015 / 1,202) | **0 MB** |
142
+ | **T1-CPU (`-c 2048`)** | `ngram-mod` | 34.64 tok/s | 13,295.3 ms | -63.7% (2.98x) | 85.2% (982 / 1,152) | 16 MB |
143
+ | **T2-Vulkan (`Arc A530M`)** | Baseline (`none`) | 29.02 tok/s | 15,342.7 ms | — | — | 0 MB |
144
+ | **T2-Vulkan (`Arc A530M`)** | `ngram-simple` | **82.52 tok/s** | **6,264.5 ms** | **-59.2% (2.84x)** | **84.3%** (1,001 / 1,188) | **0 MB** |
145
+ | **T2-Vulkan (`Arc A530M`)** | `ngram-mod` | 77.30 tok/s | 6,574.7 ms | -57.1% (2.66x) | 85.0% (963 / 1,133) | 16 MB |
146
+
147
+ *Reproduce via:* `python bench/run_bench.py --tasks-file bench/stress_tasks.json --dry-run` or generate optimized llama.cpp server commands with `crispllm llama-cmd --profile t2-vulkan --preset ngram-simple`.
148
+
149
+ ---
150
+
151
+ ## Core Capabilities
152
+
153
+ | Capability | Module | Description | Technical Implementation |
154
+ |---|---|---|---|
155
+ | **Synthetic Memory** | `crispllm.memory` | Tiered memory hierarchy: Core (pinned invariants), Episodic (recency decay), and Archival. | SQLite WAL mode, BM25 FTS5 indexing, salience-decay pruning, async consolidation worker. |
156
+ | **RAM Watchdog** | `crispllm.proxy.watchdog` | 3-OS memory watchdog (`normal`, `soft`, `hard`) capping local context before OOM occurs. | Native `/proc/meminfo` (Linux), `sysctl` (macOS), Win32 `GlobalMemoryStatusEx` (Windows). |
157
+ | **ContextBudgeter** | `crispllm.proxy.budgeter` | Unified ADR-03 dynamic context window controller. | Bucketed `num_ctx` (`[2048, 4096, 8192]`) with derived prompt escalation threshold. |
158
+ | **1-Hop AST Slicing** | `crispllm.slicer` | Focuses code context on a target symbol, its callers, and its imported callees. | Tree-sitter AST parsing, NetworkX call graphs, `mtime`-cached symbols, generic callee pruning. |
159
+ | **Task-Tier Routing** | `crispllm.proxy.classifier` | Zero-LLM heuristic classification into `fast`, `balanced`, or `deep`. | Regex syntax diff/traceback checks, context length thresholds (< 0.1 ms latency, 0 LLM calls). |
160
+ | **Speculative Decoding** | `crispllm.proxy.speculative` | Accelerates code edits locally and via cloud predicted outputs. | Cloud Predicted Outputs + fail-open circuit breaker; llama.cpp `ngram-simple` / `draft` presets. |
161
+ | **Reversible Redactor** | `crispllm.privacy` | Deterministic secret & PII masking gate. | High-entropy regex masking before cloud dispatch; live SSE stream chunk placeholder restoration. |
162
+ | **Model Context Protocol** | `crispllm.proxy.mcp_server` | Streamable HTTP MCP server at `/mcp`. | Exposes `crispllm_remember`, `crispllm_recall`, `crispllm_repo_map` (with `focus_symbol`). |
163
+
164
+ ---
165
+
166
+ ## Honest Limitations
167
+
168
+ CrispLLM is engineered specifically for local execution on resource-constrained devices. By design, it makes deliberate engineering trade-offs:
169
+ - **No Dense Vector Databases or Embedding Models:** CrispLLM does not run background embedding models or vector databases. Retrieval relies on exact-match AST symbol graphs and deterministic SQLite FTS5 BM25 search.
170
+ - **Zero-LLM Heuristic Classification:** Request task tiers (`fast`, `balanced`, `deep`) are assigned via deterministic lexical heuristics in < 0.1 ms. While fast and zero-cost, heuristics cannot infer semantic intent on ambiguous, unformatted user turns.
171
+ - **Speculative Decoding Scope:** The zero-RAM `ngram-simple` preset accelerates repetitive syntax, boilerplate, and code edits (84%+ draft acceptance). For open-ended creative writing or novel greenfield prose, draft acceptance decreases.
172
+ - **Cloud Predicted Outputs Availability:** Cloud predicted outputs require a supporting provider endpoint (e.g. OpenAI). When a provider rejects prediction parameters with HTTP 400/422, CrispLLM automatically fails open, strips the prediction payload, and retries the request without failing the user turn.
173
+
174
+ ---
175
+
176
+ ## Configuration & References
177
+
178
+ <details>
179
+ <summary><b>Configuration Reference (crispllm.toml)</b></summary>
180
+
181
+ ```toml
182
+ [proxy]
183
+ host = "127.0.0.1"
184
+ port = 8080
185
+ auth_token = "sk-local"
186
+ cors_origins = ["*"]
187
+
188
+ [memory]
189
+ enabled = true
190
+ db_path = ".crispllm/memory.db"
191
+ max_injected_tokens = 500
192
+ inject_constraints = true
193
+ compact_middle_turns = true
194
+ compact_min_turn_tokens = 40
195
+ keep_recent_turns = 2
196
+ auto_extract = true
197
+
198
+ [resources]
199
+ enabled = true
200
+ local_backend = "llama_server" # "llama_server" or "ollama"
201
+ ram_threshold_soft_mb = 1024.0
202
+ ram_threshold_hard_mb = 512.0
203
+ watchdog_poll_s = 2.0
204
+ ctx_buckets = [2048, 4096, 8192]
205
+ max_local_ctx = 8192
206
+ idle_unload_s = 300.0
207
+
208
+ [speculative]
209
+ predicted_outputs_enabled = true
210
+ min_prediction_chars = 40
211
+ max_prediction_chars = 30000
212
+ min_prediction_lines = 3
213
+ llama_preset = "ngram-simple"
214
+ draft_model_path = ""
215
+
216
+ [router]
217
+ local_base_url = "http://127.0.0.1:8081/v1"
218
+ local_model = "Qwen2.5-Coder-3B"
219
+ cloud_base_url = "https://api.openai.com/v1"
220
+ cloud_model = "gpt-4o"
221
+ cloud_api_key_env = "OPENAI_API_KEY"
222
+
223
+ [privacy]
224
+ enabled = true
225
+ redact_secrets = true
226
+ redact_emails = true
227
+ redact_ips = false
228
+ ```
229
+ </details>
230
+
231
+ <details>
232
+ <summary><b>CLI Command Reference</b></summary>
233
+
234
+ CrispLLM provides a unified command-line interface:
235
+
236
+ - `crispllm init`: Create an annotated `crispllm.toml` configuration file.
237
+ - `crispllm serve [--host HOST] [--port PORT]`: Start the proxy and MCP server.
238
+ - `crispllm status`: Inspect proxy status, memory fact counts, watchdog pressure, and cache telemetry.
239
+ - `crispllm slice PATH [--symbol SYMBOL] [--tokens TOKENS]`: Generate an AST repository map or 1-hop symbol slice.
240
+ - `crispllm llama-cmd --model PATH [--profile t1-cpu|t2-vulkan|t2-gpu] [--preset ngram-simple|ngram-mod|draft]`: Build an optimized `llama-server` execution command.
241
+ - `crispllm memory list [--session ID] [--kind constraint|constant|file|note]`: List stored synthetic facts.
242
+ - `crispllm memory search QUERY`: Search stored facts using SQLite BM25 FTS5.
243
+ - `crispllm memory delete KEY [--session ID]`: Delete or supersede a memory entry.
244
+ - `crispllm memory clear [--session ID]`: Clear session or global memory records.
245
+ - `crispllm doctor`: Check system environment, Tree-sitter parsers, SQLite FTS5 support, and hardware specs.
246
+ </details>
247
+
248
+ <details>
249
+ <summary><b>MCP Client Configuration</b></summary>
250
+
251
+ Add CrispLLM as an MCP server in your client configuration:
252
+
253
+ **Claude Desktop (`claude_desktop_config.json`):**
254
+ ```json
255
+ {
256
+ "mcpServers": {
257
+ "crispllm": {
258
+ "command": "uvx",
259
+ "args": ["crispllm", "serve"]
260
+ }
261
+ }
262
+ }
263
+ ```
264
+
265
+ **Remote / Streamable HTTP MCP (Cursor, Continue, Claude Code):**
266
+ - **Transport:** Streamable HTTP (SSE)
267
+ - **URL:** `http://127.0.0.1:8080/mcp`
268
+ - **Headers:** `{"Authorization": "Bearer sk-local"}`
269
+ </details>
270
+
271
+ ---
272
+
273
+ ## License
274
+
275
+ CrispLLM is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,77 @@
1
+ [project]
2
+ name = "crispllm"
3
+ version = "1.1.0"
4
+ description = "Lightweight unified memory & context proxy for AI coding on weak hardware"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ requires-python = ">=3.11"
8
+ keywords = [
9
+ "llm",
10
+ "memory",
11
+ "proxy",
12
+ "local-llm",
13
+ "ast-slicing",
14
+ "speculative-decoding",
15
+ "mcp",
16
+ "llama-cpp",
17
+ ]
18
+ classifiers = [
19
+ "Development Status :: 4 - Beta",
20
+ "Environment :: Console",
21
+ "Intended Audience :: Developers",
22
+ "Operating System :: OS Independent",
23
+ "Operating System :: Microsoft :: Windows",
24
+ "Operating System :: MacOS",
25
+ "Operating System :: POSIX :: Linux",
26
+ "Programming Language :: Python :: 3",
27
+ "Programming Language :: Python :: 3.11",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Programming Language :: Python :: 3.13",
30
+ "Topic :: Software Development :: Libraries :: Python Modules",
31
+ ]
32
+ dependencies = [
33
+ "click>=8.1.0",
34
+ "fastapi>=0.165.0",
35
+ "grep-ast>=0.9.0",
36
+ "httpx>=0.28.1",
37
+ "mcp>=2.3.0",
38
+ "networkx>=3.6.1",
39
+ "platformdirs>=4.14.7",
40
+ "psutil>=7.2.2",
41
+ "pydantic>=2.0",
42
+ "pydantic-settings>=2.16.3",
43
+ "tiktoken>=0.14.0",
44
+ "tomli-w>=1.2.0",
45
+ "tree-sitter-language-pack>=1.25.2",
46
+ "uvicorn>=0.54.0",
47
+ ]
48
+
49
+ [[project.authors]]
50
+ name = "Dhanush Veerla"
51
+ email = "dhanushveerla@gmail.com"
52
+
53
+ [project.urls]
54
+ Homepage = "https://github.com/dhanushveerla/crispllm"
55
+ Repository = "https://github.com/dhanushveerla/crispllm"
56
+ Documentation = "https://github.com/dhanushveerla/crispllm#readme"
57
+ "Bug Tracker" = "https://github.com/dhanushveerla/crispllm/issues"
58
+ Changelog = "https://github.com/dhanushveerla/crispllm/blob/master/CHANGELOG.md"
59
+
60
+ [project.scripts]
61
+ crispllm = "crispllm.cli:main"
62
+
63
+ [build-system]
64
+ requires = ["uv_build>=0.12.7,<0.13.0"]
65
+ build-backend = "uv_build"
66
+
67
+ [tool.uv.build-backend]
68
+ module-name = "crispllm"
69
+
70
+ [tool.pytest.ini_options]
71
+ asyncio_default_fixture_loop_scope = "function"
72
+
73
+ [dependency-groups]
74
+ dev = [
75
+ "pytest>=9.2.0",
76
+ "pytest-asyncio>=1.5.0",
77
+ ]