xithead 1.1.0 → 1.1.2

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.
@@ -7,6 +7,11 @@
7
7
 
8
8
  const { spawnSync, spawn } = require('child_process');
9
9
  const http = require('http');
10
+ const path = require('path');
11
+
12
+ const PKG_VERSION = (() => {
13
+ try { return require(path.join(__dirname, '../../package.json')).version; } catch { return '1.1.0'; }
14
+ })();
10
15
 
11
16
  const args = process.argv.slice(2);
12
17
  const PROXY_PORT = 8787;
@@ -23,25 +28,32 @@ function findPython() {
23
28
  }
24
29
 
25
30
  function proxyAlive() {
31
+ // Try /health first (fast), fall back to /api/stats
26
32
  return new Promise(resolve => {
27
- const req = http.get(`${PROXY_URL}/api/stats`, { timeout: 1500 }, res => {
28
- resolve(res.statusCode === 200);
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);
29
43
  });
30
- req.on('error', () => resolve(false));
31
- req.on('timeout', () => { req.destroy(); resolve(false); });
32
44
  });
33
45
  }
34
46
 
35
47
  function startProxy(py) {
36
- // Start Python proxy in background (detached, no output)
37
48
  const child = spawn(py, ['-m', 'xithead.cli.main', 'proxy', '--port', String(PROXY_PORT)], {
38
49
  detached: true,
39
50
  stdio: 'ignore',
51
+ windowsHide: true, // prevent flash window on Windows
40
52
  });
41
53
  child.unref();
42
54
  }
43
55
 
