squeezr-ai 1.16.1 → 1.16.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.
- package/bin/squeezr.js +70 -13
- package/package.json +1 -1
package/bin/squeezr.js
CHANGED
|
@@ -16,6 +16,15 @@ const pkg = require(path.join(ROOT, 'package.json'))
|
|
|
16
16
|
const args = process.argv.slice(2)
|
|
17
17
|
const command = args[0]
|
|
18
18
|
|
|
19
|
+
function getPortFromToml() {
|
|
20
|
+
try {
|
|
21
|
+
const toml = fs.readFileSync(path.join(ROOT, 'squeezr.toml'), 'utf-8')
|
|
22
|
+
const m = toml.match(/^port\s*=\s*(\d+)/m)
|
|
23
|
+
if (m) return parseInt(m[1])
|
|
24
|
+
} catch {}
|
|
25
|
+
return null
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
function getMitmPort(port) {
|
|
20
29
|
const envMitm = process.env.SQUEEZR_MITM_PORT
|
|
21
30
|
if (envMitm) return parseInt(envMitm)
|
|
@@ -27,6 +36,10 @@ function getMitmPort(port) {
|
|
|
27
36
|
return Number(port) + 1
|
|
28
37
|
}
|
|
29
38
|
|
|
39
|
+
function getPort() {
|
|
40
|
+
return process.env.SQUEEZR_PORT || getPortFromToml() || 8080
|
|
41
|
+
}
|
|
42
|
+
|
|
30
43
|
const HELP = `
|
|
31
44
|
Squeezr v${pkg.version} — AI context compressor for Claude Code, Codex, Aider, Gemini CLI and Ollama
|
|
32
45
|
|
|
@@ -68,7 +81,7 @@ async function startDaemon() {
|
|
|
68
81
|
}
|
|
69
82
|
|
|
70
83
|
// Check if already running — and if the version matches
|
|
71
|
-
const port =
|
|
84
|
+
const port = getPort()
|
|
72
85
|
const runningVersion = await new Promise(resolve => {
|
|
73
86
|
const req = http.get(`http://localhost:${port}/squeezr/health`, res => {
|
|
74
87
|
let data = ''
|
|
@@ -134,7 +147,7 @@ function showLogs() {
|
|
|
134
147
|
}
|
|
135
148
|
|
|
136
149
|
function stopProxy() {
|
|
137
|
-
const port =
|
|
150
|
+
const port = getPort()
|
|
138
151
|
const mitmPort = getMitmPort(port)
|
|
139
152
|
const ports = [port, mitmPort]
|
|
140
153
|
let killed = false
|
|
@@ -179,7 +192,7 @@ function stopProxy() {
|
|
|
179
192
|
}
|
|
180
193
|
|
|
181
194
|
async function checkStatus() {
|
|
182
|
-
const port =
|
|
195
|
+
const port = getPort()
|
|
183
196
|
const mitmPort = getMitmPort(port)
|
|
184
197
|
return new Promise(resolve => {
|
|
185
198
|
const req = http.get(`http://localhost:${port}/squeezr/health`, res => {
|
|
@@ -284,15 +297,59 @@ async function configurePorts() {
|
|
|
284
297
|
try { execSync(`setx HTTPS_PROXY "http://localhost:${finalMitm}"`, { stdio: 'pipe' }) } catch {}
|
|
285
298
|
console.log('Environment variables updated. Restart your terminal for changes to take effect.')
|
|
286
299
|
} else {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
300
|
+
// Update shell profiles directly
|
|
301
|
+
const profiles = [
|
|
302
|
+
path.join(os.homedir(), '.zshrc'),
|
|
303
|
+
path.join(os.homedir(), '.bashrc'),
|
|
304
|
+
path.join(os.homedir(), '.bash_profile'),
|
|
305
|
+
]
|
|
306
|
+
const envBlock = [
|
|
307
|
+
`export SQUEEZR_PORT=${finalPort}`,
|
|
308
|
+
`export SQUEEZR_MITM_PORT=${finalMitm}`,
|
|
309
|
+
`export ANTHROPIC_BASE_URL=http://localhost:${finalPort}`,
|
|
310
|
+
`export GEMINI_API_BASE_URL=http://localhost:${finalPort}`,
|
|
311
|
+
`export HTTPS_PROXY=http://localhost:${finalMitm}`,
|
|
312
|
+
].join('\n')
|
|
313
|
+
for (const p of profiles) {
|
|
314
|
+
try {
|
|
315
|
+
let content = fs.readFileSync(p, 'utf-8')
|
|
316
|
+
if (content.includes('# squeezr env vars')) {
|
|
317
|
+
// Replace existing block (from marker to the closing fi)
|
|
318
|
+
content = content.replace(
|
|
319
|
+
/# squeezr env vars[\s\S]*?fi/,
|
|
320
|
+
`# squeezr env vars\n${envBlock}\n# squeezr auto-heal\nif ! curl -sf http://localhost:${finalPort}/squeezr/health > /dev/null 2>&1; then squeezr start > /dev/null 2>&1; fi`
|
|
321
|
+
)
|
|
322
|
+
fs.writeFileSync(p, content)
|
|
323
|
+
console.log(` [ok] Updated ${p}`)
|
|
324
|
+
}
|
|
325
|
+
} catch {}
|
|
326
|
+
}
|
|
327
|
+
// Also update env for WSL setx if on WSL
|
|
328
|
+
try {
|
|
329
|
+
const procVersion = fs.readFileSync('/proc/version', 'utf-8')
|
|
330
|
+
if (/microsoft|wsl/i.test(procVersion)) {
|
|
331
|
+
const setx = '/mnt/c/Windows/System32/setx.exe'
|
|
332
|
+
try { execSync(`"${setx}" SQUEEZR_PORT "${finalPort}"`, { stdio: 'pipe' }) } catch {}
|
|
333
|
+
try { execSync(`"${setx}" SQUEEZR_MITM_PORT "${finalMitm}"`, { stdio: 'pipe' }) } catch {}
|
|
334
|
+
try { execSync(`"${setx}" ANTHROPIC_BASE_URL "http://localhost:${finalPort}"`, { stdio: 'pipe' }) } catch {}
|
|
335
|
+
try { execSync(`"${setx}" GEMINI_API_BASE_URL "http://localhost:${finalPort}"`, { stdio: 'pipe' }) } catch {}
|
|
336
|
+
try { execSync(`"${setx}" HTTPS_PROXY "http://localhost:${finalMitm}"`, { stdio: 'pipe' }) } catch {}
|
|
337
|
+
}
|
|
338
|
+
} catch {}
|
|
292
339
|
}
|
|
293
340
|
|
|
294
|
-
|
|
295
|
-
|
|
341
|
+
// Apply to current process so stop/start works immediately
|
|
342
|
+
process.env.SQUEEZR_PORT = String(finalPort)
|
|
343
|
+
process.env.SQUEEZR_MITM_PORT = String(finalMitm)
|
|
344
|
+
process.env.ANTHROPIC_BASE_URL = `http://localhost:${finalPort}`
|
|
345
|
+
process.env.HTTPS_PROXY = `http://localhost:${finalMitm}`
|
|
346
|
+
|
|
347
|
+
// Auto stop + start
|
|
348
|
+
console.log('')
|
|
349
|
+
stopProxy()
|
|
350
|
+
await new Promise(r => setTimeout(r, 1500))
|
|
351
|
+
await startDaemon()
|
|
352
|
+
console.log(`\nOpen a new terminal for env vars to apply to other tools.`)
|
|
296
353
|
}
|
|
297
354
|
|
|
298
355
|
// ── squeezr uninstall ─────────────────────────────────────────────────────────
|
|
@@ -393,7 +450,7 @@ function setupWindows() {
|
|
|
393
450
|
console.log('Setting up Squeezr for Windows...\n')
|
|
394
451
|
|
|
395
452
|
// 1. Set env vars permanently via setx (user scope, no admin needed)
|
|
396
|
-
const port =
|
|
453
|
+
const port = getPort()
|
|
397
454
|
const mitmPort = getMitmPort(port)
|
|
398
455
|
const caPath = path.join(os.homedir(), '.squeezr', 'mitm-ca', 'ca.crt')
|
|
399
456
|
const vars = {
|
|
@@ -548,7 +605,7 @@ function setupUnix() {
|
|
|
548
605
|
|
|
549
606
|
// 1. Set env vars + auto-heal guard in shell profile
|
|
550
607
|
const distIndex = path.join(ROOT, 'dist', 'index.js')
|
|
551
|
-
const port =
|
|
608
|
+
const port = getPort()
|
|
552
609
|
const mitmPort = getMitmPort(port)
|
|
553
610
|
const bundlePath = path.join(os.homedir(), '.squeezr', 'mitm-ca', 'bundle.crt')
|
|
554
611
|
const shellBlock = [
|
|
@@ -681,7 +738,7 @@ function setupWSL() {
|
|
|
681
738
|
// The guard checks if the proxy is alive on terminal open. If not, it starts
|
|
682
739
|
// it in the background. This is the safety net for WSL2 where systemd and
|
|
683
740
|
// Task Scheduler may both fail.
|
|
684
|
-
const port =
|
|
741
|
+
const port = getPort()
|
|
685
742
|
const mitmPort = getMitmPort(port)
|
|
686
743
|
const bundlePath = path.join(os.homedir(), '.squeezr', 'mitm-ca', 'bundle.crt')
|
|
687
744
|
const shellBlock = [
|
package/package.json
CHANGED