xithead 1.0.0 → 1.1.1
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.
- package/README.md +169 -91
- package/npm/bin/xithead.js +237 -42
- package/npm/postinstall.js +43 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,161 +1,239 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<img src="https://cdn.xtream-itsolutions.com/u/logo.png" alt="Xtream-ITSolutions UG" width="
|
|
2
|
+
<img src="https://cdn.xtream-itsolutions.com/u/logo.png" alt="Xtream-ITSolutions UG" width="160" />
|
|
3
3
|
<h1>xithead</h1>
|
|
4
|
-
<p><strong>Aggressive Claude Context Optimizer</strong></p>
|
|
5
|
-
<p>Cut your Claude API costs by 50–95% with zero accuracy loss.</p>
|
|
4
|
+
<p><strong>Aggressive Claude Context Optimizer — bis zu 95% Token-Einsparung</strong></p>
|
|
6
5
|
<p>
|
|
7
|
-
<a href="https://pypi.org/project/xithead/"><img src="https://img.shields.io/pypi/v/xithead?color=
|
|
8
|
-
<a href="https://www.npmjs.com/package/xithead"><img src="https://img.shields.io/npm/v/xithead?color=
|
|
9
|
-
<a href="https://discord.gg/xtream-itsolutions"><img src="https://img.shields.io/
|
|
10
|
-
<a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-
|
|
6
|
+
<a href="https://pypi.org/project/xithead/"><img src="https://img.shields.io/pypi/v/xithead?color=00d4ff&label=PyPI&style=flat-square" alt="PyPI" /></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/xithead"><img src="https://img.shields.io/npm/v/xithead?color=e879f9&label=npm&style=flat-square" alt="npm" /></a>
|
|
8
|
+
<a href="https://discord.gg/xtream-itsolutions"><img src="https://img.shields.io/badge/Discord-Join-5865F2?style=flat-square&logo=discord&logoColor=white" alt="Discord" /></a>
|
|
9
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-10b981?style=flat-square" alt="License" /></a>
|
|
11
10
|
</p>
|
|
12
11
|
<p>
|
|
13
|
-
<a href="https://discord.gg/xtream-itsolutions"
|
|
14
|
-
<a href="https://github.com/xtream-itsolutions/headroom/issues"
|
|
15
|
-
<a href="https://github.com/xtream-itsolutions/headroom/issues"
|
|
12
|
+
<a href="https://discord.gg/xtream-itsolutions">💬 Discord</a> ·
|
|
13
|
+
<a href="https://github.com/xtream-itsolutions/headroom/issues">🐛 Bug melden</a> ·
|
|
14
|
+
<a href="https://github.com/xtream-itsolutions/headroom/issues">✨ Feature anfragen</a>
|
|
16
15
|
</p>
|
|
17
16
|
</div>
|
|
18
17
|
|
|
19
18
|
---
|
|
20
19
|
|
|
21
|
-
##
|
|
20
|
+
## Was ist xithead?
|
|
22
21
|
|
|
23
|
-
**xithead**
|
|
24
|
-
|
|
22
|
+
**xithead** ist ein Claude-spezifischer Context Optimizer von **Xtream-ITSolutions UG**.
|
|
23
|
+
Er sitzt zwischen deiner App und der Claude API, komprimiert Prompts aggressiv und cached Antworten — du sendest weniger Tokens und zahlst deutlich weniger.
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
- **Drop-in Proxy** — keine Code-Änderungen nötig
|
|
26
|
+
- **Immer Sonnet 4.6** — das beste Modell, automatisch gepinnt
|
|
27
|
+
- **Ultra-Modus standardmäßig** — 50–95% Einsparung ab dem ersten Request
|
|
28
|
+
- **Live Dashboard** — Einsparungen in Echtzeit auf `localhost:8787/dashboard`
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Schnellstart — Windows (empfohlen)
|
|
33
|
+
|
|
34
|
+
```powershell
|
|
35
|
+
# PowerShell als Administrator, einmalig:
|
|
36
|
+
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
|
|
37
|
+
iex (irm https://raw.githubusercontent.com/xtream-itsolutions/headroom/main/headroom.ps1)
|
|
38
|
+
```
|
|
29
39
|
|
|
30
|
-
|
|
31
|
-
|---------|-------------|---------|
|
|
32
|
-
| 🔥 **Prompt Caching** | Auto-injects Anthropic `cache_control` markers | Up to 90% on cached tokens |
|
|
33
|
-
| 🗜️ **Context Compression** | Removes redundancy, deduplicates messages | 30–60% fewer tokens |
|
|
34
|
-
| 💾 **Smart Caching** | Multi-layer cache (memory + SQLite) | Skip repeat API calls |
|
|
35
|
-
| 🎯 **System Prompt Optimizer** | Compresses verbose system prompts | 10–40% savings |
|
|
36
|
-
| 📊 **Real-time Dashboard** | Live token & cost tracking via proxy | Full visibility |
|
|
37
|
-
| 🔌 **Drop-in Proxy** | Zero code changes needed | Works with any client |
|
|
40
|
+
Danach neues Terminal öffnen und loslegen:
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
```powershell
|
|
43
|
+
xithead # Claude starten — ultra-aggressiv, 50-95% Einsparung
|
|
44
|
+
xithead-proxy # Proxy + Dashboard auf http://localhost:8787/dashboard
|
|
45
|
+
xithead-stats # Einsparungen anzeigen
|
|
46
|
+
xithead-update # xithead aktualisieren
|
|
47
|
+
xithead-help # Alle Befehle
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
> **VS Code:** Terminal mit `Strg+\`` öffnen, PowerShell wählen, `xithead` eingeben — fertig.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
40
55
|
|
|
41
56
|
### Python
|
|
42
57
|
|
|
43
58
|
```bash
|
|
44
|
-
pip install xithead
|
|
59
|
+
pip install xithead # nur CLI + Optimizer
|
|
60
|
+
pip install "xithead[proxy]" # + Proxy + Dashboard (empfohlen)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### npm / Node.js
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install -g xithead
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## CLI Befehle
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
xithead proxy # Proxy starten (Port 8787) + Dashboard
|
|
75
|
+
xithead optimize "prompt" # Prompt optimieren und Einsparung zeigen
|
|
76
|
+
xithead stats # Session-Statistiken
|
|
77
|
+
xithead cache stats # Cache-Statistiken
|
|
78
|
+
xithead cache clear # Cache leeren
|
|
79
|
+
xithead model set claude-sonnet-4-6 # Modell setzen
|
|
80
|
+
xithead model show # Aktuelles Modell anzeigen
|
|
45
81
|
```
|
|
46
82
|
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Features
|
|
86
|
+
|
|
87
|
+
| Feature | Beschreibung | Einsparung |
|
|
88
|
+
|---------|-------------|------------|
|
|
89
|
+
| 🔥 **Prompt Caching** | `cache_control`-Marker automatisch injizieren | Bis 90% auf Cache-Hits |
|
|
90
|
+
| 🗜️ **Context Compression** | Redundanz entfernen, Nachrichten deduplizieren | 30–60% weniger Tokens |
|
|
91
|
+
| 💾 **Multi-Layer Cache** | RAM + SQLite, SHA-256 Keys, TTL | Wiederholte Calls gratis |
|
|
92
|
+
| ✂️ **Context Trim** | Alten Context trimmen (verhindert 400-Fehler) | Spart Input-Tokens |
|
|
93
|
+
| 📉 **Verbosity Reduction** | System-Prompts komprimieren | 10–40% Einsparung |
|
|
94
|
+
| 📊 **Live Dashboard** | Token- & Kosten-Tracking in Echtzeit | Volle Transparenz |
|
|
95
|
+
| 🔌 **Drop-in Proxy** | Keine Code-Änderungen | Funktioniert mit jedem Client |
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Einsparungs-Beispiele
|
|
100
|
+
|
|
101
|
+
| Anwendungsfall | Original | Nach xithead | Gespart |
|
|
102
|
+
|----------------|----------|--------------|---------|
|
|
103
|
+
| Code-Review (wiederholter Kontext) | 50.000 Tokens | 4.000 Tokens | **92%** |
|
|
104
|
+
| Chat mit langem System-Prompt | 10.000 Tokens | 2.000 Tokens | **80%** |
|
|
105
|
+
| Agentischer Loop (Tool-Ergebnisse) | 100.000 Tokens | 25.000 Tokens | **75%** |
|
|
106
|
+
| Einfaches Q&A | 500 Tokens | 400 Tokens | ~20% |
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Python API
|
|
111
|
+
|
|
47
112
|
```python
|
|
48
113
|
from xithead import optimize_for_claude
|
|
49
114
|
|
|
50
|
-
messages = [{"role": "user", "content": "
|
|
115
|
+
messages = [{"role": "user", "content": "Sehr langer Prompt hier..."}]
|
|
51
116
|
result = optimize_for_claude(messages, model="claude-sonnet-4-6")
|
|
52
117
|
|
|
53
|
-
|
|
54
|
-
print(f"
|
|
118
|
+
print(f"Tokens gespart: {result.tokens_saved}")
|
|
119
|
+
print(f"Kosten gespart: ${result.cost_saved_usd:.4f}")
|
|
120
|
+
print(f"Kompression: {result.compression_ratio:.1%}")
|
|
121
|
+
print(f"Cache-Hit: {result.cache_hit}")
|
|
122
|
+
|
|
123
|
+
# Optimierte messages an Anthropic API übergeben:
|
|
124
|
+
# client.messages.create(messages=result.messages, ...)
|
|
55
125
|
```
|
|
56
126
|
|
|
57
|
-
###
|
|
127
|
+
### Konfiguration
|
|
58
128
|
|
|
59
|
-
```
|
|
60
|
-
|
|
129
|
+
```python
|
|
130
|
+
from xithead.claude_optimizer import ClaudeOptimizer, ClaudeOptimizerConfig
|
|
131
|
+
|
|
132
|
+
config = ClaudeOptimizerConfig(
|
|
133
|
+
enable_prompt_caching=True,
|
|
134
|
+
enable_dedup=True,
|
|
135
|
+
enable_verbosity_reduction=True,
|
|
136
|
+
enable_context_trim=True,
|
|
137
|
+
max_context_tokens=180_000,
|
|
138
|
+
cache_ttl_seconds=86400,
|
|
139
|
+
)
|
|
140
|
+
optimizer = ClaudeOptimizer(config)
|
|
141
|
+
result = optimizer.optimize(messages, system="Du bist ein hilfreicher Assistent.", model="claude-sonnet-4-6")
|
|
61
142
|
```
|
|
62
143
|
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Node.js / JavaScript API
|
|
147
|
+
|
|
63
148
|
```javascript
|
|
64
|
-
const { optimize, createOptimizedClient } = require('xithead');
|
|
149
|
+
const { optimize, createOptimizedClient, injectCacheControl } = require('xithead');
|
|
65
150
|
const Anthropic = require('@anthropic-ai/sdk');
|
|
66
151
|
|
|
67
|
-
// Option 1:
|
|
152
|
+
// Option 1: Manuell optimieren
|
|
68
153
|
const result = optimize({ messages, system, model: 'claude-sonnet-4-6' });
|
|
154
|
+
console.log(result.tokensSaved, result.costSavedUsd);
|
|
69
155
|
|
|
70
|
-
// Option 2: Wrapped
|
|
156
|
+
// Option 2: Wrapped Client (optimiert automatisch jeden Call)
|
|
71
157
|
const client = new Anthropic();
|
|
72
158
|
const xitClient = createOptimizedClient(client);
|
|
73
159
|
const response = await xitClient.messages.create({
|
|
74
160
|
model: 'claude-sonnet-4-6',
|
|
75
161
|
max_tokens: 1024,
|
|
76
|
-
messages: [{ role: 'user', content: '
|
|
162
|
+
messages: [{ role: 'user', content: 'Hallo!' }],
|
|
77
163
|
});
|
|
78
|
-
console.log(xitClient.getStats());
|
|
164
|
+
console.log(xitClient.getStats());
|
|
79
165
|
```
|
|
80
166
|
|
|
81
|
-
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Proxy-Modus (Zero Code Changes)
|
|
82
170
|
|
|
83
171
|
```bash
|
|
172
|
+
# Proxy starten
|
|
84
173
|
xithead proxy --port 8787
|
|
85
|
-
# Now point your Claude client to http://localhost:8787
|
|
86
|
-
# All requests are automatically optimized
|
|
87
|
-
```
|
|
88
174
|
|
|
89
|
-
|
|
175
|
+
# Dashboard öffnen
|
|
176
|
+
# → http://localhost:8787/dashboard
|
|
90
177
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
├─ Cache lookup (skip API call if cached)
|
|
95
|
-
├─ Message deduplication
|
|
96
|
-
├─ System prompt compression
|
|
97
|
-
├─ cache_control marker injection
|
|
98
|
-
├─ Context window trim (prevent 400 errors)
|
|
99
|
-
└─ Token/cost tracking
|
|
178
|
+
# Deinen Claude Client auf den Proxy zeigen lassen:
|
|
179
|
+
export ANTHROPIC_BASE_URL=http://localhost:8787
|
|
180
|
+
claude # oder jede andere App
|
|
100
181
|
```
|
|
101
182
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
xithead optimize "your prompt" # Optimize a prompt
|
|
107
|
-
xithead stats # Show session stats
|
|
108
|
-
xithead cache clear # Clear local cache
|
|
109
|
-
xithead cache stats # Cache statistics
|
|
110
|
-
xithead memory list # List stored memories
|
|
183
|
+
In PowerShell:
|
|
184
|
+
```powershell
|
|
185
|
+
$env:ANTHROPIC_BASE_URL = "http://localhost:8787"
|
|
186
|
+
claude
|
|
111
187
|
```
|
|
112
188
|
|
|
113
|
-
|
|
189
|
+
---
|
|
114
190
|
|
|
115
|
-
|
|
116
|
-
|----------|----------------|----------------|-------|
|
|
117
|
-
| Code review (repeated context) | 50,000 | 8,000 | **84%** |
|
|
118
|
-
| Chat with long system prompt | 10,000 | 2,500 | **75%** |
|
|
119
|
-
| Agentic loop (tool results) | 100,000 | 35,000 | **65%** |
|
|
120
|
-
| Simple Q&A | 500 | 450 | ~10% |
|
|
191
|
+
## Wie es funktioniert
|
|
121
192
|
|
|
122
|
-
|
|
193
|
+
```
|
|
194
|
+
Deine App → xithead Proxy → Optimierter Request → Claude API
|
|
195
|
+
│
|
|
196
|
+
├─ Cache-Lookup (API-Call überspringen wenn gecacht)
|
|
197
|
+
├─ Nachrichten-Deduplizierung
|
|
198
|
+
├─ System-Prompt Kompression
|
|
199
|
+
├─ cache_control Marker injizieren
|
|
200
|
+
├─ Context-Window Trim (verhindert 400-Fehler)
|
|
201
|
+
└─ Token/Kosten-Tracking
|
|
202
|
+
```
|
|
123
203
|
|
|
124
|
-
|
|
125
|
-
from xithead.claude_optimizer import ClaudeOptimizer, ClaudeOptimizerConfig
|
|
204
|
+
---
|
|
126
205
|
|
|
127
|
-
|
|
128
|
-
enable_prompt_caching=True, # Inject cache_control markers
|
|
129
|
-
enable_dedup=True, # Remove duplicate messages
|
|
130
|
-
enable_verbosity_reduction=True, # Compress system prompts
|
|
131
|
-
enable_context_trim=True, # Trim old context
|
|
132
|
-
max_context_tokens=180_000, # Claude max context
|
|
133
|
-
cache_ttl_seconds=86400, # 24h cache TTL
|
|
134
|
-
)
|
|
135
|
-
optimizer = ClaudeOptimizer(config)
|
|
136
|
-
result = optimizer.optimize(messages, system="You are a helpful assistant.", model="claude-sonnet-4-6")
|
|
137
|
-
```
|
|
206
|
+
## Umgebungsvariablen
|
|
138
207
|
|
|
139
|
-
|
|
208
|
+
| Variable | Standardwert | Beschreibung |
|
|
209
|
+
|----------|-------------|--------------|
|
|
210
|
+
| `XITHEAD_MODEL` | `claude-sonnet-4-6` | Claude-Modell |
|
|
211
|
+
| `XITHEAD_ENABLE_CACHE_CONTROL` | `1` | Prompt-Caching aktivieren |
|
|
212
|
+
| `XITHEAD_ENABLE_DEDUP` | `1` | Nachrichten-Dedup aktivieren |
|
|
213
|
+
| `XITHEAD_ENABLE_CONTEXT_TRIM` | `1` | Context-Trim aktivieren |
|
|
214
|
+
| `HEADROOM_COMPRESSION_RATIO_TARGET` | `0.3` | Kompressions-Ziel (0.3 = 70%) |
|
|
215
|
+
| `HEADROOM_STRENGTH` | `aggressive` | Kompressions-Stärke |
|
|
216
|
+
| `CLAUDE_CODE_MAX_OUTPUT_TOKENS` | `2048` | Max. Output-Tokens |
|
|
140
217
|
|
|
141
|
-
|
|
218
|
+
---
|
|
142
219
|
|
|
143
|
-
|
|
144
|
-
- **headroom engine**: SmartCrusher (JSON), CodeCompressor (AST), Kompress (ML), semantic caching
|
|
145
|
-
- **Rust crates**: Native proxy (Axum), fast tokenization, embeddings
|
|
220
|
+
## Beitragen
|
|
146
221
|
|
|
147
|
-
|
|
222
|
+
Wir freuen uns über Beiträge! Öffne ein Issue oder Pull Request.
|
|
148
223
|
|
|
149
|
-
|
|
224
|
+
Tritt unserer Community bei: [discord.gg/xtream-itsolutions](https://discord.gg/xtream-itsolutions)
|
|
150
225
|
|
|
151
|
-
|
|
226
|
+
---
|
|
152
227
|
|
|
153
|
-
##
|
|
228
|
+
## Lizenz
|
|
154
229
|
|
|
155
|
-
Apache 2.0 —
|
|
230
|
+
Apache 2.0 — siehe [LICENSE](LICENSE).
|
|
156
231
|
|
|
157
232
|
---
|
|
158
233
|
|
|
159
234
|
<div align="center">
|
|
160
|
-
<
|
|
235
|
+
<p>Made with ❤️ by <a href="https://xtream-itsolutions.com"><strong>Xtream-ITSolutions UG</strong></a></p>
|
|
236
|
+
<a href="https://discord.gg/xtream-itsolutions">
|
|
237
|
+
<img src="https://img.shields.io/badge/Discord-Community_beitreten-5865F2?style=for-the-badge&logo=discord&logoColor=white" alt="Discord" />
|
|
238
|
+
</a>
|
|
161
239
|
</div>
|
package/npm/bin/xithead.js
CHANGED
|
@@ -1,58 +1,253 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* xithead CLI
|
|
4
|
-
* by Xtream-ITSolutions UG
|
|
3
|
+
* xithead CLI — Claude Context Optimizer
|
|
4
|
+
* by Xtream-ITSolutions UG | discord.gg/xtream-itsolutions
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
|
-
const {
|
|
8
|
+
const { spawnSync, spawn } = require('child_process');
|
|
9
|
+
const http = require('http');
|
|
9
10
|
const path = require('path');
|
|
10
11
|
|
|
12
|
+
const PKG_VERSION = (() => {
|
|
13
|
+
try { return require(path.join(__dirname, '../../package.json')).version; } catch { return '1.1.0'; }
|
|
14
|
+
})();
|
|
15
|
+
|
|
11
16
|
const args = process.argv.slice(2);
|
|
17
|
+
const PROXY_PORT = 8787;
|
|
18
|
+
const PROXY_URL = `http://localhost:${PROXY_PORT}`;
|
|
19
|
+
|
|
20
|
+
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
21
|
+
|
|
22
|
+
function findPython() {
|
|
23
|
+
for (const cmd of ['python', 'python3', 'py']) {
|
|
24
|
+
const r = spawnSync(cmd, ['--version'], { stdio: 'pipe' });
|
|
25
|
+
if (r.status === 0) return cmd;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function proxyAlive() {
|
|
31
|
+
// Try /health first (fast), fall back to /api/stats
|
|
32
|
+
return new Promise(resolve => {
|
|
33
|
+
const tryEndpoint = (path, cb) => {
|
|
34
|
+
const req = http.get(`${PROXY_URL}${path}`, { timeout: 3000 }, res => {
|
|
35
|
+
cb(res.statusCode === 200);
|
|
36
|
+
});
|
|
37
|
+
req.on('error', () => cb(false));
|
|
38
|
+
req.on('timeout', () => { req.destroy(); cb(false); });
|
|
39
|
+
};
|
|
40
|
+
tryEndpoint('/health', ok => {
|
|
41
|
+
if (ok) return resolve(true);
|
|
42
|
+
tryEndpoint('/api/stats', resolve);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function startProxy(py) {
|
|
48
|
+
const isWin = process.platform === 'win32';
|
|
49
|
+
// On Windows use 'start' to open a background process properly
|
|
50
|
+
if (isWin) {
|
|
51
|
+
const child = spawn('cmd', ['/c', 'start', '/b', py, '-m', 'xithead.cli.main', 'proxy', '--port', String(PROXY_PORT)], {
|
|
52
|
+
detached: true,
|
|
53
|
+
stdio: 'ignore',
|
|
54
|
+
shell: false,
|
|
55
|
+
});
|
|
56
|
+
child.unref();
|
|
57
|
+
} else {
|
|
58
|
+
const child = spawn(py, ['-m', 'xithead.cli.main', 'proxy', '--port', String(PROXY_PORT)], {
|
|
59
|
+
detached: true,
|
|
60
|
+
stdio: 'ignore',
|
|
61
|
+
});
|
|
62
|
+
child.unref();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
12
65
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
66
|
+
function waitForProxy(timeoutMs = 20000) {
|
|
67
|
+
return new Promise(async resolve => {
|
|
68
|
+
const deadline = Date.now() + timeoutMs;
|
|
69
|
+
while (Date.now() < deadline) {
|
|
70
|
+
if (await proxyAlive()) return resolve(true);
|
|
71
|
+
await new Promise(r => setTimeout(r, 400));
|
|
72
|
+
}
|
|
73
|
+
resolve(false);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function hasPythonXithead(py) {
|
|
78
|
+
const r = spawnSync(py, ['-c', 'import xithead'], { stdio: 'pipe' });
|
|
79
|
+
return r.status === 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function hasProxyDeps(py) {
|
|
83
|
+
const r = spawnSync(py, ['-c', 'import fastapi, uvicorn, httpx'], { stdio: 'pipe' });
|
|
84
|
+
return r.status === 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function installProxyDeps(py) {
|
|
88
|
+
process.stdout.write('\x1b[33m [xithead] Installiere Proxy-Abhängigkeiten...\x1b[0m\n');
|
|
89
|
+
const r = spawnSync(py, ['-m', 'pip', 'install', '-q', 'xithead[proxy]'], { stdio: 'inherit' });
|
|
90
|
+
return r.status === 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ── Commands ──────────────────────────────────────────────────────────────────
|
|
94
|
+
|
|
95
|
+
function showBanner(proxyOk) {
|
|
96
|
+
const c = {
|
|
97
|
+
cyan: '\x1b[36m',
|
|
98
|
+
green: '\x1b[32m',
|
|
99
|
+
magenta: '\x1b[35m',
|
|
100
|
+
gray: '\x1b[90m',
|
|
101
|
+
yellow: '\x1b[33m',
|
|
102
|
+
reset: '\x1b[0m',
|
|
103
|
+
};
|
|
104
|
+
console.log('');
|
|
105
|
+
console.log(`${c.cyan} ╔═══════════════════════════════════════════╗${c.reset}`);
|
|
106
|
+
const ver = `v${PKG_VERSION}`.padEnd(7);
|
|
107
|
+
console.log(`${c.cyan} ║ Xtream-ITSolutions — xithead ${ver} ║${c.reset}`);
|
|
108
|
+
console.log(`${c.cyan} ║ discord.gg/xtream-itsolutions ║${c.reset}`);
|
|
109
|
+
console.log(`${c.cyan} ╠═══════════════════════════════════════════╣${c.reset}`);
|
|
110
|
+
console.log(`${c.green} ║ Modell: claude-sonnet-4-6 ║${c.reset}`);
|
|
111
|
+
console.log(`${c.magenta} ║ Modus: Ultra-Aggressiv (50-95%) ║${c.reset}`);
|
|
112
|
+
if (proxyOk) {
|
|
113
|
+
console.log(`${c.green} ║ Proxy: http://localhost:${PROXY_PORT}/v1 ✓ ║${c.reset}`);
|
|
114
|
+
} else {
|
|
115
|
+
console.log(`${c.yellow} ║ Proxy: nicht erreichbar — direkter API ║${c.reset}`);
|
|
116
|
+
}
|
|
117
|
+
console.log(`${c.cyan} ╚═══════════════════════════════════════════╝${c.reset}`);
|
|
118
|
+
console.log('');
|
|
19
119
|
}
|
|
20
120
|
|
|
21
|
-
// Fallback: show help
|
|
22
121
|
function showHelp() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
xithead
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
122
|
+
const c = { cyan: '\x1b[36m', green: '\x1b[32m', gray: '\x1b[90m', reset: '\x1b[0m' };
|
|
123
|
+
console.log('');
|
|
124
|
+
console.log(`${c.cyan} xithead — Claude Context Optimizer${c.reset}`);
|
|
125
|
+
console.log(`${c.gray} by Xtream-ITSolutions UG${c.reset}`);
|
|
126
|
+
console.log('');
|
|
127
|
+
console.log(`${c.green} xithead${c.reset} Claude starten (Proxy auto, 50-95% Einsparung)`);
|
|
128
|
+
console.log(`${c.green} xithead proxy${c.reset} Proxy + Dashboard starten`);
|
|
129
|
+
console.log(`${c.green} xithead stats${c.reset} Token-Einsparungen anzeigen`);
|
|
130
|
+
console.log(`${c.green} xithead help${c.reset} Diese Hilfe`);
|
|
131
|
+
console.log('');
|
|
132
|
+
console.log(`${c.gray} Dashboard: http://localhost:${PROXY_PORT}/dashboard${c.reset}`);
|
|
133
|
+
console.log(`${c.gray} Discord: discord.gg/xtream-itsolutions${c.reset}`);
|
|
134
|
+
console.log('');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function showStats() {
|
|
138
|
+
return new Promise(resolve => {
|
|
139
|
+
const req = http.get(`${PROXY_URL}/api/stats`, { timeout: 3000 }, res => {
|
|
140
|
+
let body = '';
|
|
141
|
+
res.on('data', d => body += d);
|
|
142
|
+
res.on('end', () => {
|
|
143
|
+
try {
|
|
144
|
+
const s = JSON.parse(body);
|
|
145
|
+
const c = { cyan: '\x1b[36m', green: '\x1b[32m', gray: '\x1b[90m', reset: '\x1b[0m' };
|
|
146
|
+
console.log('');
|
|
147
|
+
console.log(`${c.cyan} ┌─────────────────────────────────────┐${c.reset}`);
|
|
148
|
+
console.log(`${c.cyan} │ xithead Statistiken │${c.reset}`);
|
|
149
|
+
console.log(`${c.cyan} ├─────────────────────────────────────┤${c.reset}`);
|
|
150
|
+
console.log(`${c.reset} │ Requests: ${String(s.session.requests).padEnd(19)}│${c.reset}`);
|
|
151
|
+
console.log(`${c.green} │ Tokens gespart: ${String(s.session.tokens_saved).padEnd(19)}│${c.reset}`);
|
|
152
|
+
console.log(`${c.green} │ Kosten gespart: $${String((s.session.cost_saved_usd||0).toFixed(4)).padEnd(18)}│${c.reset}`);
|
|
153
|
+
console.log(`${c.cyan} │ Cache-Hit-Rate: ${String(((s.session.cache_hit_rate||0)*100).toFixed(1)+'%').padEnd(19)}│${c.reset}`);
|
|
154
|
+
console.log(`${c.gray} │ Modell: ${String(s.model||'').padEnd(19)}│${c.reset}`);
|
|
155
|
+
console.log(`${c.cyan} └─────────────────────────────────────┘${c.reset}`);
|
|
156
|
+
} catch { console.log(' [xithead] Konnte Stats nicht parsen.'); }
|
|
157
|
+
resolve();
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
req.on('error', () => {
|
|
161
|
+
console.log('\x1b[33m [xithead] Proxy nicht erreichbar — starte mit: xithead\x1b[0m');
|
|
162
|
+
resolve();
|
|
163
|
+
});
|
|
164
|
+
req.on('timeout', () => { req.destroy(); resolve(); });
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// ── Main ──────────────────────────────────────────────────────────────────────
|
|
169
|
+
|
|
170
|
+
async function main() {
|
|
171
|
+
const cmd = args[0];
|
|
172
|
+
|
|
173
|
+
if (cmd === 'help' || cmd === '--help' || cmd === '-h') {
|
|
53
174
|
showHelp();
|
|
54
|
-
|
|
55
|
-
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (cmd === 'stats') {
|
|
179
|
+
await showStats();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (cmd === 'proxy') {
|
|
184
|
+
const py = findPython();
|
|
185
|
+
if (!py || !hasPythonXithead(py)) {
|
|
186
|
+
console.error('\x1b[31m [xithead] Python-Paket nicht installiert.\x1b[0m');
|
|
187
|
+
console.error(' Installieren: pip install "git+https://github.com/xtream-itsolutions/headroom.git#subdirectory=xithead_dist"');
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
console.log(`\x1b[36m [xithead] Proxy auf Port ${PROXY_PORT} | Ctrl+C zum Stoppen\x1b[0m`);
|
|
191
|
+
console.log(`\x1b[32m [xithead] Dashboard: ${PROXY_URL}/dashboard\x1b[0m`);
|
|
192
|
+
const child = spawnSync(py, ['-m', 'xithead.cli.main', 'proxy', '--port', String(PROXY_PORT), '--verbose'], { stdio: 'inherit' });
|
|
193
|
+
process.exit(child.status || 0);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Default: launch Claude with proxy
|
|
198
|
+
const py = findPython();
|
|
199
|
+
let proxyOk = await proxyAlive();
|
|
200
|
+
|
|
201
|
+
if (!proxyOk && py && hasPythonXithead(py)) {
|
|
202
|
+
// Auto-install proxy deps if missing
|
|
203
|
+
if (!hasProxyDeps(py)) {
|
|
204
|
+
const ok = installProxyDeps(py);
|
|
205
|
+
if (!ok) {
|
|
206
|
+
console.log('\x1b[31m [xithead] Proxy-Abhängigkeiten konnten nicht installiert werden.\x1b[0m');
|
|
207
|
+
console.log(' Manuell: pip install "xithead[proxy]"');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
process.stdout.write('\x1b[33m [xithead] Proxy startet...\x1b[0m');
|
|
211
|
+
startProxy(py);
|
|
212
|
+
proxyOk = await waitForProxy(20000);
|
|
213
|
+
if (!proxyOk) {
|
|
214
|
+
// Port may already be in use from a previous run — check once more
|
|
215
|
+
proxyOk = await proxyAlive();
|
|
216
|
+
}
|
|
217
|
+
process.stdout.write(proxyOk ? ' \x1b[32mbereit!\x1b[0m\n' : ' \x1b[33mTimeout — direkte API\x1b[0m\n');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
showBanner(proxyOk);
|
|
221
|
+
|
|
222
|
+
// Set env vars for Claude process
|
|
223
|
+
const env = {
|
|
224
|
+
...process.env,
|
|
225
|
+
ANTHROPIC_MODEL: 'claude-sonnet-4-6',
|
|
226
|
+
CLAUDE_MODEL: 'claude-sonnet-4-6',
|
|
227
|
+
CLAUDE_SMALL_FAST_MODEL: 'claude-haiku-4-5-20251001',
|
|
228
|
+
CLAUDE_CODE_MAX_OUTPUT_TOKENS: '2048',
|
|
229
|
+
CLAUDE_CODE_MAX_THINKING_TOKENS: '1000',
|
|
230
|
+
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1',
|
|
231
|
+
XITHEAD_MODEL: 'claude-sonnet-4-6',
|
|
232
|
+
XITHEAD_ENABLE_CACHE_CONTROL: '1',
|
|
233
|
+
XITHEAD_ENABLE_DEDUP: '1',
|
|
234
|
+
XITHEAD_ENABLE_CONTEXT_TRIM: '1',
|
|
235
|
+
HEADROOM_STRENGTH: 'aggressive',
|
|
236
|
+
HEADROOM_COMPRESSION_RATIO_TARGET: '0.3',
|
|
237
|
+
ANTHROPIC_BASE_URL: proxyOk ? `${PROXY_URL}/v1` : 'https://api.anthropic.com/v1',
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// Find claude binary
|
|
241
|
+
const claudeResult = spawnSync(process.platform === 'win32' ? 'where' : 'which', ['claude'], { stdio: 'pipe' });
|
|
242
|
+
if (claudeResult.status !== 0) {
|
|
243
|
+
console.error('\x1b[31m [xithead] Claude Code nicht gefunden. Installieren:\x1b[0m');
|
|
244
|
+
console.error(' npm install -g @anthropic-ai/claude-code');
|
|
56
245
|
process.exit(1);
|
|
57
246
|
}
|
|
247
|
+
|
|
248
|
+
const claudeArgs = args.length > 0 ? args : [];
|
|
249
|
+
const claudeProc = spawnSync('claude', claudeArgs, { stdio: 'inherit', env });
|
|
250
|
+
process.exit(claudeProc.status || 0);
|
|
58
251
|
}
|
|
252
|
+
|
|
253
|
+
main().catch(e => { console.error(e); process.exit(1); });
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* xithead postinstall — auto-installs Python proxy dependencies
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
const { spawnSync } = require('child_process');
|
|
8
|
+
|
|
9
|
+
function findPython() {
|
|
10
|
+
for (const cmd of ['python', 'python3', 'py']) {
|
|
11
|
+
const r = spawnSync(cmd, ['--version'], { stdio: 'pipe' });
|
|
12
|
+
if (r.status === 0) return cmd;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const py = findPython();
|
|
18
|
+
if (!py) {
|
|
19
|
+
console.log('[xithead] Python nicht gefunden — überspringe Proxy-Setup.');
|
|
20
|
+
console.log(' Installiere Python von https://python.org und führe dann aus:');
|
|
21
|
+
console.log(' pip install "xithead[proxy]"');
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Check if proxy deps already installed
|
|
26
|
+
const check = spawnSync(py, ['-c', 'import fastapi, uvicorn, httpx'], { stdio: 'pipe' });
|
|
27
|
+
if (check.status === 0) {
|
|
28
|
+
console.log('[xithead] Proxy-Abhängigkeiten bereits installiert ✓');
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
console.log('[xithead] Installiere xithead[proxy] (fastapi + uvicorn + httpx)...');
|
|
33
|
+
const result = spawnSync(
|
|
34
|
+
py, ['-m', 'pip', 'install', '-q', '--upgrade', 'xithead[proxy]'],
|
|
35
|
+
{ stdio: 'inherit' }
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (result.status === 0) {
|
|
39
|
+
console.log('[xithead] Proxy-Abhängigkeiten erfolgreich installiert ✓');
|
|
40
|
+
} else {
|
|
41
|
+
console.log('[xithead] Hinweis: Proxy-Installation fehlgeschlagen.');
|
|
42
|
+
console.log(' Manuell: pip install "xithead[proxy]"');
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xithead",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Aggressive Claude context optimizer - Cut API costs by 50-95%. By Xtream-ITSolutions UG.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude",
|
|
@@ -34,9 +34,13 @@
|
|
|
34
34
|
"README.md",
|
|
35
35
|
"LICENSE"
|
|
36
36
|
],
|
|
37
|
+
"bundledDependencies": [],
|
|
37
38
|
"engines": {
|
|
38
39
|
"node": ">=18.0.0"
|
|
39
40
|
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"postinstall": "node npm/postinstall.js"
|
|
43
|
+
},
|
|
40
44
|
"dependencies": {
|
|
41
45
|
"node-fetch": "^3.3.2"
|
|
42
46
|
},
|