xithead 1.4.0 → 1.5.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 +108 -72
- package/app/api/config/route.ts +22 -0
- package/app/api/export/route.ts +83 -0
- package/app/api/models/route.ts +12 -0
- package/app/api/stats/route.ts +46 -0
- package/app/dashboard/page.tsx +445 -0
- package/app/globals.css +35 -0
- package/app/installation/page.tsx +293 -0
- package/app/layout.tsx +35 -0
- package/app/master-design-system.css +2076 -0
- package/app/master-design-system.source.css +8 -0
- package/app/page.tsx +187 -0
- package/app/rechtliches/agb/page.tsx +165 -0
- package/app/rechtliches/datenschutz/page.tsx +128 -0
- package/app/rechtliches/impressum/page.tsx +122 -0
- package/app/rechtliches/widerruf/page.tsx +185 -0
- package/bin/xithead.js +264 -0
- package/components/layout/AppShell.tsx +25 -0
- package/components/layout/Footer.tsx +120 -0
- package/components/layout/Header.tsx +145 -0
- package/components/marketing/LegalHighlights.tsx +45 -0
- package/components/marketing/LegalPageShell.tsx +49 -0
- package/components/marketing/LegalPanel.tsx +41 -0
- package/components/marketing/index.ts +3 -0
- package/design-system/README.md +80 -0
- package/design-system/base.css +127 -0
- package/design-system/components.css +1943 -0
- package/design-system/fonts.css +17 -0
- package/design-system/tailwind-preset.js +95 -0
- package/design-system/tokens.css +48 -0
- package/design-system/utilities.css +53 -0
- package/lib/config/index.ts +12 -0
- package/lib/hooks/index.ts +4 -0
- package/lib/hooks/use-mounted.ts +13 -0
- package/lib/hooks/use-session.ts +34 -0
- package/lib/hooks/use-settings.ts +49 -0
- package/lib/utils/index.ts +1 -0
- package/lib/utils/settings.ts +162 -0
- package/lib/utils/utils.ts +6 -0
- package/middleware.ts +26 -0
- package/next-env.d.ts +7 -0
- package/next.config.ts +12 -0
- package/package.json +77 -36
- package/postcss.config.mjs +7 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/logo-transparent.png +0 -0
- package/public/xithead.ps1 +937 -0
- package/scripts/README.md +77 -0
- package/scripts/audit_wheel_glibc_symbols.py +217 -0
- package/scripts/build-master-design-system.cjs +33 -0
- package/scripts/build_rust_extension.sh +58 -0
- package/scripts/changelog-gen.py +203 -0
- package/scripts/eval_output_shaper.py +235 -0
- package/scripts/export_kompress_v2_onnx.py +267 -0
- package/scripts/fixtures/anthropic_replay_body.json +133 -0
- package/scripts/fixtures/codex_response_create_frame.json +52 -0
- package/scripts/install-git-hooks.sh +104 -0
- package/scripts/install.ps1 +1809 -0
- package/scripts/install.sh +1673 -0
- package/scripts/pr-governance.py +297 -0
- package/scripts/record_fixtures.py +59 -0
- package/scripts/refresh_model_limits.sh +48 -0
- package/scripts/replay_codex_ws_load.py +445 -0
- package/scripts/repro_codex_replay.py +699 -0
- package/scripts/smoke_issue_327.py +233 -0
- package/scripts/sync-plugin-versions.py +116 -0
- package/scripts/tests/test_changelog_gen.py +302 -0
- package/scripts/tests/test_pr_governance.py +163 -0
- package/scripts/tests/test_pr_health_labels.py +94 -0
- package/scripts/tests/test_pr_health_workflow.py +14 -0
- package/scripts/tests/test_sync_plugin_versions.py +131 -0
- package/scripts/tests/test_version_sync.py +291 -0
- package/scripts/validate-workflows.sh +39 -0
- package/scripts/verify-versions.py +106 -0
- package/scripts/version-sync.py +207 -0
- package/tailwind.config.js +31 -0
- package/tailwind.master.config.cjs +47 -0
- package/tsconfig.json +84 -0
- package/types/api.ts +12 -0
- package/types/config.ts +9 -0
- package/types/index.ts +2 -0
- package/npm/bin/xithead.js +0 -366
- package/npm/index.d.ts +0 -57
- package/npm/index.js +0 -139
- package/npm/package.json +0 -54
- package/npm/postinstall.js +0 -43
package/npm/bin/xithead.js
DELETED
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* xithead CLI — Claude Context Optimizer
|
|
4
|
-
* by Xtream-ITSolutions UG | discord.gg/xtream-itsolutions
|
|
5
|
-
*/
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
const { spawnSync, spawn, execSync } = require('child_process');
|
|
9
|
-
const http = require('http');
|
|
10
|
-
const https = require('https');
|
|
11
|
-
const path = require('path');
|
|
12
|
-
const fs = require('fs');
|
|
13
|
-
|
|
14
|
-
const PKG_PATH = path.join(__dirname, '../../package.json');
|
|
15
|
-
const PKG_VERSION = (() => {
|
|
16
|
-
try { return require(PKG_PATH).version; } catch { return '1.2.0'; }
|
|
17
|
-
})();
|
|
18
|
-
|
|
19
|
-
const args = process.argv.slice(2);
|
|
20
|
-
const PROXY_PORT = 8787;
|
|
21
|
-
const PROXY_URL = `http://localhost:${PROXY_PORT}`;
|
|
22
|
-
|
|
23
|
-
// ── Update logic ──────────────────────────────────────────────────────────────
|
|
24
|
-
|
|
25
|
-
const UPDATE_CACHE = path.join(
|
|
26
|
-
process.env.APPDATA || process.env.HOME || require('os').homedir(),
|
|
27
|
-
'.xithead', 'last_update_check'
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
function shouldCheckUpdate() {
|
|
31
|
-
try {
|
|
32
|
-
const ts = parseInt(fs.readFileSync(UPDATE_CACHE, 'utf8').trim(), 10);
|
|
33
|
-
return Date.now() - ts > 6 * 60 * 60 * 1000; // once per 6h
|
|
34
|
-
} catch { return true; }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function markUpdateChecked() {
|
|
38
|
-
try {
|
|
39
|
-
fs.mkdirSync(path.dirname(UPDATE_CACHE), { recursive: true });
|
|
40
|
-
fs.writeFileSync(UPDATE_CACHE, String(Date.now()));
|
|
41
|
-
} catch {}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function fetchLatestNpmVersion() {
|
|
45
|
-
return new Promise(resolve => {
|
|
46
|
-
const req = https.get('https://registry.npmjs.org/xithead/latest', { timeout: 5000 }, res => {
|
|
47
|
-
let body = '';
|
|
48
|
-
res.on('data', d => body += d);
|
|
49
|
-
res.on('end', () => {
|
|
50
|
-
try { resolve(JSON.parse(body).version || null); } catch { resolve(null); }
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
req.on('error', () => resolve(null));
|
|
54
|
-
req.on('timeout', () => { req.destroy(); resolve(null); });
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function versionGt(a, b) {
|
|
59
|
-
const pa = a.split('.').map(Number);
|
|
60
|
-
const pb = b.split('.').map(Number);
|
|
61
|
-
for (let i = 0; i < 3; i++) {
|
|
62
|
-
if ((pa[i]||0) > (pb[i]||0)) return true;
|
|
63
|
-
if ((pa[i]||0) < (pb[i]||0)) return false;
|
|
64
|
-
}
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async function autoUpdate(py) {
|
|
69
|
-
if (!shouldCheckUpdate()) return;
|
|
70
|
-
markUpdateChecked();
|
|
71
|
-
|
|
72
|
-
const latest = await fetchLatestNpmVersion();
|
|
73
|
-
if (!latest || !versionGt(latest, PKG_VERSION)) {
|
|
74
|
-
// npm is up to date — still ensure Python pkg is current (silent)
|
|
75
|
-
if (py) {
|
|
76
|
-
spawn(py, ['-m', 'pip', 'install', '-q', '--upgrade', 'xithead[proxy]'], {
|
|
77
|
-
detached: true, stdio: 'ignore',
|
|
78
|
-
}).unref();
|
|
79
|
-
}
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// New npm version available — update in background
|
|
84
|
-
process.stdout.write(
|
|
85
|
-
`\x1b[33m [xithead] Update v${PKG_VERSION} → v${latest} wird installiert...\x1b[0m\n`
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
89
|
-
const up = spawn(
|
|
90
|
-
npmCmd,
|
|
91
|
-
['install', '-g', '--allow-scripts=xithead', `xithead@${latest}`],
|
|
92
|
-
{ detached: true, stdio: 'ignore' }
|
|
93
|
-
);
|
|
94
|
-
up.unref();
|
|
95
|
-
|
|
96
|
-
// Also update Python package
|
|
97
|
-
if (py) {
|
|
98
|
-
spawn(py, ['-m', 'pip', 'install', '-q', '--upgrade', 'xithead[proxy]'], {
|
|
99
|
-
detached: true, stdio: 'ignore',
|
|
100
|
-
}).unref();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
process.stdout.write(
|
|
104
|
-
`\x1b[32m [xithead] Update läuft im Hintergrund — beim nächsten Start aktiv.\x1b[0m\n`
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
109
|
-
|
|
110
|
-
function findPython() {
|
|
111
|
-
for (const cmd of ['python', 'python3', 'py']) {
|
|
112
|
-
const r = spawnSync(cmd, ['--version'], { stdio: 'pipe' });
|
|
113
|
-
if (r.status === 0) return cmd;
|
|
114
|
-
}
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function proxyAlive() {
|
|
119
|
-
return new Promise(resolve => {
|
|
120
|
-
const tryEndpoint = (p, cb) => {
|
|
121
|
-
const req = http.get(`${PROXY_URL}${p}`, { timeout: 3000 }, res => {
|
|
122
|
-
cb(res.statusCode === 200);
|
|
123
|
-
});
|
|
124
|
-
req.on('error', () => cb(false));
|
|
125
|
-
req.on('timeout', () => { req.destroy(); cb(false); });
|
|
126
|
-
};
|
|
127
|
-
tryEndpoint('/health', ok => {
|
|
128
|
-
if (ok) return resolve(true);
|
|
129
|
-
tryEndpoint('/api/stats', resolve);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function startProxy(py) {
|
|
135
|
-
const child = spawn(py, ['-m', 'xithead.cli.main', 'proxy', '--port', String(PROXY_PORT)], {
|
|
136
|
-
detached: true,
|
|
137
|
-
stdio: 'ignore',
|
|
138
|
-
windowsHide: true,
|
|
139
|
-
});
|
|
140
|
-
child.unref();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function waitForProxy(timeoutMs = 20000) {
|
|
144
|
-
return new Promise(async resolve => {
|
|
145
|
-
const deadline = Date.now() + timeoutMs;
|
|
146
|
-
while (Date.now() < deadline) {
|
|
147
|
-
if (await proxyAlive()) return resolve(true);
|
|
148
|
-
await new Promise(r => setTimeout(r, 400));
|
|
149
|
-
}
|
|
150
|
-
resolve(false);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function hasPythonXithead(py) {
|
|
155
|
-
const r = spawnSync(py, ['-c', 'import xithead'], { stdio: 'pipe' });
|
|
156
|
-
return r.status === 0;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function hasProxyDeps(py) {
|
|
160
|
-
const r = spawnSync(py, ['-c', 'import fastapi, uvicorn, httpx'], { stdio: 'pipe' });
|
|
161
|
-
return r.status === 0;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function installProxyDeps(py) {
|
|
165
|
-
process.stdout.write('\x1b[33m [xithead] Installiere Proxy-Abhängigkeiten...\x1b[0m\n');
|
|
166
|
-
const r = spawnSync(py, ['-m', 'pip', 'install', '-q', 'xithead[proxy]'], { stdio: 'inherit' });
|
|
167
|
-
return r.status === 0;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// ── Commands ──────────────────────────────────────────────────────────────────
|
|
171
|
-
|
|
172
|
-
function showBanner(proxyOk) {
|
|
173
|
-
const R = '\x1b[0m', B = '\x1b[1m';
|
|
174
|
-
const cyan = '\x1b[96m', cyanD = '\x1b[36m';
|
|
175
|
-
const green = '\x1b[92m', greenD = '\x1b[32m';
|
|
176
|
-
const yellow = '\x1b[93m';
|
|
177
|
-
const gray = '\x1b[90m';
|
|
178
|
-
const magenta = '\x1b[95m';
|
|
179
|
-
const white = '\x1b[97m';
|
|
180
|
-
|
|
181
|
-
const proxyLine = proxyOk
|
|
182
|
-
? `${green} ┃ ${greenD}Proxy ${green}${B}aktiv ✓${R}${green} http://localhost:${PROXY_PORT} ┃${R}`
|
|
183
|
-
: `${yellow} ┃ ${yellow}Proxy direkte Anthropic API (kein Proxy) ┃${R}`;
|
|
184
|
-
|
|
185
|
-
console.log('');
|
|
186
|
-
console.log(`${cyanD} ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓${R}`);
|
|
187
|
-
console.log(`${cyanD} ┃${R} ${B}${white}⚡ xithead${R} ${cyan}v${PKG_VERSION}${R} ${gray}by Xtream-ITSolutions UG${R} ${cyanD}┃${R}`);
|
|
188
|
-
console.log(`${cyanD} ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫${R}`);
|
|
189
|
-
console.log(`${cyanD} ┃${R} ${gray}Modus ${R}${magenta}${B}Ultra-Aggressiv (50–95% Einsparung)${R} ${cyanD}┃${R}`);
|
|
190
|
-
console.log(proxyLine);
|
|
191
|
-
console.log(`${cyanD} ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫${R}`);
|
|
192
|
-
if (proxyOk) {
|
|
193
|
-
console.log(`${cyanD} ┃${R} ${gray}Dashboard ${cyan}http://localhost:${PROXY_PORT}/dashboard${R} ${cyanD}┃${R}`);
|
|
194
|
-
}
|
|
195
|
-
console.log(`${cyanD} ┃${R} ${gray}Discord ${R}\x1b[34mdiscord.gg/xtream-itsolutions${R} ${cyanD}┃${R}`);
|
|
196
|
-
console.log(`${cyanD} ┃${R} ${gray}Web ${R}\x1b[34mxtream-itsolutions.com${R} ${cyanD}┃${R}`);
|
|
197
|
-
console.log(`${cyanD} ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛${R}`);
|
|
198
|
-
console.log('');
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function showHelp() {
|
|
202
|
-
const c = { cyan: '\x1b[36m', green: '\x1b[32m', gray: '\x1b[90m', reset: '\x1b[0m' };
|
|
203
|
-
console.log('');
|
|
204
|
-
console.log(`${c.cyan} xithead — Claude Context Optimizer${c.reset}`);
|
|
205
|
-
console.log(`${c.gray} by Xtream-ITSolutions UG${c.reset}`);
|
|
206
|
-
console.log('');
|
|
207
|
-
console.log(`${c.green} xithead${c.reset} Claude starten (Proxy auto, 50-95% Einsparung)`);
|
|
208
|
-
console.log(`${c.green} xithead proxy${c.reset} Proxy + Dashboard starten`);
|
|
209
|
-
console.log(`${c.green} xithead stats${c.reset} Token-Einsparungen anzeigen`);
|
|
210
|
-
console.log(`${c.green} xithead update${c.reset} Manuelles Update (npm + Python)`);
|
|
211
|
-
console.log(`${c.green} xithead help${c.reset} Diese Hilfe`);
|
|
212
|
-
console.log('');
|
|
213
|
-
console.log(`${c.gray} Dashboard: http://localhost:${PROXY_PORT}/dashboard${c.reset}`);
|
|
214
|
-
console.log(`${c.gray} Discord: discord.gg/xtream-itsolutions${c.reset}`);
|
|
215
|
-
console.log('');
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
async function showStats() {
|
|
219
|
-
return new Promise(resolve => {
|
|
220
|
-
const req = http.get(`${PROXY_URL}/api/stats`, { timeout: 3000 }, res => {
|
|
221
|
-
let body = '';
|
|
222
|
-
res.on('data', d => body += d);
|
|
223
|
-
res.on('end', () => {
|
|
224
|
-
try {
|
|
225
|
-
const s = JSON.parse(body);
|
|
226
|
-
const c = { cyan: '\x1b[36m', green: '\x1b[32m', gray: '\x1b[90m', reset: '\x1b[0m' };
|
|
227
|
-
console.log('');
|
|
228
|
-
console.log(`${c.cyan} ┌─────────────────────────────────────┐${c.reset}`);
|
|
229
|
-
console.log(`${c.cyan} │ xithead Statistiken │${c.reset}`);
|
|
230
|
-
console.log(`${c.cyan} ├─────────────────────────────────────┤${c.reset}`);
|
|
231
|
-
console.log(`${c.reset} │ Requests: ${String(s.session.requests).padEnd(19)}│${c.reset}`);
|
|
232
|
-
console.log(`${c.green} │ Tokens gespart: ${String(s.session.tokens_saved).padEnd(19)}│${c.reset}`);
|
|
233
|
-
console.log(`${c.green} │ Kosten gespart: $${String((s.session.cost_saved_usd||0).toFixed(4)).padEnd(18)}│${c.reset}`);
|
|
234
|
-
console.log(`${c.cyan} │ Cache-Hit-Rate: ${String(((s.session.cache_hit_rate||0)*100).toFixed(1)+'%').padEnd(19)}│${c.reset}`);
|
|
235
|
-
console.log(`${c.gray} │ Modell: ${String(s.model||'').padEnd(19)}│${c.reset}`);
|
|
236
|
-
console.log(`${c.cyan} └─────────────────────────────────────┘${c.reset}`);
|
|
237
|
-
} catch { console.log(' [xithead] Konnte Stats nicht parsen.'); }
|
|
238
|
-
resolve();
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
req.on('error', () => {
|
|
242
|
-
console.log('\x1b[33m [xithead] Proxy nicht erreichbar — starte mit: xithead\x1b[0m');
|
|
243
|
-
resolve();
|
|
244
|
-
});
|
|
245
|
-
req.on('timeout', () => { req.destroy(); resolve(); });
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
async function runManualUpdate(py) {
|
|
250
|
-
const c = { cyan: '\x1b[36m', green: '\x1b[32m', yellow: '\x1b[33m', reset: '\x1b[0m' };
|
|
251
|
-
console.log('');
|
|
252
|
-
console.log(`${c.cyan} [xithead] Prüfe auf Updates...${c.reset}`);
|
|
253
|
-
|
|
254
|
-
const latest = await fetchLatestNpmVersion();
|
|
255
|
-
if (latest && versionGt(latest, PKG_VERSION)) {
|
|
256
|
-
console.log(`${c.yellow} npm: v${PKG_VERSION} → v${latest}${c.reset}`);
|
|
257
|
-
const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
258
|
-
spawnSync(npmCmd, ['install', '-g', '--allow-scripts=xithead', `xithead@${latest}`], { stdio: 'inherit' });
|
|
259
|
-
console.log(`${c.green} npm xithead auf v${latest} aktualisiert ✓${c.reset}`);
|
|
260
|
-
} else {
|
|
261
|
-
console.log(`${c.green} npm xithead v${PKG_VERSION} — bereits aktuell ✓${c.reset}`);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (py) {
|
|
265
|
-
console.log(`${c.cyan} Python xithead[proxy] wird aktualisiert...${c.reset}`);
|
|
266
|
-
spawnSync(py, ['-m', 'pip', 'install', '-q', '--upgrade', 'xithead[proxy]'], { stdio: 'inherit' });
|
|
267
|
-
console.log(`${c.green} Python-Paket aktualisiert ✓${c.reset}`);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
markUpdateChecked();
|
|
271
|
-
console.log('');
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// ── Main ──────────────────────────────────────────────────────────────────────
|
|
275
|
-
|
|
276
|
-
async function main() {
|
|
277
|
-
const cmd = args[0];
|
|
278
|
-
|
|
279
|
-
if (cmd === 'help' || cmd === '--help' || cmd === '-h') {
|
|
280
|
-
showHelp();
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (cmd === 'stats') {
|
|
285
|
-
await showStats();
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const py = findPython();
|
|
290
|
-
|
|
291
|
-
if (cmd === 'update') {
|
|
292
|
-
await runManualUpdate(py);
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (cmd === 'proxy') {
|
|
297
|
-
if (!py || !hasPythonXithead(py)) {
|
|
298
|
-
console.error('\x1b[31m [xithead] Python-Paket nicht installiert.\x1b[0m');
|
|
299
|
-
console.error(' Installieren: pip install "xithead[proxy]"');
|
|
300
|
-
process.exit(1);
|
|
301
|
-
}
|
|
302
|
-
console.log(`\x1b[36m [xithead] Proxy auf Port ${PROXY_PORT} | Ctrl+C zum Stoppen\x1b[0m`);
|
|
303
|
-
console.log(`\x1b[32m [xithead] Dashboard: ${PROXY_URL}/dashboard\x1b[0m`);
|
|
304
|
-
const child = spawnSync(py, ['-m', 'xithead.cli.main', 'proxy', '--port', String(PROXY_PORT), '--verbose'], { stdio: 'inherit' });
|
|
305
|
-
process.exit(child.status || 0);
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Default: launch Claude with proxy
|
|
310
|
-
// Kick off background auto-update check (non-blocking)
|
|
311
|
-
const updatePromise = autoUpdate(py);
|
|
312
|
-
|
|
313
|
-
let proxyOk = await proxyAlive();
|
|
314
|
-
|
|
315
|
-
if (!proxyOk && py && hasPythonXithead(py)) {
|
|
316
|
-
if (!hasProxyDeps(py)) {
|
|
317
|
-
const ok = installProxyDeps(py);
|
|
318
|
-
if (!ok) {
|
|
319
|
-
console.log('\x1b[31m [xithead] Proxy-Abhängigkeiten konnten nicht installiert werden.\x1b[0m');
|
|
320
|
-
console.log(' Manuell: pip install "xithead[proxy]"');
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
process.stdout.write('\x1b[33m [xithead] Proxy startet...\x1b[0m');
|
|
324
|
-
startProxy(py);
|
|
325
|
-
proxyOk = await waitForProxy(20000);
|
|
326
|
-
if (!proxyOk) {
|
|
327
|
-
proxyOk = await proxyAlive();
|
|
328
|
-
}
|
|
329
|
-
process.stdout.write(proxyOk ? ' \x1b[32mbereit!\x1b[0m\n' : ' \x1b[33mTimeout — direkte API\x1b[0m\n');
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
showBanner(proxyOk);
|
|
333
|
-
|
|
334
|
-
// Wait for update check to finish (it's fast, already running)
|
|
335
|
-
await updatePromise;
|
|
336
|
-
|
|
337
|
-
const env = {
|
|
338
|
-
...process.env,
|
|
339
|
-
CLAUDE_CODE_MAX_OUTPUT_TOKENS: '16000',
|
|
340
|
-
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1',
|
|
341
|
-
XITHEAD_ENABLE_CACHE_CONTROL: '1',
|
|
342
|
-
XITHEAD_ENABLE_DEDUP: '1',
|
|
343
|
-
XITHEAD_ENABLE_CONTEXT_TRIM: '1',
|
|
344
|
-
HEADROOM_STRENGTH: 'aggressive',
|
|
345
|
-
HEADROOM_COMPRESSION_RATIO_TARGET: '0.3',
|
|
346
|
-
};
|
|
347
|
-
// Claude Code haengt /v1/... selbst an — Basis-URL daher OHNE /v1 (wie upstream headroom)
|
|
348
|
-
if (proxyOk) {
|
|
349
|
-
env.ANTHROPIC_BASE_URL = PROXY_URL;
|
|
350
|
-
} else {
|
|
351
|
-
delete env.ANTHROPIC_BASE_URL; // direkte Anthropic-API, Claude nutzt seinen Default
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
const claudeResult = spawnSync(process.platform === 'win32' ? 'where' : 'which', ['claude'], { stdio: 'pipe' });
|
|
355
|
-
if (claudeResult.status !== 0) {
|
|
356
|
-
console.error('\x1b[31m [xithead] Claude Code nicht gefunden. Installieren:\x1b[0m');
|
|
357
|
-
console.error(' npm install -g @anthropic-ai/claude-code');
|
|
358
|
-
process.exit(1);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
const claudeArgs = args.length > 0 ? args : [];
|
|
362
|
-
const claudeProc = spawnSync('claude', claudeArgs, { stdio: 'inherit', env });
|
|
363
|
-
process.exit(claudeProc.status || 0);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
main().catch(e => { console.error(e); process.exit(1); });
|
package/npm/index.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* xithead - Claude Context Optimizer
|
|
3
|
-
* by Xtream-ITSolutions UG
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export interface Message {
|
|
7
|
-
role: 'user' | 'assistant';
|
|
8
|
-
content: string | ContentBlock[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface ContentBlock {
|
|
12
|
-
type: 'text' | 'image' | 'tool_use' | 'tool_result';
|
|
13
|
-
text?: string;
|
|
14
|
-
cache_control?: { type: 'ephemeral' };
|
|
15
|
-
[key: string]: unknown;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface OptimizeOptions {
|
|
19
|
-
messages: Message[];
|
|
20
|
-
system?: string | ContentBlock[];
|
|
21
|
-
model?: string;
|
|
22
|
-
enableCacheControl?: boolean;
|
|
23
|
-
enableDedup?: boolean;
|
|
24
|
-
enableSystemCompress?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface OptimizeResult {
|
|
28
|
-
messages: Message[];
|
|
29
|
-
system?: string | ContentBlock[];
|
|
30
|
-
tokensSaved: number;
|
|
31
|
-
costSavedUsd: number;
|
|
32
|
-
compressionRatio: number;
|
|
33
|
-
techniquesApplied: string[];
|
|
34
|
-
model: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface XitheadStats {
|
|
38
|
-
requests: number;
|
|
39
|
-
tokensSaved: number;
|
|
40
|
-
costSavedUsd: number;
|
|
41
|
-
avgTokensSaved: number;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function optimize(options: OptimizeOptions): OptimizeResult;
|
|
45
|
-
export function injectCacheControl(messages: Message[], system?: string | ContentBlock[], minTokens?: number): { messages: Message[]; system?: string | ContentBlock[] };
|
|
46
|
-
export function dedupMessages(messages: Message[]): { messages: Message[]; changed: boolean };
|
|
47
|
-
export function estimateTokens(text: string): number;
|
|
48
|
-
export function createOptimizedClient(anthropicClient: unknown): {
|
|
49
|
-
messages: {
|
|
50
|
-
create(params: Record<string, unknown>): Promise<unknown>;
|
|
51
|
-
stream(params: Record<string, unknown>): unknown;
|
|
52
|
-
};
|
|
53
|
-
getStats(): XitheadStats;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const CLAUDE_INPUT_COST_PER_TOKEN: number;
|
|
57
|
-
export const CLAUDE_CACHE_READ_COST: number;
|
package/npm/index.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* xtream-head — Claude Code Proxy
|
|
3
|
-
* by Xtream-ITSolutions UG | xtream-head.com
|
|
4
|
-
*/
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
|
-
const CLAUDE_INPUT_COST_PER_TOKEN = 3e-6;
|
|
8
|
-
const CLAUDE_CACHE_READ_COST = 0.30e-6;
|
|
9
|
-
|
|
10
|
-
function estimateTokens(text) {
|
|
11
|
-
return Math.ceil(text.length / 4);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function injectCacheControl(messages, system, minTokens = 1024) {
|
|
15
|
-
let optimizedSystem = system;
|
|
16
|
-
let optimizedMessages = [...messages];
|
|
17
|
-
|
|
18
|
-
if (typeof system === 'string' && estimateTokens(system) >= minTokens) {
|
|
19
|
-
optimizedSystem = [{ type: 'text', text: system, cache_control: { type: 'ephemeral' } }];
|
|
20
|
-
} else if (Array.isArray(system)) {
|
|
21
|
-
optimizedSystem = system.map((block, i) => {
|
|
22
|
-
if (block.type === 'text' && estimateTokens(block.text || '') >= minTokens && i === system.length - 1) {
|
|
23
|
-
return { ...block, cache_control: { type: 'ephemeral' } };
|
|
24
|
-
}
|
|
25
|
-
return block;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
for (let i = optimizedMessages.length - 1; i >= 0; i--) {
|
|
30
|
-
const msg = optimizedMessages[i];
|
|
31
|
-
if (msg.role === 'user') {
|
|
32
|
-
const content = msg.content;
|
|
33
|
-
if (typeof content === 'string' && estimateTokens(content) >= minTokens) {
|
|
34
|
-
optimizedMessages[i] = {
|
|
35
|
-
...msg,
|
|
36
|
-
content: [{ type: 'text', text: content, cache_control: { type: 'ephemeral' } }]
|
|
37
|
-
};
|
|
38
|
-
} else if (Array.isArray(content)) {
|
|
39
|
-
optimizedMessages[i] = {
|
|
40
|
-
...msg,
|
|
41
|
-
content: content.map((block, j) => {
|
|
42
|
-
const text = block.text || block.content || '';
|
|
43
|
-
if (estimateTokens(String(text)) >= minTokens && j === content.length - 1) {
|
|
44
|
-
return { ...block, cache_control: { type: 'ephemeral' } };
|
|
45
|
-
}
|
|
46
|
-
return block;
|
|
47
|
-
}),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return { messages: optimizedMessages, system: optimizedSystem };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function dedupMessages(messages) {
|
|
58
|
-
if (messages.length < 2) return { messages, changed: false };
|
|
59
|
-
const result = [messages[0]];
|
|
60
|
-
let changed = false;
|
|
61
|
-
for (let i = 1; i < messages.length; i++) {
|
|
62
|
-
const cur = messages[i];
|
|
63
|
-
const prev = result[result.length - 1];
|
|
64
|
-
if (cur.role === prev.role && JSON.stringify(cur.content) === JSON.stringify(prev.content)) {
|
|
65
|
-
changed = true;
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
result.push(cur);
|
|
69
|
-
}
|
|
70
|
-
return { messages: result, changed };
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function optimize({ messages, system, model = 'claude-sonnet-4-6', enableCacheControl = true, enableDedup = true } = {}) {
|
|
74
|
-
const techniques = [];
|
|
75
|
-
let msgs = [...messages];
|
|
76
|
-
let sys = system;
|
|
77
|
-
|
|
78
|
-
const originalTokens = estimateTokens(JSON.stringify(msgs) + JSON.stringify(sys || ''));
|
|
79
|
-
|
|
80
|
-
if (enableDedup) {
|
|
81
|
-
const { messages: deduped, changed } = dedupMessages(msgs);
|
|
82
|
-
if (changed) { msgs = deduped; techniques.push('dedup'); }
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (enableCacheControl) {
|
|
86
|
-
const result = injectCacheControl(msgs, sys);
|
|
87
|
-
msgs = result.messages;
|
|
88
|
-
sys = result.system;
|
|
89
|
-
techniques.push('cache_control');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const optimizedTokens = estimateTokens(JSON.stringify(msgs) + JSON.stringify(sys || ''));
|
|
93
|
-
const tokensSaved = Math.max(0, originalTokens - optimizedTokens);
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
messages: msgs,
|
|
97
|
-
system: sys,
|
|
98
|
-
tokensSaved,
|
|
99
|
-
costSavedUsd: tokensSaved * CLAUDE_INPUT_COST_PER_TOKEN,
|
|
100
|
-
compressionRatio: originalTokens > 0 ? tokensSaved / originalTokens : 0,
|
|
101
|
-
techniquesApplied: techniques,
|
|
102
|
-
model,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function createOptimizedClient(anthropicClient) {
|
|
107
|
-
const stats = { requests: 0, tokensSaved: 0, costSavedUsd: 0 };
|
|
108
|
-
return {
|
|
109
|
-
messages: {
|
|
110
|
-
create(params) {
|
|
111
|
-
const result = optimize({ messages: params.messages || [], system: params.system, model: params.model });
|
|
112
|
-
stats.requests++;
|
|
113
|
-
stats.tokensSaved += result.tokensSaved;
|
|
114
|
-
stats.costSavedUsd += result.costSavedUsd;
|
|
115
|
-
return anthropicClient.messages.create({ ...params, messages: result.messages, system: result.system });
|
|
116
|
-
},
|
|
117
|
-
stream(params) {
|
|
118
|
-
const result = optimize({ messages: params.messages || [], system: params.system, model: params.model });
|
|
119
|
-
stats.requests++;
|
|
120
|
-
stats.tokensSaved += result.tokensSaved;
|
|
121
|
-
stats.costSavedUsd += result.costSavedUsd;
|
|
122
|
-
return anthropicClient.messages.stream({ ...params, messages: result.messages, system: result.system });
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
getStats() {
|
|
126
|
-
return { ...stats, avgTokensSaved: stats.requests > 0 ? stats.tokensSaved / stats.requests : 0 };
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
module.exports = {
|
|
132
|
-
optimize,
|
|
133
|
-
createOptimizedClient,
|
|
134
|
-
injectCacheControl,
|
|
135
|
-
dedupMessages,
|
|
136
|
-
estimateTokens,
|
|
137
|
-
CLAUDE_INPUT_COST_PER_TOKEN,
|
|
138
|
-
CLAUDE_CACHE_READ_COST,
|
|
139
|
-
};
|
package/npm/package.json
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "xithead",
|
|
3
|
-
"version": "1.4.0",
|
|
4
|
-
"description": "Lokaler Claude Code Proxy — Prompt Cache maximieren, Token-Kosten bis zu 88% reduzieren. By Xtream-ITSolutions UG.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"claude",
|
|
7
|
-
"anthropic",
|
|
8
|
-
"llm",
|
|
9
|
-
"token",
|
|
10
|
-
"optimization",
|
|
11
|
-
"caching",
|
|
12
|
-
"proxy",
|
|
13
|
-
"context",
|
|
14
|
-
"ai",
|
|
15
|
-
"cost-reduction",
|
|
16
|
-
"claude-code"
|
|
17
|
-
],
|
|
18
|
-
"author": "Xtream-ITSolutions UG <hello@xtream-itsolutions.com>",
|
|
19
|
-
"license": "Apache-2.0",
|
|
20
|
-
"homepage": "https://xtream-head.com",
|
|
21
|
-
"repository": {
|
|
22
|
-
"type": "git",
|
|
23
|
-
"url": "git+https://github.com/xtream-itsolutions/xithead.git"
|
|
24
|
-
},
|
|
25
|
-
"bugs": {
|
|
26
|
-
"url": "https://github.com/xtream-itsolutions/xithead/issues"
|
|
27
|
-
},
|
|
28
|
-
"bin": {
|
|
29
|
-
"xithead": "./bin/xithead.js"
|
|
30
|
-
},
|
|
31
|
-
"files": [
|
|
32
|
-
"index.js",
|
|
33
|
-
"index.d.ts",
|
|
34
|
-
"bin/",
|
|
35
|
-
"config/",
|
|
36
|
-
"utils/"
|
|
37
|
-
],
|
|
38
|
-
"type": "module",
|
|
39
|
-
"engines": {
|
|
40
|
-
"node": ">=18.0.0"
|
|
41
|
-
},
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"chalk": "^5.3.0",
|
|
44
|
-
"dotenv": "^16.4.5",
|
|
45
|
-
"yargs": "^17.7.2"
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@types/node": "^22.0.0"
|
|
49
|
-
},
|
|
50
|
-
"publishConfig": {
|
|
51
|
-
"access": "public",
|
|
52
|
-
"registry": "https://registry.npmjs.org/"
|
|
53
|
-
}
|
|
54
|
-
}
|
package/npm/postinstall.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
}
|