@mettlelabs/mettle 0.0.0-beta.2 → 0.0.0-beta.20

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 ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 mettle
4
+ Copyright (c) 2025 opencode
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/bin/mettle.cjs ADDED
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env node
2
+
3
+ const childProcess = require("node:child_process")
4
+ const fs = require("node:fs")
5
+ const path = require("node:path")
6
+ const os = require("node:os")
7
+
8
+ const forwardedSignals =
9
+ process.platform === "win32" ? ["SIGINT", "SIGTERM", "SIGHUP"] : ["SIGINT", "SIGTERM", "SIGHUP", "SIGUSR1"]
10
+
11
+ function run(target) {
12
+ // Tell the CLI which npm package launched it, so the self-updater can detect its install
13
+ // method. The native binary lives in a per-platform package (@mettlelabs/mettle-<suffix>)
14
+ // without a bin field, so the updater cannot rediscover the wrapper from its own path.
15
+ const env = { ...process.env, METTLE_NPM_ROOT: wrapperDir }
16
+ const child = childProcess.spawn(target, process.argv.slice(2), { stdio: "inherit", env })
17
+ child.on("error", (error) => {
18
+ console.error(error.message)
19
+ process.exit(1)
20
+ })
21
+ const forwarders = {}
22
+ for (const signal of forwardedSignals) {
23
+ forwarders[signal] = () => {
24
+ try {
25
+ child.kill(signal)
26
+ } catch {}
27
+ }
28
+ process.on(signal, forwarders[signal])
29
+ }
30
+ child.on("exit", (code, signal) => {
31
+ for (const forwardedSignal of forwardedSignals) process.removeListener(forwardedSignal, forwarders[forwardedSignal])
32
+ if (signal) return process.kill(process.pid, signal)
33
+ process.exit(typeof code === "number" ? code : 0)
34
+ })
35
+ }
36
+
37
+ const envPath = process.env.METTLE_BIN_PATH
38
+ const scriptDir = path.dirname(fs.realpathSync(__filename))
39
+ const wrapperDir = path.dirname(scriptDir)
40
+ const command = path.basename(__filename).replace(/\.cjs$/, "")
41
+ const platform = { darwin: "darwin", linux: "linux", win32: "windows" }[os.platform()] || os.platform()
42
+ const arch = { x64: "x64", arm64: "arm64", arm: "arm" }[os.arch()] || os.arch()
43
+ const base = `@mettlelabs/mettle-${platform}-${arch}`
44
+ const binary = platform === "windows" ? "mettle.exe" : "mettle"
45
+
46
+ // AVX2 support is a fixed property of the machine, so probe it once and cache the result next
47
+ // to the launcher. The Windows probe spawns PowerShell, which is too slow to run on every
48
+ // invocation. Binary resolution itself stays dynamic so an `npm update` is picked up at once.
49
+ function supportsAvx2() {
50
+ if (arch !== "x64") return false
51
+ const cacheFile = path.join(scriptDir, `.${command}-avx2`)
52
+ try {
53
+ const value = fs.readFileSync(cacheFile, "utf8").trim()
54
+ if (value === "1") return true
55
+ if (value === "0") return false
56
+ } catch {}
57
+ const result = detectAvx2()
58
+ try {
59
+ fs.writeFileSync(cacheFile, result ? "1" : "0")
60
+ } catch {}
61
+ return result
62
+ }
63
+
64
+ function detectAvx2() {
65
+ if (arch !== "x64") return false
66
+ if (platform === "linux") {
67
+ try {
68
+ return /(^|\s)avx2(\s|$)/i.test(fs.readFileSync("/proc/cpuinfo", "utf8"))
69
+ } catch {
70
+ return false
71
+ }
72
+ }
73
+ if (platform === "darwin") {
74
+ try {
75
+ const result = childProcess.spawnSync("sysctl", ["-n", "hw.optional.avx2_0"], { encoding: "utf8", timeout: 1500 })
76
+ return result.status === 0 && (result.stdout || "").trim() === "1"
77
+ } catch {
78
+ return false
79
+ }
80
+ }
81
+ if (platform === "windows") {
82
+ const command =
83
+ '(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
84
+ for (const executable of ["powershell.exe", "pwsh.exe", "pwsh", "powershell"]) {
85
+ try {
86
+ const result = childProcess.spawnSync(executable, ["-NoProfile", "-NonInteractive", "-Command", command], {
87
+ encoding: "utf8",
88
+ timeout: 3000,
89
+ windowsHide: true,
90
+ })
91
+ if (result.status !== 0) continue
92
+ const output = (result.stdout || "").trim().toLowerCase()
93
+ if (output === "true" || output === "1") return true
94
+ if (output === "false" || output === "0") return false
95
+ } catch {}
96
+ }
97
+ }
98
+ return false
99
+ }
100
+
101
+ const names = (() => {
102
+ const baseline = arch === "x64" && !supportsAvx2()
103
+ if (platform === "linux") {
104
+ const musl = (() => {
105
+ try {
106
+ if (fs.existsSync("/etc/alpine-release")) return true
107
+ const result = childProcess.spawnSync("ldd", ["--version"], { encoding: "utf8" })
108
+ return ((result.stdout || "") + (result.stderr || "")).toLowerCase().includes("musl")
109
+ } catch {
110
+ return false
111
+ }
112
+ })()
113
+ if (musl)
114
+ return arch === "x64"
115
+ ? baseline
116
+ ? [`${base}-baseline-musl`, `${base}-musl`, `${base}-baseline`, base]
117
+ : [`${base}-musl`, `${base}-baseline-musl`, base, `${base}-baseline`]
118
+ : [`${base}-musl`, base]
119
+ return arch === "x64"
120
+ ? baseline
121
+ ? [`${base}-baseline`, base, `${base}-baseline-musl`, `${base}-musl`]
122
+ : [base, `${base}-baseline`, `${base}-musl`, `${base}-baseline-musl`]
123
+ : [base, `${base}-musl`]
124
+ }
125
+ return arch === "x64" ? (baseline ? [`${base}-baseline`, base] : [base, `${base}-baseline`]) : [base]
126
+ })()
127
+
128
+ function findBinary(startDir) {
129
+ let current = startDir
130
+ for (;;) {
131
+ const modules = path.join(current, "node_modules")
132
+ if (fs.existsSync(modules))
133
+ for (const name of names) {
134
+ const candidate = path.join(modules, name, "bin", binary)
135
+ if (fs.existsSync(candidate)) return candidate
136
+ }
137
+ const parent = path.dirname(current)
138
+ if (parent === current) return
139
+ current = parent
140
+ }
141
+ }
142
+
143
+ const resolved = envPath || findBinary(scriptDir)
144
+ if (!resolved) {
145
+ console.error(
146
+ `It seems that your package manager failed to install the right ${command} CLI package. Try manually installing ` +
147
+ names.map((name) => `"${name}"`).join(" or ") +
148
+ " package",
149
+ )
150
+ process.exit(1)
151
+ }
152
+ run(resolved)
package/package.json CHANGED
@@ -1,29 +1,35 @@
1
1
  {
2
2
  "name": "@mettlelabs/mettle",
3
- "version": "0.0.0-beta.2",
4
- "license": "UNLICENSED",
5
- "type": "module",
6
- "bin": {
7
- "mettle": "bin/mettle.js"
8
- },
9
- "scripts": {
10
- "postinstall": "node bin/postinstall.js"
11
- },
12
- "files": [
13
- "bin"
14
- ],
15
- "engines": {
16
- "node": "24.x"
17
- },
3
+ "version": "0.0.0-beta.20",
4
+ "license": "MIT",
18
5
  "repository": {
19
6
  "type": "git",
20
7
  "url": "git+https://github.com/prolabsinc/mettle-cli.git"
21
8
  },
9
+ "bin": {
10
+ "mettle": "./bin/mettle.cjs"
11
+ },
12
+ "os": [
13
+ "darwin",
14
+ "linux",
15
+ "win32"
16
+ ],
17
+ "cpu": [
18
+ "arm64",
19
+ "x64"
20
+ ],
22
21
  "optionalDependencies": {
23
- "@mettlelabs/mettle-darwin-arm64": "npm:@mettlelabs/mettle@0.0.0-beta.2-darwin-arm64",
24
- "@mettlelabs/mettle-darwin-x64": "npm:@mettlelabs/mettle@0.0.0-beta.2-darwin-x64",
25
- "@mettlelabs/mettle-linux-x64": "npm:@mettlelabs/mettle@0.0.0-beta.2-linux-x64",
26
- "@mettlelabs/mettle-linux-arm64": "npm:@mettlelabs/mettle@0.0.0-beta.2-linux-arm64",
27
- "@mettlelabs/mettle-win32-x64": "npm:@mettlelabs/mettle@0.0.0-beta.2-win32-x64"
22
+ "@mettlelabs/mettle-darwin-arm64": "0.0.0-beta.20",
23
+ "@mettlelabs/mettle-darwin-x64": "0.0.0-beta.20",
24
+ "@mettlelabs/mettle-darwin-x64-baseline": "0.0.0-beta.20",
25
+ "@mettlelabs/mettle-linux-arm64": "0.0.0-beta.20",
26
+ "@mettlelabs/mettle-linux-arm64-musl": "0.0.0-beta.20",
27
+ "@mettlelabs/mettle-linux-x64": "0.0.0-beta.20",
28
+ "@mettlelabs/mettle-linux-x64-baseline": "0.0.0-beta.20",
29
+ "@mettlelabs/mettle-linux-x64-baseline-musl": "0.0.0-beta.20",
30
+ "@mettlelabs/mettle-linux-x64-musl": "0.0.0-beta.20",
31
+ "@mettlelabs/mettle-windows-arm64": "0.0.0-beta.20",
32
+ "@mettlelabs/mettle-windows-x64": "0.0.0-beta.20",
33
+ "@mettlelabs/mettle-windows-x64-baseline": "0.0.0-beta.20"
28
34
  }
29
- }
35
+ }
package/bin/mettle.js DELETED
@@ -1,53 +0,0 @@
1
- #!/usr/bin/env node
2
- // docs/scripts/src/launcher.md
3
-
4
- import { spawn } from "node:child_process";
5
- import { createRequire } from "node:module";
6
- import { constants } from "node:os";
7
- import { dirname, join } from "node:path";
8
-
9
- const require = createRequire(import.meta.url);
10
- const { name, bin, optionalDependencies } = require("../package.json");
11
- const target = `${process.platform}-${process.arch}`;
12
- const [command] = Object.keys(bin);
13
- const executable = process.platform === "win32" ? `${command}.exe` : command;
14
-
15
- let binary;
16
- try {
17
- binary = join(
18
- dirname(require.resolve(`${name}-${target}/package.json`)),
19
- "bin",
20
- executable,
21
- );
22
- } catch {
23
- const supported = Object.keys(optionalDependencies)
24
- .map((alias) => alias.slice(name.length + 1))
25
- .join(", ");
26
- process.stderr.write(
27
- `${name} has no build installed for ${target}. Builds exist for ${supported}. ` +
28
- "If yours is listed, reinstall without --omit=optional or --no-optional.\n",
29
- );
30
- process.exit(1);
31
- }
32
-
33
- const child = spawn(binary, process.argv.slice(2), { stdio: "inherit" });
34
-
35
- const ignored =
36
- process.platform === "win32" ? ["SIGINT"] : ["SIGINT", "SIGHUP", "SIGQUIT"];
37
- for (const signal of ignored) process.on(signal, () => {});
38
- process.on("SIGTERM", () => child.kill("SIGTERM"));
39
-
40
- child.on("error", (error) => {
41
- process.stderr.write(`${binary}: ${error.message}\n`);
42
- process.exit(1);
43
- });
44
-
45
- child.on("exit", (code, signal) => {
46
- if (signal) {
47
- process.removeAllListeners(signal);
48
- process.exitCode = 128 + constants.signals[signal];
49
- process.kill(process.pid, signal);
50
- return;
51
- }
52
- process.exit(code);
53
- });
@@ -1,28 +0,0 @@
1
- // docs/scripts/src/postinstall.md
2
-
3
- import { closeSync, openSync, readFileSync, writeSync } from "node:fs";
4
-
5
- const { engines } = JSON.parse(
6
- readFileSync(new URL("../package.json", import.meta.url), "utf8"),
7
- );
8
- const node = engines.node.replace(/\.x$/, "");
9
-
10
- const next = `
11
- Mettle CLI installed.
12
-
13
- Next:
14
- mettle login save your model provider key
15
- cd your-project the folder you want to investigate
16
- mettle open the chat
17
-
18
- Needs Docker running and Node.js ${node}.
19
-
20
- `;
21
-
22
- if (!process.env.CI) {
23
- try {
24
- const terminal = openSync("/dev/tty", "w");
25
- writeSync(terminal, next);
26
- closeSync(terminal);
27
- } catch {}
28
- }