@axionorbital/tamarind 1.5.43 → 1.6.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/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 CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@axionorbital/tamarind",
3
- "version": "1.5.43",
3
+ "version": "1.6.0",
4
4
  "description": "Tamarind — verification-first coding agent for the terminal.",
5
5
  "bin": {
6
- "tamarind": "bin/tamarind.mjs"
6
+ "tamarind": "bin/tamarind"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node ./postinstall.mjs"
7
10
  },
8
11
  "files": [
9
12
  "bin",
13
+ "postinstall.mjs",
10
14
  "LICENSE",
11
15
  "THIRD-PARTY-NOTICES.md"
12
16
  ],
@@ -20,11 +24,10 @@
20
24
  "x64"
21
25
  ],
22
26
  "optionalDependencies": {
23
- "@axionorbital/tamarind-darwin-arm64": "1.5.43",
24
- "@axionorbital/tamarind-windows-x64": "1.5.43",
25
- "@axionorbital/tamarind-linux-arm64": "1.5.43",
26
- "@axionorbital/tamarind-linux-x64": "1.5.43",
27
- "@axionorbital/tamarind-darwin-x64": "1.5.43"
27
+ "@axionorbital/tamarind-darwin-arm64": "1.6.0",
28
+ "@axionorbital/tamarind-linux-arm64": "1.6.0",
29
+ "@axionorbital/tamarind-linux-x64": "1.6.0",
30
+ "@axionorbital/tamarind-darwin-x64": "1.6.0"
28
31
  },
29
32
  "license": "UNLICENSED",
30
33
  "private": false,
