lean-ctx-bin 2.5.0

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 ADDED
@@ -0,0 +1,47 @@
1
+ # lean-ctx-bin
2
+
3
+ Pre-built binary distribution of [lean-ctx](https://github.com/yvgude/lean-ctx) — the Cognitive Filter for AI Engineering.
4
+
5
+ No Rust toolchain required. The correct binary for your platform is downloaded automatically during `npm install`.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install -g lean-ctx-bin
11
+ ```
12
+
13
+ After installing, run the one-command setup:
14
+
15
+ ```bash
16
+ lean-ctx setup
17
+ ```
18
+
19
+ This auto-detects your shell and editors, installs shell aliases, creates MCP configs, and verifies everything.
20
+
21
+ ## Supported Platforms
22
+
23
+ | Platform | Architecture |
24
+ |----------|-------------|
25
+ | Linux | x86_64, aarch64 |
26
+ | macOS | x86_64, Apple Silicon |
27
+ | Windows | x86_64 |
28
+
29
+ ## Alternative Install Methods
30
+
31
+ ```bash
32
+ # Universal installer (no Rust needed)
33
+ curl -fsSL https://leanctx.com/install.sh | sh
34
+
35
+ # Homebrew (macOS/Linux)
36
+ brew tap yvgude/lean-ctx && brew install lean-ctx
37
+
38
+ # Cargo (requires Rust)
39
+ cargo install lean-ctx
40
+ ```
41
+
42
+ ## Links
43
+
44
+ - [Documentation](https://leanctx.com/docs/getting-started)
45
+ - [GitHub](https://github.com/yvgude/lean-ctx)
46
+ - [crates.io](https://crates.io/crates/lean-ctx)
47
+ - [Discord](https://discord.gg/pTHkG9Hew9)
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { spawnSync } = require("child_process");
5
+ const path = require("path");
6
+
7
+ const IS_WIN = process.platform === "win32";
8
+ const BINARY = path.join(__dirname, IS_WIN ? "lean-ctx.exe" : "lean-ctx");
9
+
10
+ const result = spawnSync(BINARY, process.argv.slice(2), {
11
+ stdio: "inherit",
12
+ env: process.env,
13
+ });
14
+
15
+ if (result.error) {
16
+ if (result.error.code === "ENOENT") {
17
+ console.error("lean-ctx binary not found. Run: npm rebuild lean-ctx-bin");
18
+ } else {
19
+ console.error(`lean-ctx: ${result.error.message}`);
20
+ }
21
+ process.exit(127);
22
+ }
23
+
24
+ process.exit(result.status ?? 1);
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "lean-ctx-bin",
3
+ "version": "2.5.0",
4
+ "description": "lean-ctx — the token-efficient context tool for LLM coding agents. Installs a pre-built binary, no Rust required.",
5
+ "keywords": ["lean-ctx", "mcp", "llm", "context", "claude", "cursor", "ai", "token-optimization"],
6
+ "homepage": "https://leanctx.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/yvgude/lean-ctx.git",
10
+ "directory": "packages/lean-ctx-bin"
11
+ },
12
+ "license": "MIT",
13
+ "bin": {
14
+ "lean-ctx": "./bin/lean-ctx.js"
15
+ },
16
+ "scripts": {
17
+ "postinstall": "node postinstall.js"
18
+ },
19
+ "files": [
20
+ "bin/",
21
+ "postinstall.js",
22
+ "README.md"
23
+ ],
24
+ "engines": {
25
+ "node": ">=16"
26
+ }
27
+ }
package/postinstall.js ADDED
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const { execSync } = require("child_process");
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+ const https = require("https");
8
+ const { createGunzip } = require("zlib");
9
+
10
+ const REPO = "yvgude/lean-ctx";
11
+ const BIN_DIR = path.join(__dirname, "bin");
12
+ const IS_WIN = process.platform === "win32";
13
+ const BINARY_NAME = IS_WIN ? "lean-ctx.exe" : "lean-ctx";
14
+ const BINARY_PATH = path.join(BIN_DIR, BINARY_NAME);
15
+
16
+ function getTarget() {
17
+ const platform = process.platform;
18
+ const arch = process.arch;
19
+
20
+ const key = `${platform}-${arch}`;
21
+ const targets = {
22
+ "linux-x64": "x86_64-unknown-linux-gnu",
23
+ "linux-arm64": "aarch64-unknown-linux-gnu",
24
+ "darwin-x64": "x86_64-apple-darwin",
25
+ "darwin-arm64": "aarch64-apple-darwin",
26
+ "win32-x64": "x86_64-pc-windows-msvc",
27
+ };
28
+
29
+ const target = targets[key];
30
+ if (!target) {
31
+ console.error(`Unsupported platform: ${key}`);
32
+ console.error("Build from source instead: cargo install lean-ctx");
33
+ process.exit(1);
34
+ }
35
+ return target;
36
+ }
37
+
38
+ function httpsGet(url) {
39
+ return new Promise((resolve, reject) => {
40
+ const get = (u) => {
41
+ https.get(u, { headers: { "User-Agent": "lean-ctx-bin-npm" } }, (res) => {
42
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
43
+ get(res.headers.location);
44
+ return;
45
+ }
46
+ if (res.statusCode !== 200) {
47
+ reject(new Error(`HTTP ${res.statusCode} for ${u}`));
48
+ return;
49
+ }
50
+ resolve(res);
51
+ }).on("error", reject);
52
+ };
53
+ get(url);
54
+ });
55
+ }
56
+
57
+ function httpsGetJson(url) {
58
+ return new Promise((resolve, reject) => {
59
+ httpsGet(url).then((res) => {
60
+ let data = "";
61
+ res.on("data", (c) => (data += c));
62
+ res.on("end", () => {
63
+ try { resolve(JSON.parse(data)); }
64
+ catch (e) { reject(e); }
65
+ });
66
+ }).catch(reject);
67
+ });
68
+ }
69
+
70
+ async function downloadToFile(url, dest) {
71
+ const res = await httpsGet(url);
72
+ return new Promise((resolve, reject) => {
73
+ const ws = fs.createWriteStream(dest);
74
+ res.pipe(ws);
75
+ ws.on("finish", resolve);
76
+ ws.on("error", reject);
77
+ });
78
+ }
79
+
80
+ function extractTarGz(archive, destDir, binaryName) {
81
+ const gunzip = createGunzip();
82
+ const input = fs.createReadStream(archive);
83
+
84
+ return new Promise((resolve, reject) => {
85
+ const chunks = [];
86
+ input.pipe(gunzip)
87
+ .on("data", (c) => chunks.push(c))
88
+ .on("end", () => {
89
+ const buf = Buffer.concat(chunks);
90
+ let offset = 0;
91
+ while (offset < buf.length) {
92
+ const header = buf.subarray(offset, offset + 512);
93
+ if (header.every((b) => b === 0)) break;
94
+
95
+ const name = header.subarray(0, 100).toString("utf8").replace(/\0/g, "");
96
+ const sizeStr = header.subarray(124, 136).toString("utf8").replace(/\0/g, "").trim();
97
+ const size = parseInt(sizeStr, 8) || 0;
98
+ offset += 512;
99
+
100
+ const baseName = path.basename(name);
101
+ if (baseName === binaryName && size > 0) {
102
+ const dest = path.join(destDir, binaryName);
103
+ fs.writeFileSync(dest, buf.subarray(offset, offset + size));
104
+ if (!IS_WIN) fs.chmodSync(dest, 0o755);
105
+ resolve(dest);
106
+ return;
107
+ }
108
+ offset += Math.ceil(size / 512) * 512;
109
+ }
110
+ reject(new Error(`${binaryName} not found in archive`));
111
+ })
112
+ .on("error", reject);
113
+ });
114
+ }
115
+
116
+ async function main() {
117
+ if (fs.existsSync(BINARY_PATH)) {
118
+ console.log("lean-ctx binary already exists, skipping download");
119
+ return;
120
+ }
121
+
122
+ const target = getTarget();
123
+ console.log(`lean-ctx: installing for ${target}...`);
124
+
125
+ const release = await httpsGetJson(`https://api.github.com/repos/${REPO}/releases/latest`);
126
+ const tag = release.tag_name;
127
+ console.log(`lean-ctx: latest release ${tag}`);
128
+
129
+ const ext = IS_WIN ? ".zip" : ".tar.gz";
130
+ const assetName = `lean-ctx-${target}${ext}`;
131
+ const asset = (release.assets || []).find((a) => a.name === assetName);
132
+ if (!asset) {
133
+ console.error(`No binary for ${target}. Install from source: cargo install lean-ctx`);
134
+ process.exit(1);
135
+ }
136
+
137
+ const tmpDir = fs.mkdtempSync(path.join(require("os").tmpdir(), "lean-ctx-"));
138
+ const archivePath = path.join(tmpDir, assetName);
139
+
140
+ try {
141
+ await downloadToFile(asset.browser_download_url, archivePath);
142
+ console.log("lean-ctx: downloaded, extracting...");
143
+
144
+ fs.mkdirSync(BIN_DIR, { recursive: true });
145
+
146
+ if (IS_WIN) {
147
+ execSync(`tar -xf "${archivePath}" -C "${BIN_DIR}"`, { stdio: "ignore" });
148
+ } else {
149
+ await extractTarGz(archivePath, BIN_DIR, "lean-ctx");
150
+ }
151
+
152
+ console.log(`lean-ctx: installed to ${BINARY_PATH}`);
153
+ } finally {
154
+ fs.rmSync(tmpDir, { recursive: true, force: true });
155
+ }
156
+ }
157
+
158
+ main().catch((err) => {
159
+ console.error(`lean-ctx: installation failed: ${err.message}`);
160
+ console.error("Install from source instead: cargo install lean-ctx");
161
+ process.exit(1);
162
+ });