@hanzo/cli 8.5.890 → 8.5.910
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 +9 -7
- package/bin/hanzo.js +129 -10
- package/install.js +242 -31
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
# @hanzo/cli
|
|
2
2
|
|
|
3
|
-
The Hanzo CLI —
|
|
3
|
+
The Hanzo CLI — unified entrypoint for Hanzo AI cloud, `dev` coding agent, `hanzo-mcp`, `hanzo-engine` local inference, `hanzo-node` (`hanzod`), and `hanzo-vm`.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npm i -g
|
|
6
|
+
npm i -g hanzo
|
|
7
7
|
hanzo --help
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
`postinstall`
|
|
11
|
-
matching this package's version
|
|
12
|
-
|
|
13
|
-
`
|
|
14
|
-
|
|
10
|
+
`postinstall` stays lightweight by downloading only the `hanzo` CLI binary for
|
|
11
|
+
your platform from the GitHub release matching this package's version and
|
|
12
|
+
verifying it against its `.sha256` sidecar. Companion binaries (`dev`,
|
|
13
|
+
`hanzo-mcp`, `hanzo-engine`, `hanzod`, `zt`, `hanzo-vm`) are downloaded and
|
|
14
|
+
verified **lazily on first use** into `bin/`, and `bin/hanzo.js` prepends its
|
|
15
|
+
own `bin/` directory to `PATH` (handling Windows `Path` case-insensitively) so
|
|
16
|
+
companion executables are always discoverable.
|
|
15
17
|
|
|
16
18
|
Prebuilt for macOS (arm64, x64), Linux (arm64, x64) and Windows (x64). On any
|
|
17
19
|
other platform the install is skipped with a warning rather than failing.
|
package/bin/hanzo.js
CHANGED
|
@@ -1,22 +1,141 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Hand the real binary the argv it was given and get out of the way.
|
|
3
3
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// binary
|
|
4
|
+
// Prepends this `bin/` directory to PATH (handling Windows `Path`
|
|
5
|
+
// case-insensitively) so sibling binaries (`dev`, `hanzo-mcp`, `hanzo-engine`,
|
|
6
|
+
// `hanzo-vm`, `zt`, `hanzod`) are always discoverable, and lazily fetches any
|
|
7
|
+
// missing companion binary on first invocation via `../install.js`.
|
|
8
8
|
const { spawnSync } = require("node:child_process");
|
|
9
|
-
const { existsSync } = require("node:fs");
|
|
10
|
-
const { join } = require("node:path");
|
|
9
|
+
const { existsSync, realpathSync } = require("node:fs");
|
|
10
|
+
const { basename, delimiter, join } = require("node:path");
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
13
|
+
const installScript = join(__dirname, "..", "install.js");
|
|
14
|
+
|
|
15
|
+
const env = { ...process.env };
|
|
16
|
+
const pathKey =
|
|
17
|
+
Object.keys(env).find((key) => key.toLowerCase() === "path") || "PATH";
|
|
18
|
+
|
|
19
|
+
env[pathKey] = __dirname + delimiter + (env[pathKey] || "");
|
|
20
|
+
|
|
21
|
+
const TOOL_BINS = {
|
|
22
|
+
hanzo: "hanzo",
|
|
23
|
+
dev: "dev",
|
|
24
|
+
mcp: "hanzo-mcp",
|
|
25
|
+
gen: "gen",
|
|
26
|
+
zt: "zt",
|
|
27
|
+
engine: "hanzo-engine",
|
|
28
|
+
vm: "hanzo-vm",
|
|
29
|
+
node: "hanzod",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// A tool counts as present when its native binary sits beside this launcher,
|
|
33
|
+
// or anywhere on PATH as a REAL binary. npm's own global shims (`hanzo-mcp`,
|
|
34
|
+
// `hanzo-dev`, … all symlinks to this very file) are on PATH too, and must not
|
|
35
|
+
// count: treating one as the tool skips the download and then execs nothing.
|
|
36
|
+
function realBinary(p) {
|
|
37
|
+
try {
|
|
38
|
+
return !realpathSync(p).endsWith(".js");
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function hasLocal(tool) {
|
|
45
|
+
return existsSync(join(__dirname, (TOOL_BINS[tool] || tool) + ext));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function hasTool(tool) {
|
|
49
|
+
if (hasLocal(tool)) return true;
|
|
50
|
+
const binName = (TOOL_BINS[tool] || tool) + ext;
|
|
51
|
+
for (const dir of (env[pathKey] || "").split(delimiter)) {
|
|
52
|
+
const p = dir && join(dir, binName);
|
|
53
|
+
if (p && existsSync(p) && realBinary(p)) return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isHelpOrVersion(args) {
|
|
59
|
+
return args.some((a) => a === "--help" || a === "-h" || a === "--version" || a === "-V" || a === "version" || a === "help");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const rawName = basename(process.argv[1] || "hanzo").replace(/\.(js|cmd|ps1|exe)$/i, "");
|
|
63
|
+
let argv = process.argv.slice(2);
|
|
64
|
+
let targetTool = "hanzo";
|
|
65
|
+
const required = [];
|
|
66
|
+
|
|
67
|
+
if (rawName === "hanzo-dev" || rawName === "dev") {
|
|
68
|
+
targetTool = "dev";
|
|
69
|
+
required.push("dev", "mcp");
|
|
70
|
+
} else if (rawName === "hanzo-mcp" || rawName === "mcp") {
|
|
71
|
+
targetTool = "mcp";
|
|
72
|
+
required.push("mcp");
|
|
73
|
+
} else if (rawName === "hanzo-engine") {
|
|
74
|
+
targetTool = "engine";
|
|
75
|
+
required.push("engine");
|
|
76
|
+
} else if (rawName === "hanzo-node" || rawName === "hanzod") {
|
|
77
|
+
targetTool = "hanzo";
|
|
78
|
+
argv = ["chain", ...(argv.length ? argv : ["up"])];
|
|
79
|
+
required.push("hanzo", "node");
|
|
80
|
+
} else {
|
|
81
|
+
required.push("hanzo");
|
|
82
|
+
const sub = argv[0];
|
|
83
|
+
if (sub === "mcp") {
|
|
84
|
+
targetTool = "mcp";
|
|
85
|
+
argv = argv.slice(1);
|
|
86
|
+
required.length = 0;
|
|
87
|
+
required.push("mcp");
|
|
88
|
+
} else if (sub === "node" && ["up", "join", "status", "stop"].includes(argv[1])) {
|
|
89
|
+
argv = ["chain", ...argv.slice(1)];
|
|
90
|
+
if (!isHelpOrVersion(argv)) required.push("node");
|
|
91
|
+
} else if (sub === "engine" && argv[1] === "run") {
|
|
92
|
+
targetTool = "engine";
|
|
93
|
+
argv = argv.slice(1);
|
|
94
|
+
required.length = 0;
|
|
95
|
+
required.push("engine");
|
|
96
|
+
} else if (!isHelpOrVersion(argv)) {
|
|
97
|
+
if (!sub || sub.startsWith("-") || sub === "dev" || sub === "code" || sub === "desktop") {
|
|
98
|
+
required.push("dev", "mcp");
|
|
99
|
+
} else if (sub === "__mcp") {
|
|
100
|
+
required.push("mcp");
|
|
101
|
+
} else if (sub === "engine" && argv[1] === "serve") {
|
|
102
|
+
required.push("engine");
|
|
103
|
+
} else if (sub === "link" || sub === "zt") {
|
|
104
|
+
required.push("zt");
|
|
105
|
+
} else if (sub === "vm" || sub === "up" || sub === "build") {
|
|
106
|
+
required.push("vm");
|
|
107
|
+
} else if (sub === "chain") {
|
|
108
|
+
required.push("node");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// The binary this launcher execs must be HERE (it is run by absolute path);
|
|
114
|
+
// companions only need to be findable on PATH, which starts here.
|
|
115
|
+
// `@hanzo/mcp` taught `… mcp serve`; the native server serves stdio bare, so a
|
|
116
|
+
// leading `serve` is the same request and must not die as an unknown command.
|
|
117
|
+
if (targetTool === "mcp" && argv[0] === "serve") argv = argv.slice(1);
|
|
118
|
+
|
|
119
|
+
const missing = required.filter((t) => (t === targetTool ? !hasLocal(t) : !hasTool(t)));
|
|
120
|
+
if (missing.length > 0 && existsSync(installScript) && env.HANZO_NO_LAZY_INSTALL !== "1") {
|
|
121
|
+
spawnSync(process.execPath, [installScript, ...missing], {
|
|
122
|
+
stdio: "inherit",
|
|
123
|
+
env,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const binName = (TOOL_BINS[targetTool] || "hanzo") + ext;
|
|
128
|
+
const bin = join(__dirname, binName);
|
|
13
129
|
if (!existsSync(bin)) {
|
|
14
130
|
console.error(
|
|
15
|
-
|
|
16
|
-
"if that was skipped (--ignore-scripts) run `node " + join(__dirname, "..", "install.js") + "`."
|
|
131
|
+
`hanzo: the ${TOOL_BINS[targetTool] || "hanzo"} binary is missing. Run \`node ${installScript} ${targetTool}\` to fetch it.`
|
|
17
132
|
);
|
|
18
133
|
process.exit(1);
|
|
19
134
|
}
|
|
20
|
-
|
|
135
|
+
|
|
136
|
+
const r = spawnSync(bin, argv, {
|
|
137
|
+
stdio: "inherit",
|
|
138
|
+
env,
|
|
139
|
+
});
|
|
21
140
|
if (r.error) { console.error("hanzo:", r.error.message); process.exit(1); }
|
|
22
141
|
process.exit(r.status ?? 0);
|
package/install.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Fetch the binary for THIS platform from the GitHub release for THIS version
|
|
2
|
+
// Fetch the binary for THIS platform from the GitHub release for THIS version,
|
|
3
|
+
// and lazily fetch companion stack binaries (`dev`, `hanzo-mcp`, `gen`, `zt`,
|
|
4
|
+
// `hanzo-engine`, `hanzo-vm`, `hanzod`) on demand when invoked with tool names.
|
|
3
5
|
//
|
|
4
6
|
// Why a downloader rather than five optionalDependencies (which is what
|
|
5
7
|
// @hanzo/dev does): the release matrix already publishes
|
|
@@ -8,13 +10,14 @@
|
|
|
8
10
|
// same bytes under a second set of version numbers, and they drift — that is
|
|
9
11
|
// how a `latest` ends up serving last week's binary for one platform only.
|
|
10
12
|
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
|
|
13
|
+
// By default (`postinstall` with no args), ONLY `hanzo` (+ `hanzo-cli` alias)
|
|
14
|
+
// is downloaded so `npm install -g hanzo` stays fast and lightweight. Companion
|
|
15
|
+
// binaries (`dev`, `mcp`, `engine`, `node`, `zt`, `vm`, `gen`) are fetched
|
|
16
|
+
// lazily on first use by `bin/hanzo.js` (or eagerly with `HANZO_NPM_EAGER=1` /
|
|
17
|
+
// `node install.js --all`).
|
|
18
|
+
const { createWriteStream, mkdirSync, chmodSync, copyFileSync, existsSync, symlinkSync, unlinkSync, writeFileSync } = require("node:fs");
|
|
16
19
|
const { createHash } = require("node:crypto");
|
|
17
|
-
const {
|
|
20
|
+
const { rm } = require("node:fs/promises");
|
|
18
21
|
const { join } = require("node:path");
|
|
19
22
|
const { execFileSync } = require("node:child_process");
|
|
20
23
|
const { pipeline } = require("node:stream/promises");
|
|
@@ -22,10 +25,17 @@ const { pipeline } = require("node:stream/promises");
|
|
|
22
25
|
const VERSION = require("./package.json").version;
|
|
23
26
|
const REPO = "hanzoai/cli";
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
const TOOLS = {
|
|
29
|
+
hanzo: { repo: "hanzoai/cli", bin: "hanzo", alias: "hanzo-cli", versioned: true },
|
|
30
|
+
mcp: { repo: "hanzoai/mcp", bin: "hanzo-mcp", alias: "mcp" },
|
|
31
|
+
dev: { repo: "hanzoai/dev", bin: "dev", alias: "hanzo-dev" },
|
|
32
|
+
gen: { repo: "hanzoai/gen", bin: "gen", alias: "hanzo-gen" },
|
|
33
|
+
zt: { repo: "hanzozt/zt", bin: "zt", alias: "hanzo-zet" },
|
|
34
|
+
engine: { repo: "hanzoai/engine", bin: "hanzo-engine", alias: "hanzoai", kind: "engine" },
|
|
35
|
+
vm: { repo: "hanzoai/vm", bin: "hanzo-vm", alias: "", kind: "vm" },
|
|
36
|
+
node: { repo: "hanzoai/node", bin: "hanzod", alias: "hanzo-node" },
|
|
37
|
+
};
|
|
38
|
+
|
|
29
39
|
const TARGETS = {
|
|
30
40
|
"darwin-arm64": "darwin-arm64",
|
|
31
41
|
"darwin-x64": "darwin-amd64",
|
|
@@ -34,30 +44,47 @@ const TARGETS = {
|
|
|
34
44
|
"win32-x64": "windows-amd64",
|
|
35
45
|
};
|
|
36
46
|
|
|
47
|
+
const ENGINE_TARGETS = {
|
|
48
|
+
"darwin-arm64": "macos-arm64",
|
|
49
|
+
"darwin-x64": "macos-amd64",
|
|
50
|
+
"linux-arm64": "linux-arm64",
|
|
51
|
+
"linux-x64": "linux-amd64",
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const VM_TARGETS = {
|
|
55
|
+
"darwin-arm64": "darwin-aarch64",
|
|
56
|
+
"linux-arm64": "linux-aarch64",
|
|
57
|
+
"linux-x64": "linux-x86_64",
|
|
58
|
+
};
|
|
59
|
+
|
|
37
60
|
async function get(url) {
|
|
38
61
|
const res = await fetch(url, { redirect: "follow" });
|
|
39
62
|
if (!res.ok) throw new Error(`${res.status} ${res.statusText} for ${url}`);
|
|
40
63
|
return res;
|
|
41
64
|
}
|
|
42
65
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
66
|
+
function linkAlias(dest, binName, aliasName, ext) {
|
|
67
|
+
if (!aliasName) return;
|
|
68
|
+
const src = join(dest, `${binName}${ext}`);
|
|
69
|
+
const dst = join(dest, `${aliasName}${ext}`);
|
|
70
|
+
if (!existsSync(src)) return;
|
|
71
|
+
try {
|
|
72
|
+
if (existsSync(dst)) unlinkSync(dst);
|
|
73
|
+
symlinkSync(`${binName}${ext}`, dst);
|
|
74
|
+
} catch {
|
|
75
|
+
copyFileSync(src, dst);
|
|
76
|
+
if (process.platform !== "win32") chmodSync(dst, 0o755);
|
|
51
77
|
}
|
|
78
|
+
}
|
|
52
79
|
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
80
|
+
async function downloadAndExtract({ assetUrl, sha256Url, assetName, dest }) {
|
|
81
|
+
const tmp = join(__dirname, `${process.pid}-${assetName}`);
|
|
82
|
+
let want = null;
|
|
83
|
+
if (sha256Url) {
|
|
84
|
+
want = (await (await get(sha256Url)).text()).trim().split(/\s+/)[0];
|
|
85
|
+
}
|
|
59
86
|
|
|
60
|
-
const res = await get(
|
|
87
|
+
const res = await get(assetUrl);
|
|
61
88
|
const hash = createHash("sha256");
|
|
62
89
|
const file = createWriteStream(tmp);
|
|
63
90
|
await pipeline(res.body, async function* (src) {
|
|
@@ -65,18 +92,202 @@ async function main() {
|
|
|
65
92
|
}, file);
|
|
66
93
|
|
|
67
94
|
const got = hash.digest("hex");
|
|
68
|
-
if (got !== want) {
|
|
95
|
+
if (want && got !== want) {
|
|
69
96
|
await rm(tmp, { force: true });
|
|
70
|
-
throw new Error(`checksum mismatch for ${
|
|
97
|
+
throw new Error(`checksum mismatch for ${assetName}\n expected ${want}\n got ${got}`);
|
|
71
98
|
}
|
|
72
99
|
|
|
73
100
|
mkdirSync(dest, { recursive: true });
|
|
74
101
|
execFileSync("tar", ["-xzf", tmp, "-C", dest]);
|
|
75
102
|
await rm(tmp, { force: true });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function fetchStandardTool({ base, bin, alias, target, dest, ext }) {
|
|
106
|
+
const asset = `${bin}-${target}.tar.gz`;
|
|
107
|
+
await downloadAndExtract({
|
|
108
|
+
assetUrl: `${base}/${asset}`,
|
|
109
|
+
sha256Url: `${base}/${asset}.sha256`,
|
|
110
|
+
assetName: asset,
|
|
111
|
+
dest,
|
|
112
|
+
});
|
|
113
|
+
const out = join(dest, `${bin}${ext}`);
|
|
114
|
+
if (existsSync(out) && process.platform !== "win32") chmodSync(out, 0o755);
|
|
115
|
+
linkAlias(dest, bin, alias, ext);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function fetchEngine({ key, dest, ext }) {
|
|
119
|
+
const engineTarget = ENGINE_TARGETS[key];
|
|
120
|
+
if (!engineTarget) {
|
|
121
|
+
throw new Error(`no prebuilt hanzo-engine binary for ${key}; install via https://github.com/hanzoai/engine`);
|
|
122
|
+
}
|
|
123
|
+
const asset = `hanzoai-${engineTarget}.tar.gz`;
|
|
124
|
+
let tag = "v1.7.92";
|
|
125
|
+
let sha256Url = null;
|
|
126
|
+
try {
|
|
127
|
+
const res = await fetch("https://api.github.com/repos/hanzoai/engine/releases?per_page=15", {
|
|
128
|
+
headers: { "User-Agent": "@hanzo/cli" },
|
|
129
|
+
});
|
|
130
|
+
if (res.ok) {
|
|
131
|
+
const releases = await res.json();
|
|
132
|
+
const match = releases.find(
|
|
133
|
+
(r) => Array.isArray(r.assets) && r.assets.some((a) => a.name === asset)
|
|
134
|
+
);
|
|
135
|
+
if (match) {
|
|
136
|
+
tag = match.tag_name;
|
|
137
|
+
if (match.assets.some((a) => a.name === `${asset}.sha256`)) {
|
|
138
|
+
sha256Url = `https://github.com/hanzoai/engine/releases/download/${tag}/${asset}.sha256`;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
} catch {
|
|
143
|
+
// Fall back to known release tag with prebuilt assets
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const base = `https://github.com/hanzoai/engine/releases/download/${tag}`;
|
|
147
|
+
await downloadAndExtract({
|
|
148
|
+
assetUrl: `${base}/${asset}`,
|
|
149
|
+
sha256Url,
|
|
150
|
+
assetName: asset,
|
|
151
|
+
dest,
|
|
152
|
+
});
|
|
76
153
|
|
|
77
|
-
const
|
|
78
|
-
if (existsSync(
|
|
79
|
-
|
|
154
|
+
const engine = join(dest, `hanzoai${ext}`);
|
|
155
|
+
if (existsSync(engine) && process.platform !== "win32") chmodSync(engine, 0o755);
|
|
156
|
+
writeFileSync(join(dest, "hanzo-engine"), ENGINE_ADAPTER, { mode: 0o755 });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// The CLI runs `hanzo-engine serve -m MODEL [engine args…]` (commands/engine.rs).
|
|
160
|
+
// The released engine binary (`hanzoai`) has no `serve`: it takes its options
|
|
161
|
+
// first and then a model selector, and serves HTTP only when given a port. This
|
|
162
|
+
// adapter is that translation, and nothing else: any other argv passes through.
|
|
163
|
+
const ENGINE_ADAPTER = `#!/bin/sh
|
|
164
|
+
# hanzo-engine: adapts \`serve -m MODEL [opts]\` to the released engine binary.
|
|
165
|
+
here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
166
|
+
engine="$here/hanzoai"
|
|
167
|
+
[ "\${1:-}" = serve ] || exec "$engine" "$@"
|
|
168
|
+
shift
|
|
169
|
+
model=""; port=""; set -- "$@" --hanzo-end
|
|
170
|
+
while [ "$1" != --hanzo-end ]; do
|
|
171
|
+
case "$1" in
|
|
172
|
+
-m|--model) model="$2"; shift 2 ;;
|
|
173
|
+
-p|--port) port="$2"; shift 2 ;;
|
|
174
|
+
--overlay) shift 2 ;;
|
|
175
|
+
*) set -- "$@" "$1"; shift ;;
|
|
176
|
+
esac
|
|
177
|
+
done
|
|
178
|
+
shift
|
|
179
|
+
[ -n "$model" ] || { echo "hanzo-engine: serve needs -m MODEL" >&2; exit 2; }
|
|
180
|
+
exec "$engine" --port "\${port:-\${HANZO_ENGINE_PORT:-1234}}" "$@" run -m "$model"
|
|
181
|
+
`;
|
|
182
|
+
|
|
183
|
+
async function fetchVm({ key, dest, ext }) {
|
|
184
|
+
const vmTarget = VM_TARGETS[key];
|
|
185
|
+
if (!vmTarget) {
|
|
186
|
+
throw new Error(`no prebuilt hanzo-vm binary for ${key}`);
|
|
187
|
+
}
|
|
188
|
+
let tag = "v2.0.2";
|
|
189
|
+
try {
|
|
190
|
+
const res = await fetch("https://api.github.com/repos/hanzoai/vm/releases/latest", {
|
|
191
|
+
headers: { "User-Agent": "@hanzo/cli" },
|
|
192
|
+
});
|
|
193
|
+
if (res.ok) {
|
|
194
|
+
const rel = await res.json();
|
|
195
|
+
if (rel && rel.tag_name) tag = rel.tag_name;
|
|
196
|
+
}
|
|
197
|
+
} catch {
|
|
198
|
+
// Fall back to v2.0.2
|
|
199
|
+
}
|
|
200
|
+
const asset = `hanzo-vm-${tag}-${vmTarget}.tar.gz`;
|
|
201
|
+
const base = `https://github.com/hanzoai/vm/releases/download/${tag}`;
|
|
202
|
+
await downloadAndExtract({
|
|
203
|
+
assetUrl: `${base}/${asset}`,
|
|
204
|
+
sha256Url: `${base}/${asset}.sha256`,
|
|
205
|
+
assetName: asset,
|
|
206
|
+
dest,
|
|
207
|
+
});
|
|
208
|
+
const out = join(dest, `hanzo-vm${ext}`);
|
|
209
|
+
if (existsSync(out) && process.platform !== "win32") chmodSync(out, 0o755);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function installOne(name, { key, target, dest, ext, optional }) {
|
|
213
|
+
const tool = TOOLS[name];
|
|
214
|
+
if (!tool) return;
|
|
215
|
+
let fellBack = false;
|
|
216
|
+
try {
|
|
217
|
+
if (tool.kind === "engine") {
|
|
218
|
+
await fetchEngine({ key, dest, ext });
|
|
219
|
+
} else if (tool.kind === "vm") {
|
|
220
|
+
await fetchVm({ key, dest, ext });
|
|
221
|
+
} else {
|
|
222
|
+
const primaryBase = tool.versioned
|
|
223
|
+
? `https://github.com/${tool.repo}/releases/download/v${VERSION}`
|
|
224
|
+
: `https://github.com/${tool.repo}/releases/latest/download`;
|
|
225
|
+
try {
|
|
226
|
+
await fetchStandardTool({
|
|
227
|
+
base: primaryBase,
|
|
228
|
+
bin: tool.bin,
|
|
229
|
+
alias: tool.alias,
|
|
230
|
+
target,
|
|
231
|
+
dest,
|
|
232
|
+
ext,
|
|
233
|
+
});
|
|
234
|
+
} catch (err) {
|
|
235
|
+
if (tool.versioned && String(err.message || err).startsWith("404 ")) {
|
|
236
|
+
fellBack = true;
|
|
237
|
+
await fetchStandardTool({
|
|
238
|
+
base: `https://github.com/${tool.repo}/releases/latest/download`,
|
|
239
|
+
bin: tool.bin,
|
|
240
|
+
alias: tool.alias,
|
|
241
|
+
target,
|
|
242
|
+
dest,
|
|
243
|
+
ext,
|
|
244
|
+
});
|
|
245
|
+
} else {
|
|
246
|
+
throw err;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const label = tool.versioned && !fellBack ? `${tool.bin} ${VERSION}` : `${tool.bin} (latest release)`;
|
|
251
|
+
console.error(`@hanzo/cli: installed ${label} (${target})`);
|
|
252
|
+
} catch (err) {
|
|
253
|
+
if (!optional || String(err.message || err).includes("checksum mismatch")) throw err;
|
|
254
|
+
console.warn(`@hanzo/cli: optional companion ${tool.bin} skipped (${err.message})`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function main() {
|
|
259
|
+
const key = `${process.platform}-${process.arch}`;
|
|
260
|
+
const target = TARGETS[key];
|
|
261
|
+
if (!target) {
|
|
262
|
+
console.warn(`@hanzo/cli: no prebuilt binary for ${key}; skipping download.`);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const dest = join(__dirname, "bin");
|
|
267
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
268
|
+
const args = process.argv.slice(2);
|
|
269
|
+
|
|
270
|
+
if (args.length > 0 && !args.includes("--all")) {
|
|
271
|
+
for (const arg of args) {
|
|
272
|
+
const name = arg.replace(/^hanzo-/, "");
|
|
273
|
+
const toolKey = TOOLS[arg] ? arg : TOOLS[name] ? name : null;
|
|
274
|
+
if (toolKey) {
|
|
275
|
+
await installOne(toolKey, { key, target, dest, ext, optional: toolKey === "node" || toolKey === "gen" });
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Default `postinstall`: lightweight install of `hanzo` (+ `hanzo-cli` alias) only.
|
|
282
|
+
// All companion binaries (`dev`, `hanzo-mcp`, `hanzo-engine`, `hanzo-vm`, `zt`, `gen`)
|
|
283
|
+
// are lazily downloaded on first use by `bin/hanzo.js`.
|
|
284
|
+
await installOne("hanzo", { key, target, dest, ext, optional: false });
|
|
285
|
+
|
|
286
|
+
if (process.env.HANZO_NPM_EAGER === "1" || args.includes("--all")) {
|
|
287
|
+
for (const name of ["mcp", "dev", "gen", "zt"]) {
|
|
288
|
+
await installOne(name, { key, target, dest, ext, optional: true });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
80
291
|
}
|
|
81
292
|
|
|
82
293
|
main().catch((err) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/cli",
|
|
3
|
-
"version": "8.5.
|
|
4
|
-
"description": "Hanzo CLI —
|
|
3
|
+
"version": "8.5.910",
|
|
4
|
+
"description": "Hanzo CLI — unified CLI, coding agent (dev), MCP server, local inference engine, and node",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
},
|
|
10
10
|
"homepage": "https://hanzo.ai",
|
|
11
11
|
"bin": {
|
|
12
|
-
"hanzo": "bin/hanzo.js"
|
|
12
|
+
"hanzo": "bin/hanzo.js",
|
|
13
|
+
"hanzo-dev": "bin/hanzo.js",
|
|
14
|
+
"hanzo-mcp": "bin/hanzo.js",
|
|
15
|
+
"hanzo-engine": "bin/hanzo.js",
|
|
16
|
+
"hanzo-node": "bin/hanzo.js"
|
|
13
17
|
},
|
|
14
18
|
"files": [
|
|
15
19
|
"bin/",
|