squeez 0.2.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.js +50 -0
- package/install.js +165 -0
- package/package.json +37 -0
package/bin.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/**
|
|
4
|
+
* bin.js — CLI entry point for the squeez npm package.
|
|
5
|
+
* Delegates all arguments to the native binary at ~/.claude/squeez/bin/squeez.
|
|
6
|
+
* Auto-installs if the binary is missing (e.g. after `npx squeez`).
|
|
7
|
+
*/
|
|
8
|
+
const { execFileSync, execSync } = require('child_process');
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const os = require('os');
|
|
12
|
+
|
|
13
|
+
const BINARY = path.join(
|
|
14
|
+
os.homedir(), '.claude', 'squeez', 'bin',
|
|
15
|
+
process.platform === 'win32' ? 'squeez.exe' : 'squeez'
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
if (!fs.existsSync(BINARY)) {
|
|
19
|
+
process.stderr.write('squeez: binary not found — running installer...\n');
|
|
20
|
+
if (process.platform === 'win32') {
|
|
21
|
+
process.stderr.write('squeez: on Windows, download from https://github.com/claudioemmanuel/squeez/releases\n');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
execSync(
|
|
26
|
+
'curl -fsSL https://raw.githubusercontent.com/claudioemmanuel/squeez/main/install.sh | sh',
|
|
27
|
+
{ stdio: 'inherit' }
|
|
28
|
+
);
|
|
29
|
+
} catch (_) {
|
|
30
|
+
// If curl failed, try running install.js alongside this file
|
|
31
|
+
try {
|
|
32
|
+
require(path.join(__dirname, 'install.js'));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
process.stderr.write(`squeez: installation failed: ${e.message}\n`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!fs.existsSync(BINARY)) {
|
|
41
|
+
process.stderr.write('squeez: binary still not found after install attempt.\n');
|
|
42
|
+
process.stderr.write('Run manually: curl -fsSL https://raw.githubusercontent.com/claudioemmanuel/squeez/main/install.sh | sh\n');
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
execFileSync(BINARY, process.argv.slice(2), { stdio: 'inherit' });
|
|
48
|
+
} catch (e) {
|
|
49
|
+
process.exit(e.status ?? 1);
|
|
50
|
+
}
|
package/install.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/**
|
|
4
|
+
* postinstall — downloads the squeez binary and registers Claude Code hooks.
|
|
5
|
+
* Runs automatically on `npm install -g squeez` or `npx squeez`.
|
|
6
|
+
*/
|
|
7
|
+
const { execSync } = require('child_process');
|
|
8
|
+
const https = require('https');
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const os = require('os');
|
|
12
|
+
|
|
13
|
+
// Allow skipping (e.g. in CI that only needs the npm package metadata)
|
|
14
|
+
if (process.env.SQUEEZ_SKIP_INSTALL === '1') process.exit(0);
|
|
15
|
+
|
|
16
|
+
const INSTALL_DIR = path.join(os.homedir(), '.claude', 'squeez');
|
|
17
|
+
const BINARY = path.join(INSTALL_DIR, 'bin', process.platform === 'win32' ? 'squeez.exe' : 'squeez');
|
|
18
|
+
const RELEASES = 'https://github.com/claudioemmanuel/squeez/releases/latest/download';
|
|
19
|
+
|
|
20
|
+
function log(msg) { process.stdout.write(`squeez: ${msg}\n`); }
|
|
21
|
+
function warn(msg) { process.stderr.write(`squeez: ${msg}\n`); }
|
|
22
|
+
|
|
23
|
+
// ── Platform map ───────────────────────────────────────────────────────────
|
|
24
|
+
const PLATFORM_MAP = {
|
|
25
|
+
darwin: { x64: 'squeez-macos-universal', arm64: 'squeez-macos-universal' },
|
|
26
|
+
linux: { x64: 'squeez-linux-x86_64', arm64: 'squeez-linux-aarch64' },
|
|
27
|
+
win32: { x64: 'squeez-windows-x86_64.exe' },
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function getBinary() {
|
|
31
|
+
const plat = PLATFORM_MAP[process.platform];
|
|
32
|
+
if (!plat) return null;
|
|
33
|
+
return plat[process.arch] || plat['x64'] || null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ── Download helper (Node built-in https, no external deps) ───────────────
|
|
37
|
+
function download(url, dest) {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const tmp = dest + '.tmp';
|
|
40
|
+
const file = fs.createWriteStream(tmp);
|
|
41
|
+
const follow = (u) => {
|
|
42
|
+
https.get(u, (res) => {
|
|
43
|
+
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
44
|
+
follow(res.headers.location);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (res.statusCode !== 200) {
|
|
48
|
+
reject(new Error(`HTTP ${res.statusCode} for ${u}`));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
res.pipe(file);
|
|
52
|
+
file.on('finish', () => {
|
|
53
|
+
file.close();
|
|
54
|
+
fs.renameSync(tmp, dest);
|
|
55
|
+
resolve();
|
|
56
|
+
});
|
|
57
|
+
}).on('error', reject);
|
|
58
|
+
};
|
|
59
|
+
follow(url);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function main() {
|
|
64
|
+
// Already installed and up-to-date — just register hooks
|
|
65
|
+
if (fs.existsSync(BINARY)) {
|
|
66
|
+
log('binary already present — skipping download.');
|
|
67
|
+
registerHooks();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ── Unix: prefer install.sh (also handles hooks + Copilot) ───────────
|
|
72
|
+
if (process.platform !== 'win32') {
|
|
73
|
+
try {
|
|
74
|
+
log('running install.sh …');
|
|
75
|
+
execSync(
|
|
76
|
+
'curl -fsSL https://raw.githubusercontent.com/claudioemmanuel/squeez/main/install.sh | sh',
|
|
77
|
+
{ stdio: 'inherit' }
|
|
78
|
+
);
|
|
79
|
+
return;
|
|
80
|
+
} catch (_) {
|
|
81
|
+
warn('curl not found — falling back to Node.js downloader.');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ── Fallback: Node.js binary download (no curl required) ─────────────
|
|
86
|
+
const binaryName = getBinary();
|
|
87
|
+
if (!binaryName) {
|
|
88
|
+
warn(`unsupported platform ${process.platform}/${process.arch}.`);
|
|
89
|
+
warn('Download manually from https://github.com/claudioemmanuel/squeez/releases');
|
|
90
|
+
process.exit(0);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
fs.mkdirSync(path.join(INSTALL_DIR, 'bin'), { recursive: true });
|
|
94
|
+
fs.mkdirSync(path.join(INSTALL_DIR, 'hooks'), { recursive: true });
|
|
95
|
+
fs.mkdirSync(path.join(INSTALL_DIR, 'sessions'), { recursive: true });
|
|
96
|
+
|
|
97
|
+
log(`downloading ${binaryName} …`);
|
|
98
|
+
try {
|
|
99
|
+
await download(`${RELEASES}/${binaryName}`, BINARY);
|
|
100
|
+
fs.chmodSync(BINARY, 0o755);
|
|
101
|
+
log('binary downloaded.');
|
|
102
|
+
} catch (err) {
|
|
103
|
+
warn(`download failed: ${err.message}`);
|
|
104
|
+
warn('Install manually: curl -fsSL https://raw.githubusercontent.com/claudioemmanuel/squeez/main/install.sh | sh');
|
|
105
|
+
process.exit(0);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
registerHooks();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function registerHooks() {
|
|
112
|
+
const settingsPath = path.join(os.homedir(), '.claude', 'settings.json');
|
|
113
|
+
let settings = {};
|
|
114
|
+
try {
|
|
115
|
+
if (fs.existsSync(settingsPath)) {
|
|
116
|
+
settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
117
|
+
}
|
|
118
|
+
} catch (_) {}
|
|
119
|
+
|
|
120
|
+
let changed = false;
|
|
121
|
+
|
|
122
|
+
// PreToolUse
|
|
123
|
+
if (!Array.isArray(settings.PreToolUse)) { settings.PreToolUse = []; }
|
|
124
|
+
const preHook = { matcher: 'Bash', hooks: [{ type: 'command', command: 'bash ~/.claude/squeez/hooks/pretooluse.sh' }] };
|
|
125
|
+
if (!settings.PreToolUse.some(h => JSON.stringify(h).includes('squeez'))) {
|
|
126
|
+
settings.PreToolUse.push(preHook); changed = true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// SessionStart
|
|
130
|
+
if (!Array.isArray(settings.SessionStart)) { settings.SessionStart = []; }
|
|
131
|
+
const startHook = { hooks: [{ type: 'command', command: 'bash ~/.claude/squeez/hooks/session-start.sh' }] };
|
|
132
|
+
if (!settings.SessionStart.some(h => JSON.stringify(h).includes('squeez'))) {
|
|
133
|
+
settings.SessionStart.push(startHook); changed = true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// PostToolUse
|
|
137
|
+
if (!Array.isArray(settings.PostToolUse)) { settings.PostToolUse = []; }
|
|
138
|
+
const postHook = { hooks: [{ type: 'command', command: 'bash ~/.claude/squeez/hooks/posttooluse.sh' }] };
|
|
139
|
+
if (!settings.PostToolUse.some(h => JSON.stringify(h).includes('squeez'))) {
|
|
140
|
+
settings.PostToolUse.push(postHook); changed = true;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// StatusLine
|
|
144
|
+
const squeezStatusCmd = 'bash ~/.claude/squeez/bin/statusline.sh';
|
|
145
|
+
const existingStatus = typeof settings.statusLine === 'object' ? settings.statusLine : {};
|
|
146
|
+
const existingCmd = existingStatus.command || '';
|
|
147
|
+
if (!existingCmd.includes('squeez')) {
|
|
148
|
+
settings.statusLine = existingCmd
|
|
149
|
+
? { type: 'command', command: `bash -c 'input=$(cat); echo "$input" | { ${existingCmd}; } 2>/dev/null; echo "$input" | ${squeezStatusCmd}'` }
|
|
150
|
+
: { type: 'command', command: squeezStatusCmd };
|
|
151
|
+
changed = true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (changed) {
|
|
155
|
+
try {
|
|
156
|
+
fs.writeFileSync(settingsPath + '.tmp', JSON.stringify(settings, null, 2));
|
|
157
|
+
fs.renameSync(settingsPath + '.tmp', settingsPath);
|
|
158
|
+
log('Claude Code hooks registered.');
|
|
159
|
+
} catch (err) {
|
|
160
|
+
warn(`could not write settings.json: ${err.message}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
main().catch(err => { warn(err.message); process.exit(0); });
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "squeez",
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "Hook-based token compressor for Claude Code, Copilot CLI, and OpenCode. Compresses bash output up to 95%, collapses redundant calls, injects caveman persona.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"claude-code",
|
|
7
|
+
"token-optimizer",
|
|
8
|
+
"context-window",
|
|
9
|
+
"llm-tools",
|
|
10
|
+
"copilot-cli",
|
|
11
|
+
"compression"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/claudioemmanuel/squeez",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/claudioemmanuel/squeez/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/claudioemmanuel/squeez.git"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "claudioemmanuel",
|
|
23
|
+
"bin": {
|
|
24
|
+
"squeez": "bin.js"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"postinstall": "node install.js"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=16"
|
|
31
|
+
},
|
|
32
|
+
"os": [
|
|
33
|
+
"darwin",
|
|
34
|
+
"linux",
|
|
35
|
+
"win32"
|
|
36
|
+
]
|
|
37
|
+
}
|