@@ -0,0 +1,157 @@
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
+ // What to copy FROM the platform package (build.ts names the binary `tamarind`).
26
+ const sourceBinary = platform === "windows" ? "tamarind.exe" : "tamarind"
27
+ // Target matching the resolver's bin field, so the `tamarind` command links.
28
+ const targetBinary = path.join(__dirname, "bin", "tamarind")
29
+
30
+ function supportsAvx2() {
31
+ if (arch !== "x64") return false
32
+ if (platform === "linux") {
33
+ try {
34
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
35
+ } catch {
36
+ return false
37
+ }
38
+ }
39
+ if (platform === "darwin") {
40
+ try {
41
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], {
42
+ encoding: "utf8",
43
+ timeout: 1500,
44
+ })
45
+ if (result.status !== 0) return false
46
+ return (result.stdout || "").trim() === "1"
47
+ } catch {
48
+ return false
49
+ }
50
+ }
51
+ return false
52
+ }
53
+
54
+ function isMusl() {
55
+ if (platform !== "linux") return false
56
+ try {
57
+ if (fs.existsSync("/etc/alpine-release")) return true
58
+ } catch {
59
+ // host may block the probe
60
+ }
61
+ try {
62
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
63
+ return `${result.stdout || ""}${result.stderr || ""}`.toLowerCase().includes("musl")
64
+ } catch {
65
+ return false
66
+ }
67
+ }
68
+
69
+ function packageNames() {
70
+ const baseline = arch === "x64" && !supportsAvx2()
71
+ if (platform === "linux") {
72
+ if (isMusl()) {
73
+ if (arch === "x64")
74
+ return baseline
75
+ ? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
76
+ : [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
77
+ return [`${base}-musl`, base]
78
+ }
79
+ if (arch === "x64")
80
+ return baseline
81
+ ? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
82
+ : [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
83
+ return [base, `${base}-musl`]
84
+ }
85
+ if (arch === "x64") return baseline ? [`${base}-baseline`, base] : [base, `${base}-baseline`]
86
+ return [base]
87
+ }
88
+
89
+ function resolveBinary(name) {
90
+ const packageJsonPath = require.resolve(`${name}/package.json`)
91
+ const binaryPath = path.join(path.dirname(packageJsonPath), "bin", sourceBinary)
92
+ if (!fs.existsSync(binaryPath)) throw new Error(`Binary not found at ${binaryPath}`)
93
+ return binaryPath
94
+ }
95
+
96
+ function copyBinary(source, target) {
97
+ if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)
98
+ fs.mkdirSync(path.dirname(target), { recursive: true })
99
+ if (fs.existsSync(target)) fs.unlinkSync(target)
100
+ try {
101
+ fs.linkSync(source, target)
102
+ } catch {
103
+ fs.copyFileSync(source, target)
104
+ }
105
+ fs.chmodSync(target, 0o755)
106
+ }
107
+
108
+ function installPackage(name) {
109
+ const version = packageJson.optionalDependencies?.[name]
110
+ if (!version) return
111
+ const temp = fs.mkdtempSync(path.join(os.tmpdir(), "tamarind-install-"))
112
+ try {
113
+ const result = childProcess.spawnSync(
114
+ "npm",
115
+ ["install", "--ignore-scripts", "--no-save", "--loglevel=error", "--prefix", temp, `${name}@${version}`],
116
+ { stdio: "inherit", windowsHide: true },
117
+ )
118
+ if (result.status !== 0) return
119
+ const packageDir = path.join(temp, "node_modules", name)
120
+ copyBinary(path.join(packageDir, "bin", sourceBinary), targetBinary)
121
+ return true
122
+ } finally {
123
+ fs.rmSync(temp, { recursive: true, force: true })
124
+ }
125
+ }
126
+
127
+ function verifyBinary() {
128
+ const result = childProcess.spawnSync(targetBinary, ["--version"], {
129
+ encoding: "utf8",
130
+ stdio: "ignore",
131
+ windowsHide: true,
132
+ })
133
+ return result.status === 0
134
+ }
135
+
136
+ function main() {
137
+ for (const name of packageNames()) {
138
+ try {
139
+ copyBinary(resolveBinary(name), targetBinary)
140
+ if (verifyBinary()) return
141
+ } catch {
142
+ if (installPackage(name) && verifyBinary()) return
143
+ }
144
+ }
145
+ throw new Error(
146
+ `Could not find a Tamarind binary for your platform. Try manually installing ${packageNames()
147
+ .map((name) => JSON.stringify(name))
148
+ .join(" or ")}.`,
149
+ )
150
+ }
151
+
152
+ try {
153
+ main()
154
+ } catch (error) {
155
+ console.error(error.message)
156
+ process.exit(1)
157
+ }
package/bin/tamarind.mjs DELETED
@@ -1,133 +0,0 @@
1
- #!/usr/bin/env node
2
- // Resolver entry for `@axionorbital/tamarind`. Shipped as the package's `bin`
3
- // (bin/tamarind.mjs). At RUNTIME it resolves the platform-matched binary that npm
4
- // installed via this package's optionalDependencies and execs it, forwarding
5
- // argv, stdio, exit code and signals.
6
- //
7
- // Why a JS launcher instead of the old postinstall+stub: npm links a package's
8
- // `bin` BEFORE running install scripts, generating the Windows .cmd/.ps1 shims
9
- // from the bin target's shebang at that moment. The old design pointed `bin` at a
10
- // `#!/usr/bin/env sh` stub, so the shim baked in `sh` execution; postinstall then
11
- // overwrote the stub with a native Windows PE, leaving the shim running
12
- // `sh <tamarind.exe>` → "cannot execute binary file". Pointing `bin` at THIS node
13
- // script makes npm shim `node tamarind.mjs` identically on every OS — no
14
- // shebang/swap race, no extensionless-PE problem — and lets us drop the
15
- // postinstall entirely (optionalDependencies install natively, no scripts).
16
-
17
- import { createRequire } from "node:module"
18
- import fs from "node:fs"
19
- import os from "node:os"
20
- import path from "node:path"
21
- import childProcess from "node:child_process"
22
- const { spawnSync } = childProcess
23
-
24
- const require = createRequire(import.meta.url)
25
-
26
- // Resolution mirrors the prior postinstall so a given host picks the SAME
27
- // platform package. build.ts names dirs win32→windows.
28
- const platformMap = { darwin: "darwin", linux: "linux", win32: "windows" }
29
- const archMap = { x64: "x64", arm64: "arm64", arm: "arm" }
30
- const platform = platformMap[os.platform()] ?? os.platform()
31
- const arch = archMap[os.arch()] ?? os.arch()
32
- const base = `@axionorbital/tamarind-${platform}-${arch}`
33
- // Windows ships bin/tamarind.exe (a PE needs the extension to spawn); every other
34
- // platform ships bin/tamarind.
35
- const sourceBinary = platform === "windows" ? "tamarind.exe" : "tamarind"
36
-
37
- function supportsAvx2() {
38
- if (arch !== "x64") return false
39
- if (platform === "linux") {
40
- try {
41
- return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
42
- } catch {
43
- return false
44
- }
45
- }
46
- if (platform === "darwin") {
47
- try {
48
- const r = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], { encoding: "utf8", timeout: 1500 })
49
- return r.status === 0 && (r.stdout || "").trim() === "1"
50
- } catch {
51
- return false
52
- }
53
- }
54
- return false
55
- }
56
-
57
- function isMusl() {
58
- if (platform !== "linux") return false
59
- try {
60
- if (fs.existsSync("/etc/alpine-release")) return true
61
- } catch {}
62
- try {
63
- const r = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
64
- return `${r.stdout || ""}${r.stderr || ""}`.toLowerCase().includes("musl")
65
- } catch {
66
- return false
67
- }
68
- }
69
-
70
- // Candidate package names, most-specific first, mirroring postinstall's chain so
71
- // baseline (no-AVX2) and musl variant packages resolve when present.
72
- function packageNames() {
73
- const baseline = arch === "x64" && !supportsAvx2()
74
- if (platform === "linux") {
75
- if (isMusl()) {
76
- if (arch === "x64")
77
- return baseline
78
- ? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
79
- : [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
80
- return [`${base}-musl`, base]
81
- }
82
- if (arch === "x64")
83
- return baseline
84
- ? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
85
- : [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
86
- return [base, `${base}-musl`]
87
- }
88
- if (arch === "x64") return baseline ? [`${base}-baseline`, base] : [base, `${base}-baseline`]
89
- return [base]
90
- }
91
-
92
- function resolveBinary() {
93
- const tried = []
94
- for (const name of packageNames()) {
95
- tried.push(name)
96
- try {
97
- const pkgJson = require.resolve(`${name}/package.json`)
98
- const bin = path.join(path.dirname(pkgJson), "bin", sourceBinary)
99
- if (fs.existsSync(bin)) return bin
100
- } catch {
101
- // not installed for this host — try the next candidate
102
- }
103
- }
104
- return { error: tried }
105
- }
106
-
107
- const resolved = resolveBinary()
108
- if (typeof resolved !== "string") {
109
- console.error(
110
- `Tamarind: no platform binary found for ${platform}-${arch}. Expected one of: ` +
111
- `${resolved.error.join(", ")}. Reinstall with \`npm i -g @axionorbital/tamarind\` ` +
112
- `(ensure optional dependencies are not disabled).`,
113
- )
114
- process.exit(1)
115
- }
116
-
117
- // Exec the native binary. stdio:"inherit" preserves the real TTY (raw mode for the
118
- // TUI). No shell:true — args pass through verbatim (no mangling/injection).
119
- const child = spawnSync(resolved, process.argv.slice(2), { stdio: "inherit", windowsHide: false })
120
-
121
- if (child.error) {
122
- console.error(`Tamarind: failed to launch ${resolved}: ${child.error.message}`)
123
- process.exit(1)
124
- }
125
- // Re-raise a terminating signal (Ctrl-C etc.) so the parent's exit reflects it;
126
- // otherwise forward the child's numeric exit code.
127
- if (child.signal) {
128
- try {
129
- process.kill(process.pid, child.signal)
130
- } catch {}
131
- process.exit(1)
132
- }
133
- process.exit(child.status ?? 0)