skim-llm 0.2.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 (43) hide show
  1. skim_llm-0.2.0/LICENSE +21 -0
  2. skim_llm-0.2.0/PKG-INFO +390 -0
  3. skim_llm-0.2.0/README.md +312 -0
  4. skim_llm-0.2.0/adapters/__init__.py +12 -0
  5. skim_llm-0.2.0/adapters/base_adapter.py +226 -0
  6. skim_llm-0.2.0/adapters/claude_adapter.py +212 -0
  7. skim_llm-0.2.0/adapters/gemini_adapter.py +164 -0
  8. skim_llm-0.2.0/adapters/ollama_adapter.py +194 -0
  9. skim_llm-0.2.0/adapters/openai_adapter.py +117 -0
  10. skim_llm-0.2.0/core/__init__.py +1 -0
  11. skim_llm-0.2.0/core/audit.py +150 -0
  12. skim_llm-0.2.0/core/baseline.py +186 -0
  13. skim_llm-0.2.0/core/check.py +144 -0
  14. skim_llm-0.2.0/core/cli.py +295 -0
  15. skim_llm-0.2.0/core/config.py +128 -0
  16. skim_llm-0.2.0/core/context_analyzer.py +322 -0
  17. skim_llm-0.2.0/core/fix.py +169 -0
  18. skim_llm-0.2.0/core/hooks.py +141 -0
  19. skim_llm-0.2.0/core/proxy.py +529 -0
  20. skim_llm-0.2.0/core/secrets_detector.py +169 -0
  21. skim_llm-0.2.0/core/token_counter.py +315 -0
  22. skim_llm-0.2.0/pyproject.toml +88 -0
  23. skim_llm-0.2.0/scripts/__init__.py +1 -0
  24. skim_llm-0.2.0/scripts/add_final_slide.py +177 -0
  25. skim_llm-0.2.0/scripts/example_usage.py +124 -0
  26. skim_llm-0.2.0/scripts/generate_config.py +351 -0
  27. skim_llm-0.2.0/scripts/update_pptx.py +183 -0
  28. skim_llm-0.2.0/server/__init__.py +1 -0
  29. skim_llm-0.2.0/server/app.py +297 -0
  30. skim_llm-0.2.0/server/auth.py +187 -0
  31. skim_llm-0.2.0/server/db.py +245 -0
  32. skim_llm-0.2.0/server/static/dashboard.html +632 -0
  33. skim_llm-0.2.0/server/static/login.html +86 -0
  34. skim_llm-0.2.0/setup.cfg +4 -0
  35. skim_llm-0.2.0/skim_llm.egg-info/PKG-INFO +390 -0
  36. skim_llm-0.2.0/skim_llm.egg-info/SOURCES.txt +41 -0
  37. skim_llm-0.2.0/skim_llm.egg-info/dependency_links.txt +1 -0
  38. skim_llm-0.2.0/skim_llm.egg-info/entry_points.txt +11 -0
  39. skim_llm-0.2.0/skim_llm.egg-info/requires.txt +38 -0
  40. skim_llm-0.2.0/skim_llm.egg-info/top_level.txt +5 -0
  41. skim_llm-0.2.0/skim_mcp/__init__.py +1 -0
  42. skim_llm-0.2.0/skim_mcp/server.py +168 -0
  43. skim_llm-0.2.0/tests/test_core.py +142 -0
