@axionorbital/tamarind 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.
- package/LICENSE +1 -0
- package/bin/tamarind +5 -0
- package/package.json +40 -0
- package/postinstall.mjs +155 -0
package/LICENSE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright AxionOrbital. All rights reserved.
|
package/bin/tamarind
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
echo "Error: Tamarind's postinstall did not run, so the platform binary is missing." >&2
|
|
3
|
+
echo "This happens with --ignore-scripts or package managers that skip postinstall." >&2
|
|
4
|
+
echo "Fix: cd \"\$(npm root -g)/@axionorbital/tamarind\" && node postinstall.mjs" >&2
|
|
5
|
+
exit 1
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@axionorbital/tamarind",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tamarind — verification-first coding agent for the terminal.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"tamarind": "./bin/tamarind"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node ./postinstall.mjs"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin",
|
|
13
|
+
"postinstall.mjs",
|
|
14
|
+
"LICENSE"
|
|
15
|
+
],
|
|
16
|
+
"os": [
|
|
17
|
+
"darwin",
|
|
18
|
+
"linux",
|
|
19
|
+
"win32"
|
|
20
|
+
],
|
|
21
|
+
"cpu": [
|
|
22
|
+
"arm64",
|
|
23
|
+
"x64"
|
|
24
|
+
],
|
|
25
|
+
"optionalDependencies": {
|
|
26
|
+
"@axionorbital/tamarind-darwin-arm64": "0.1.0",
|
|
27
|
+
"@axionorbital/tamarind-linux-arm64": "0.1.0",
|
|
28
|
+
"@axionorbital/tamarind-linux-x64": "0.1.0",
|
|
29
|
+
"@axionorbital/tamarind-darwin-x64": "0.1.0"
|
|
30
|
+
},
|
|
31
|
+
"license": "UNLICENSED",
|
|
32
|
+
"private": false,
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"registry": "https://registry.npmjs.org"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/AxionOrbital/tamarind.git"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Runs after `npm i -g @axionorbital/tamarind`. Picks the platform-matched
|
|
3
|
+
// binary package that npm installed via optionalDependencies and links its
|
|
4
|
+
// executable into ./bin/tamarind so the `tamarind` command works.
|
|
5
|
+
|
|
6
|
+
import childProcess from "child_process"
|
|
7
|
+
import fs from "fs"
|
|
8
|
+
import os from "os"
|
|
9
|
+
import path from "path"
|
|
10
|
+
import { createRequire } from "module"
|
|
11
|
+
import { fileURLToPath } from "url"
|
|
12
|
+
|
|
13
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
14
|
+
const require = createRequire(import.meta.url)
|
|
15
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8"))
|
|
16
|
+
|
|
17
|
+
const SCOPE = "@axionorbital/tamarind"
|
|
18
|
+
|
|
19
|
+
const platformMap = { darwin: "darwin", linux: "linux", win32: "windows" }
|
|
20
|
+
const archMap = { x64: "x64", arm64: "arm64", arm: "arm" }
|
|
21
|
+
|
|
22
|
+
const platform = platformMap[os.platform()] ?? os.platform()
|
|
23
|
+
const arch = archMap[os.arch()] ?? os.arch()
|
|
24
|
+
const base = `${SCOPE}-${platform}-${arch}`
|
|
25
|
+
const sourceBinary = platform === "windows" ? "tamarind.exe" : "tamarind"
|
|
26
|
+
const targetBinary = path.join(__dirname, "bin", sourceBinary)
|
|
27
|
+
|
|
28
|
+
function supportsAvx2() {
|
|
29
|
+
if (arch !== "x64") return false
|
|
30
|
+
if (platform === "linux") {
|
|
31
|
+
try {
|
|
32
|
+
return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
|
|
33
|
+
} catch {
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (platform === "darwin") {
|
|
38
|
+
try {
|
|
39
|
+
const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
|
|
40
|
+
encoding: "utf8",
|
|
41
|
+
timeout: 1500,
|
|
42
|
+
})
|
|
43
|
+
if (result.status !== 0) return false
|
|
44
|
+
return (result.stdout || "").trim() === "1"
|
|
45
|
+
} catch {
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isMusl() {
|
|
53
|
+
if (platform !== "linux") return false
|
|
54
|
+
try {
|
|
55
|
+
if (fs.existsSync("/etc/alpine-release")) return true
|
|
56
|
+
} catch {
|
|
57
|
+
// host may block the probe
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
61
|
+
return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl")
|
|
62
|
+
} catch {
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function packageNames() {
|
|
68
|
+
const baseline = arch === "x64" && !supportsAvx2()
|
|
69
|
+
if (platform === "linux") {
|
|
70
|
+
if (isMusl()) {
|
|
71
|
+
if (arch === "x64")
|
|
72
|
+
return baseline
|
|
73
|
+
? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
|
|
74
|
+
: [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
|
|
75
|
+
return [`${base}-musl`, base]
|
|
76
|
+
}
|
|
77
|
+
if (arch === "x64")
|
|
78
|
+
return baseline
|
|
79
|
+
? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
|
|
80
|
+
: [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
|
|
81
|
+
return [base, `${base}-musl`]
|
|
82
|
+
}
|
|
83
|
+
if (arch === "x64") return baseline ? [`${base}-baseline`, base] : [base, `${base}-baseline`]
|
|
84
|
+
return [base]
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function resolveBinary(name) {
|
|
88
|
+
const packageJsonPath = require.resolve(`${name}/package.json`)
|
|
89
|
+
const binaryPath = path.join(path.dirname(packageJsonPath), "bin", sourceBinary)
|
|
90
|
+
if (!fs.existsSync(binaryPath)) throw new Error(`Binary not found at ${binaryPath}`)
|
|
91
|
+
return binaryPath
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function copyBinary(source, target) {
|
|
95
|
+
if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)
|
|
96
|
+
fs.mkdirSync(path.dirname(target), { recursive: true })
|
|
97
|
+
if (fs.existsSync(target)) fs.unlinkSync(target)
|
|
98
|
+
try {
|
|
99
|
+
fs.linkSync(source, target)
|
|
100
|
+
} catch {
|
|
101
|
+
fs.copyFileSync(source, target)
|
|
102
|
+
}
|
|
103
|
+
fs.chmodSync(target, 0o755)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function installPackage(name) {
|
|
107
|
+
const version = packageJson.optionalDependencies?.[name]
|
|
108
|
+
if (!version) return
|
|
109
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), "tamarind-install-"))
|
|
110
|
+
try {
|
|
111
|
+
const result = childProcess.spawnSync(
|
|
112
|
+
"npm",
|
|
113
|
+
["install", "--ignore-scripts", "--no-save", "--loglevel=error", "--prefix", temp, `${name}@${version}`],
|
|
114
|
+
{ stdio: "inherit", windowsHide: true },
|
|
115
|
+
)
|
|
116
|
+
if (result.status !== 0) return
|
|
117
|
+
const packageDir = path.join(temp, "node_modules", name)
|
|
118
|
+
copyBinary(path.join(packageDir, "bin", sourceBinary), targetBinary)
|
|
119
|
+
return true
|
|
120
|
+
} finally {
|
|
121
|
+
fs.rmSync(temp, { recursive: true, force: true })
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function verifyBinary() {
|
|
126
|
+
const result = childProcess.spawnSync(targetBinary, ["--version"], {
|
|
127
|
+
encoding: "utf8",
|
|
128
|
+
stdio: "ignore",
|
|
129
|
+
windowsHide: true,
|
|
130
|
+
})
|
|
131
|
+
return result.status === 0
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function main() {
|
|
135
|
+
for (const name of packageNames()) {
|
|
136
|
+
try {
|
|
137
|
+
copyBinary(resolveBinary(name), targetBinary)
|
|
138
|
+
if (verifyBinary()) return
|
|
139
|
+
} catch {
|
|
140
|
+
if (installPackage(name) && verifyBinary()) return
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
throw new Error(
|
|
144
|
+
`Could not find a Tamarind binary for your platform. Try manually installing ${packageNames()
|
|
145
|
+
.map((name) => JSON.stringify(name))
|
|
146
|
+
.join(" or ")}.`,
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
main()
|
|
152
|
+
} catch (error) {
|
|
153
|
+
console.error(error.message)
|
|
154
|
+
process.exit(1)
|
|
155
|
+
}
|