tilth 0.1.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.
Files changed (3) hide show
  1. package/install.js +98 -0
  2. package/package.json +28 -0
  3. package/run.js +21 -0
package/install.js ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const https = require("https");
6
+ const http = require("http");
7
+ const fs = require("fs");
8
+ const path = require("path");
9
+ const { execSync } = require("child_process");
10
+ const zlib = require("zlib");
11
+
12
+ const PLATFORM_MAP = {
13
+ "linux-x64": "x86_64-unknown-linux-musl",
14
+ "linux-arm64": "aarch64-unknown-linux-musl",
15
+ "darwin-x64": "x86_64-apple-darwin",
16
+ "darwin-arm64": "aarch64-apple-darwin",
17
+ "win32-x64": "x86_64-pc-windows-msvc",
18
+ };
19
+
20
+ const key = `${process.platform}-${process.arch}`;
21
+ const target = PLATFORM_MAP[key];
22
+
23
+ if (!target) {
24
+ console.error(`tilth: unsupported platform ${key}`);
25
+ console.error(`Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`);
26
+ process.exit(1);
27
+ }
28
+
29
+ const version = require("./package.json").version;
30
+ const isWindows = process.platform === "win32";
31
+ const ext = isWindows ? "zip" : "tar.gz";
32
+ const binName = isWindows ? "tilth.exe" : "tilth";
33
+ const url = `https://github.com/jahala/tilth/releases/download/v${version}/tilth-${target}.${ext}`;
34
+
35
+ const binDir = path.join(__dirname, "bin");
36
+ const binPath = path.join(binDir, binName);
37
+
38
+ // Skip if binary already exists (e.g. re-install)
39
+ if (fs.existsSync(binPath)) {
40
+ process.exit(0);
41
+ }
42
+
43
+ fs.mkdirSync(binDir, { recursive: true });
44
+
45
+ console.log(`tilth: downloading ${target} binary...`);
46
+
47
+ function follow(url, callback) {
48
+ const mod = url.startsWith("https") ? https : http;
49
+ mod.get(url, { headers: { "User-Agent": "tilth-npm" } }, (res) => {
50
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
51
+ follow(res.headers.location, callback);
52
+ } else if (res.statusCode !== 200) {
53
+ console.error(`tilth: download failed (HTTP ${res.statusCode})`);
54
+ console.error(`URL: ${url}`);
55
+ console.error("Install manually: cargo install tilth");
56
+ process.exit(1);
57
+ } else {
58
+ callback(res);
59
+ }
60
+ }).on("error", (err) => {
61
+ console.error(`tilth: download failed: ${err.message}`);
62
+ console.error("Install manually: cargo install tilth");
63
+ process.exit(1);
64
+ });
65
+ }
66
+
67
+ follow(url, (res) => {
68
+ if (isWindows) {
69
+ // For Windows, save zip and extract with tar (available on modern Windows)
70
+ const tmpZip = path.join(binDir, "tilth.zip");
71
+ const out = fs.createWriteStream(tmpZip);
72
+ res.pipe(out);
73
+ out.on("finish", () => {
74
+ out.close();
75
+ try {
76
+ execSync(`tar -xf "${tmpZip}" -C "${binDir}"`, { stdio: "ignore" });
77
+ fs.unlinkSync(tmpZip);
78
+ } catch {
79
+ console.error("tilth: failed to extract. Install manually: cargo install tilth");
80
+ process.exit(1);
81
+ }
82
+ });
83
+ } else {
84
+ // Unix: pipe through gunzip and tar
85
+ const tar = require("child_process").spawn("tar", ["xz", "-C", binDir], {
86
+ stdio: ["pipe", "inherit", "inherit"],
87
+ });
88
+ res.pipe(tar.stdin);
89
+ tar.on("close", (code) => {
90
+ if (code !== 0) {
91
+ console.error("tilth: failed to extract. Install manually: cargo install tilth");
92
+ process.exit(1);
93
+ }
94
+ fs.chmodSync(binPath, 0o755);
95
+ console.log("tilth: installed successfully");
96
+ });
97
+ }
98
+ });
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "tilth",
3
+ "version": "0.1.0",
4
+ "description": "Tree-sitter indexed lookups — smart code reading for AI agents",
5
+ "bin": {
6
+ "tilth": "run.js"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node install.js"
10
+ },
11
+ "files": [
12
+ "install.js",
13
+ "run.js",
14
+ "README.md"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/jahala/tilth"
19
+ },
20
+ "keywords": [
21
+ "mcp",
22
+ "code-search",
23
+ "tree-sitter",
24
+ "developer-tools",
25
+ "ai-agents"
26
+ ],
27
+ "license": "MIT"
28
+ }
package/run.js ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const { execFileSync } = require("child_process");
6
+ const path = require("path");
7
+
8
+ const isWindows = process.platform === "win32";
9
+ const binName = isWindows ? "tilth.exe" : "tilth";
10
+ const bin = path.join(__dirname, "bin", binName);
11
+
12
+ try {
13
+ execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });
14
+ } catch (err) {
15
+ if (err.status != null) {
16
+ process.exit(err.status);
17
+ }
18
+ console.error(`tilth: failed to run binary at ${bin}`);
19
+ console.error(err.message);
20
+ process.exit(1);
21
+ }