skim_llm-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TokenWise Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,390 @@
1
+ Metadata-Version: 2.4
2
+ Name: skim-llm
3
+ Version: 0.2.0
4
+ Summary: Runtime token proxy + optimization toolkit for LLM developers and enterprises. Intercepts API calls, strips waste in real-time, tracks costs, and serves a web dashboard.
5
+ Author-email: bb1nfosec <vickytestssec@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 TokenWise Contributors
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/bb1nfosec/skim
29
+ Project-URL: Repository, https://github.com/bb1nfosec/skim
30
+ Project-URL: Issues, https://github.com/bb1nfosec/skim/issues
31
+ Project-URL: Changelog, https://github.com/bb1nfosec/skim/blob/main/CHANGELOG.md
32
+ Keywords: llm,tokens,token-optimization,claude,openai,gemini,ollama,ai,cost,developer-tools,proxy,api-gateway,context-window,runtime,enterprise,dashboard
33
+ Classifier: Development Status :: 4 - Beta
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: Intended Audience :: System Administrators
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.10
39
+ Classifier: Programming Language :: Python :: 3.11
40
+ Classifier: Programming Language :: Python :: 3.12
41
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
42
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
43
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
44
+ Classifier: Environment :: Console
45
+ Classifier: Operating System :: OS Independent
46
+ Requires-Python: >=3.10
47
+ Description-Content-Type: text/markdown
48
+ License-File: LICENSE
49
+ Provides-Extra: tiktoken
50
+ Requires-Dist: tiktoken>=0.7.0; extra == "tiktoken"
51
+ Provides-Extra: claude
52
+ Requires-Dist: anthropic>=0.40.0; extra == "claude"
53
+ Provides-Extra: openai
54
+ Requires-Dist: openai>=1.50.0; extra == "openai"
55
+ Provides-Extra: gemini
56
+ Requires-Dist: google-generativeai>=0.8.0; extra == "gemini"
57
+ Provides-Extra: mcp
58
+ Requires-Dist: mcp>=1.0.0; extra == "mcp"
59
+ Provides-Extra: web
60
+ Requires-Dist: flask>=3.0.0; extra == "web"
61
+ Provides-Extra: sso
62
+ Requires-Dist: authlib>=1.3.0; extra == "sso"
63
+ Requires-Dist: httpx>=0.27.0; extra == "sso"
64
+ Provides-Extra: ldap
65
+ Requires-Dist: ldap3>=2.9.0; extra == "ldap"
66
+ Provides-Extra: dev
67
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
68
+ Requires-Dist: tiktoken>=0.7.0; extra == "dev"
69
+ Requires-Dist: flask>=3.0.0; extra == "dev"
70
+ Provides-Extra: all
71
+ Requires-Dist: tiktoken>=0.7.0; extra == "all"
72
+ Requires-Dist: anthropic>=0.40.0; extra == "all"
73
+ Requires-Dist: openai>=1.50.0; extra == "all"
74
+ Requires-Dist: google-generativeai>=0.8.0; extra == "all"
75
+ Requires-Dist: mcp>=1.0.0; extra == "all"
76
+ Requires-Dist: flask>=3.0.0; extra == "all"
77
+ Dynamic: license-file
78
+
79
+ <div align="center">
80
+
81
+ # skim
82
+
83
+ **The runtime layer between your AI tools and the LLM API.**
84
+
85
+ [![PyPI](https://img.shields.io/pypi/v/skim-llm?color=2563eb&logo=pypi&logoColor=white)](https://pypi.org/project/skim-llm/)
86
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-2563eb?logo=python&logoColor=white)](https://www.python.org/)
87
+ [![License: MIT](https://img.shields.io/badge/license-MIT-059669)](LICENSE)
88
+ [![Zero hard deps](https://img.shields.io/badge/core-zero%20hard%20deps-d97706)](pyproject.toml)
89
+
90
+ [Quickstart](#quickstart) · [Proxy](#proxy--the-core) · [Dashboard](#dashboard) · [CLI](#cli-reference) · [Enterprise](#enterprise) · [Demo](https://demo-mu-ten-60.vercel.app)
91
+
92
+ </div>
93
+
94
+ ---
95
+
96
+ Most LLM tools waste tokens invisibly. Claude Code reads a `package-lock.json` (122k tokens, $0.37) before answering a question about a 200-line file. Conversation history compounds quadratically. Your 200k context window fills up silently, quality degrades, and you're flying blind until the model forgets what it was doing.
97
+
98
+ **skim** sits in the API call path and fixes this in real-time — without touching any code.
99
+
100
+ ```
101
+ Your tool (Claude Code / Cursor / custom)
102
+
103
+
104
+ skim proxy ← one env var activates this
105
+ ├── strips lock files from tool outputs
106
+ ├── auto-injects prompt caching (50–90% cheaper)
107
+ ├── shows live context fill %
108
+ └── ships usage data to your team dashboard
109
+
110
+
111
+ Anthropic / OpenAI / Gemini API
112
+ ```
113
+
114
+ ---
115
+
116
+ ## Quickstart
117
+
118
+ ```bash
119
+ pip install skim-llm
120
+
121
+ # Start the proxy
122
+ skim proxy --port 7474 --path .
123
+
124
+ # In your shell (or .zshrc / .bashrc):
125
+ export ANTHROPIC_BASE_URL=http://localhost:7474
126
+
127
+ # That's it. Every Claude Code / Cursor call now goes through skim.
128
+ ```
129
+
130
+ **What you'll see in the terminal:**
131
+
132
+ ```
133
+ [skim] 14:23:01 call #1 1,247ms
134
+ Context ████░░░░░░░░░░░░░░░░░░ 12.4% 24.8k/200k
135
+ This call: 24.8k in / 1.2k out stripped 122k waste (package-lock.json)
136
+
137
+ [skim] 14:23:45 call #2 892ms
138
+ Context ███████░░░░░░░░░░░░░░░ 38.1% 76.2k/200k
139
+ This call: 51.4k in / 2.1k out cache hit 18.6k tokens free
140
+
141
+ [skim] 14:24:55 call #4 788ms
142
+ Context ████████████████░░░░░░ 78.4% 156.8k/200k
143
+ ⚠ 78% full — /compact NOW before quality degrades
144
+ ```
145
+
146
+ ---
147
+
148
+ ## Proxy — the core
149
+
150
+ The proxy is what makes skim different from every other LLM cost tool. They scan files. skim intercepts calls.
151
+
152
+ ### What it does on every API call
153
+
154
+ **1. Waste filtering**
155
+ Detects lock files, build artifacts, and generated code inside `tool_result` blocks (the content Claude Code gets back when it reads a file) and strips them before they enter context. A `package-lock.json` read that would cost 122k tokens becomes a 12-token note.
156
+
157
+ **2. Prompt caching auto-injection** (Anthropic only)
158
+ Wraps your system prompt and large context blocks with `cache_control: {"type": "ephemeral"}` automatically. First call: Anthropic caches the content (25% write fee once). Every subsequent call: that content is free. For Claude Code, the CLAUDE.md + project context loads at zero cost on calls 2+. Real savings: 50–90% on system prompt tokens.
159
+
160
+ **3. Live session health**
161
+ After every call, prints context fill % with a progress bar. Warns at 65%, alerts at 85%. For Claude Code Pro users, this is the visibility you never had.
162
+
163
+ **4. Actual usage tracking**
164
+ Reads `usage.input_tokens` from the API response — not estimates. Ships real numbers to `~/.skim/audit.log` and optionally to a central team dashboard.
165
+
166
+ ### OpenAI-compatible tools
167
+
168
+ ```bash
169
+ export OPENAI_BASE_URL=http://localhost:7474
170
+ ```
171
+
172
+ Works with anything that uses `openai.OpenAI(base_url=...)`.
173
+
174
+ ---
175
+
176
+ ## Dashboard
177
+
178
+ For teams, skim includes a web server with login, per-user cost attribution, and budget alerts.
179
+
180
+ ```bash
181
+ # Install web extras
182
+ pip install 'skim-llm[web]'
183
+
184
+ # Start the server
185
+ SKIM_ADMIN_EMAIL=you@corp.com skim server --host 0.0.0.0 --port 7475
186
+
187
+ # Open http://localhost:7475/dashboard
188
+ ```
189
+
190
+ Then connect each developer's proxy to it:
191
+
192
+ ```bash
193
+ export SKIM_SERVER_URL=https://skim.corp.internal
194
+ export SKIM_SERVER_TOKEN=sk-skim-... # generate in Settings
195
+ ```
196
+
197
+ **Auth options:**
198
+ - Local password (default)
199
+ - LDAP / Active Directory: set `SKIM_LDAP_URL` + `SKIM_LDAP_BASE_DN`
200
+ - Google / GitHub / Azure AD / Okta: set `SKIM_OIDC_*` env vars
201
+
202
+ **Docker:**
203
+ ```bash
204
+ docker run -p 7474:7474 -p 7475:7475 \
205
+ -e SKIM_ADMIN_EMAIL=you@corp.com \
206
+ -v /data/skim:/data \
207
+ ghcr.io/bb1nfosec/skim
208
+ ```
209
+
210
+ ---
211
+
212
+ ## CLI Reference
213
+
214
+ ```
215
+ skim scan Audit token costs per file
216
+ skim analyze Detect waste patterns with severity + auto-fix
217
+ skim fix Write .llmignore rules — shows before/after savings
218
+ skim check CI budget gate (exits 1 if over threshold)
219
+ skim generate Generate .llmignore, .skimrc, CLAUDE.md
220
+ skim secrets Scan for leaked credentials (AWS, OpenAI, GitHub PAT...)
221
+ skim proxy Runtime interceptor + query optimizer
222
+ skim server Web dashboard + REST API
223
+ skim audit View operation log (~/.skim/audit.log)
224
+ skim config Manage .skimrc configuration
225
+ skim hooks Install/remove git pre-commit budget gate
226
+ skim baseline Save/compare token count snapshots
227
+ ```
228
+
229
+ ### Static analysis (no API key needed)
230
+
231
+ ```bash
232
+ # See what's eating your tokens and what it costs
233
+ skim scan --path ./my-project
234
+
235
+ # Find waste patterns with one-line fixes
236
+ skim analyze --path .
237
+
238
+ # Auto-fix: write .llmignore rules, show before/after
239
+ skim fix --path . --min-severity medium
240
+
241
+ # Fail CI if project exceeds 30% of model context limit
242
+ skim check --path . --max-pct 30 --fail-on-waste
243
+ ```
244
+
245
+ **Example output — `skim fix`:**
246
+ ```
247
+ distill fix — ./my-project
248
+ ──────────────────────────────────────────────────────
249
+ Before : 166.8k tokens (83.4% ctx) $0.50/session
250
+
251
+ Pattern Severity Tokens saved Rules
252
+ ────────────────────────────────────────────────────
253
+ Lock files HIGH 160.3k +7
254
+ Test snapshots MEDIUM 4.1k +2
255
+
256
+ ✓ Written to .llmignore
257
+
258
+ After : 6.5k tokens (3.2% ctx) $0.02/session
259
+ Saved : 160.3k tokens (96.1% reduction) $0.48/session
260
+ Now : 51 sessions / $1
261
+ ```
262
+
263
+ ### Secrets scan
264
+
265
+ ```bash
266
+ # Scan before any LLM touches your codebase
267
+ skim secrets --path . --fail # exits 1 if findings exist
268
+ ```
269
+
270
+ Detects: AWS Access Key IDs, OpenAI API keys, Anthropic keys, GitHub PATs, private key blocks, Stripe live keys, Slack tokens, JWTs, and generic secrets/passwords.
271
+
272
+ ### Baseline regression (CI)
273
+
274
+ ```bash
275
+ # Save before a refactor
276
+ skim baseline save --name pre-refactor
277
+
278
+ # Compare after — fails CI if > 5k tokens regressed
279
+ skim baseline compare --name pre-refactor
280
+ ```
281
+
282
+ ### Git hook
283
+
284
+ ```bash
285
+ # Block commits that push context over budget
286
+ skim hooks install --max-pct 30 --fail-on-waste
287
+ ```
288
+
289
+ ---
290
+
291
+ ## Enterprise
292
+
293
+ | Need | Solution |
294
+ |------|----------|
295
+ | Cost attribution by team | `skim server` dashboard, per-user breakdown |
296
+ | Budget enforcement | `skim check` in CI + git hooks + proxy hard limits |
297
+ | SSO / LDAP | `SKIM_OIDC_*` + `SKIM_LDAP_*` env vars |
298
+ | Audit trail | `~/.skim/audit.log` + central server ingestion |
299
+ | Self-hosted deployment | Docker image + Helm chart (see `deploy/`) |
300
+ | Secrets governance | `skim secrets --fail` in pre-commit + CI |
301
+ | Regression prevention | `skim baseline compare` in PR pipelines |
302
+ | Air-gapped / Ollama | `--model ollama` — all analysis local, $0.00 |
303
+
304
+ ---
305
+
306
+ ## Configuration
307
+
308
+ Create `.skimrc` in your project root (commit it for team-wide policy):
309
+
310
+ ```ini
311
+ model = claude # claude | openai | gemini | ollama
312
+ max_pct = 30 # fail CI if context exceeds X% of limit
313
+ fail_on_waste = false # also fail on HIGH severity patterns
314
+ min_severity = high # auto-fix: high | medium | low
315
+ audit = false # log every operation to ~/.skim/audit.log
316
+ proxy_port = 7474
317
+ ```
318
+
319
+ ---
320
+
321
+ ## MCP Server
322
+
323
+ Exposes skim as Claude Desktop tools (no CLI needed):
324
+
325
+ ```json
326
+ {
327
+ "mcpServers": {
328
+ "skim": { "command": "skim-mcp" }
329
+ }
330
+ }
331
+ ```
332
+
333
+ Available tools: `scan_tokens`, `analyze_context`, `check_budget`, `fix_context`, `generate_llmignore`
334
+
335
+ ---
336
+
337
+ ## Python API
338
+
339
+ ```python
340
+ from adapters import ClaudeAdapter
341
+
342
+ claude = ClaudeAdapter(
343
+ model="claude-sonnet-4-5",
344
+ system_prompt="You are a terse coding assistant.",
345
+ enable_caching=True, # enables prompt caching automatically
346
+ )
347
+ response = claude.chat("Refactor the auth module")
348
+ claude.print_stats()
349
+ # Session: 12,400 tokens | Cache hit rate: 87% | Cost: $0.0037
350
+ ```
351
+
352
+ Adapters: `ClaudeAdapter`, `OpenAIAdapter`, `GeminiAdapter`, `OllamaAdapter`
353
+
354
+ ---
355
+
356
+ ## Install
357
+
358
+ ```bash
359
+ # Core (zero hard deps — scan, analyze, check, fix, proxy)
360
+ pip install skim-llm
361
+
362
+ # With accurate token counting
363
+ pip install 'skim-llm[tiktoken]'
364
+
365
+ # With Claude adapter
366
+ pip install 'skim-llm[claude]'
367
+
368
+ # Web dashboard
369
+ pip install 'skim-llm[web]'
370
+
371
+ # Enterprise (SSO + LDAP)
372
+ pip install 'skim-llm[web,sso,ldap]'
373
+
374
+ # Everything
375
+ pip install 'skim-llm[all]'
376
+ ```
377
+
378
+ ---
379
+
380
+ ## Demo
381
+
382
+ Live demo (individual + org/enterprise): **https://demo-mu-ten-60.vercel.app**
383
+
384
+ ---
385
+
386
+ <div align="center">
387
+
388
+ MIT License · [GitHub](https://github.com/bb1nfosec/skim) · [Issues](https://github.com/bb1nfosec/skim/issues) · [Changelog](CHANGELOG.md)
389
+
390
+ </div>