44
- function waitForProxy(timeoutMs = 8000) {
56
+ function waitForProxy(timeoutMs = 20000) {
45
57
  return new Promise(async resolve => {
46
58
  const deadline = Date.now() + timeoutMs;
47
59
  while (Date.now() < deadline) {
@@ -57,30 +69,46 @@ function hasPythonXithead(py) {
57
69
  return r.status === 0;
58
70
  }
59
71
 
72
+ function hasProxyDeps(py) {
73
+ const r = spawnSync(py, ['-c', 'import fastapi, uvicorn, httpx'], { stdio: 'pipe' });
74
+ return r.status === 0;
75
+ }
76
+
77
+ function installProxyDeps(py) {
78
+ process.stdout.write('\x1b[33m [xithead] Installiere Proxy-Abhängigkeiten...\x1b[0m\n');
79
+ const r = spawnSync(py, ['-m', 'pip', 'install', '-q', 'xithead[proxy]'], { stdio: 'inherit' });
80
+ return r.status === 0;
81
+ }
82
+
60
83
  // ── Commands ──────────────────────────────────────────────────────────────────
61
84
 
62
85
  function showBanner(proxyOk) {
63
- const c = {
64
- cyan: '\x1b[36m',
65
- green: '\x1b[32m',
66
- magenta: '\x1b[35m',
67
- gray: '\x1b[90m',
68
- yellow: '\x1b[33m',
69
- reset: '\x1b[0m',
70
- };
86
+ const R = '\x1b[0m', B = '\x1b[1m';
87
+ const cyan = '\x1b[96m', cyanD = '\x1b[36m';
88
+ const green = '\x1b[92m', greenD = '\x1b[32m';
89
+ const yellow = '\x1b[93m';
90
+ const gray = '\x1b[90m';
91
+ const magenta = '\x1b[95m';
92
+ const white = '\x1b[97m';
93
+
94
+ const proxyLine = proxyOk
95
+ ? `${green} ┃ ${greenD}Proxy ${green}${B}aktiv ✓${R}${green} http://localhost:${PROXY_PORT}/v1 ┃${R}`
96
+ : `${yellow} ┃ ${yellow}Proxy direkte Anthropic API (kein Proxy) ┃${R}`;
97
+
71
98
  console.log('');
72
- console.log(`${c.cyan} ╔═══════════════════════════════════════════╗${c.reset}`);
73
- console.log(`${c.cyan} ║ Xtream-ITSolutions — xithead v1.0.0 ║${c.reset}`);
74
- console.log(`${c.cyan} ║ discord.gg/xtream-itsolutions ║${c.reset}`);
75
- console.log(`${c.cyan} ╠═══════════════════════════════════════════╣${c.reset}`);
76
- console.log(`${c.green} ║ Modell: claude-sonnet-4-6 ║${c.reset}`);
77
- console.log(`${c.magenta} ║ Modus: Ultra-Aggressiv (50-95%) ║${c.reset}`);
99
+ console.log(`${cyanD} ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓${R}`);
100
+ console.log(`${cyanD} ┃${R} ${B}${white}⚡ xithead${R} ${cyan}v${PKG_VERSION}${R} ${gray}by Xtream-ITSolutions UG${R} ${cyanD}┃${R}`);
101
+ console.log(`${cyanD} ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫${R}`);
102
+ console.log(`${cyanD} ┃${R} ${gray}Modell ${R}${green}${B}claude-sonnet-4-6${R} ${cyanD}┃${R}`);
103
+ console.log(`${cyanD} ┃${R} ${gray}Modus ${R}${magenta}${B}Ultra-Aggressiv (50–95% Einsparung)${R} ${cyanD}┃${R}`);
104
+ console.log(proxyLine);
105
+ console.log(`${cyanD} ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫${R}`);
78
106
  if (proxyOk) {
79
- console.log(`${c.green} ║ Proxy: http://localhost:${PROXY_PORT}/v1 ✓ ║${c.reset}`);
80
- } else {
81
- console.log(`${c.yellow} ║ Proxy: nicht erreichbar — direkter API ║${c.reset}`);
107
+ console.log(`${cyanD} ┃${R} ${gray}Dashboard ${cyan}http://localhost:${PROXY_PORT}/dashboard${R} ${cyanD}┃${R}`);
82
108
  }
83
- console.log(`${c.cyan} ╚═══════════════════════════════════════════╝${c.reset}`);
109
+ console.log(`${cyanD} ┃${R} ${gray}Discord ${R}\x1b[34mdiscord.gg/xtream-itsolutions${R} ${cyanD}┃${R}`);
110
+ console.log(`${cyanD} ┃${R} ${gray}Web ${R}\x1b[34mxtream-itsolutions.com${R} ${cyanD}┃${R}`);
111
+ console.log(`${cyanD} ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛${R}`);
84
112
  console.log('');
85
113
  }
86
114
 
@@ -165,10 +193,22 @@ async function main() {
165
193
  let proxyOk = await proxyAlive();
166
194
 
167
195
  if (!proxyOk && py && hasPythonXithead(py)) {
196
+ // Auto-install proxy deps if missing
197
+ if (!hasProxyDeps(py)) {
198
+ const ok = installProxyDeps(py);
199
+ if (!ok) {
200
+ console.log('\x1b[31m [xithead] Proxy-Abhängigkeiten konnten nicht installiert werden.\x1b[0m');
201
+ console.log(' Manuell: pip install "xithead[proxy]"');
202
+ }
203
+ }
168
204
  process.stdout.write('\x1b[33m [xithead] Proxy startet...\x1b[0m');
169
205
  startProxy(py);
170
- proxyOk = await waitForProxy();
171
- process.stdout.write(proxyOk ? ' \x1b[32mbereit!\x1b[0m\n' : ' \x1b[33mTimeout\x1b[0m\n');
206
+ proxyOk = await waitForProxy(20000);
207
+ if (!proxyOk) {
208
+ // Port may already be in use from a previous run — check once more
209
+ proxyOk = await proxyAlive();
210
+ }
211
+ process.stdout.write(proxyOk ? ' \x1b[32mbereit!\x1b[0m\n' : ' \x1b[33mTimeout — direkte API\x1b[0m\n');
172
212
  }
173
213
 
174
214
  showBanner(proxyOk);
@@ -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.1.0",
3
+ "version": "1.1.2",
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
  },