hermes-agent 0.19.0 → 0.20.1
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/DISCLAIMER.md +15 -16
- package/NOTICE +13 -11
- package/PRIVACY.md +59 -22
- package/README.md +472 -89
- package/SECURITY.md +291 -138
- package/bin/hermes-npm.js +5 -0
- package/lib/npm-channel.js +533 -0
- package/lib/package-metadata.js +1 -1
- package/lib/python-launcher.js +45 -52
- package/lib/upstream-migration.js +336 -0
- package/lib/uv-installer.js +258 -0
- package/package.json +20 -6
- package/scripts/postinstall.js +294 -46
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
const { spawn } = require("node:child_process");
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
const os = require("node:os");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
|
|
6
|
+
const packageJson = require("../package.json");
|
|
7
|
+
const { getRuntimeSourceDirectory } = require("./python-launcher");
|
|
8
|
+
|
|
9
|
+
const packageRoot = path.resolve(__dirname, "..");
|
|
10
|
+
const upstreamRepositoryUrls = new Set([
|
|
11
|
+
"https://github.com/NousResearch/hermes-agent",
|
|
12
|
+
"https://github.com/NousResearch/hermes-agent.git",
|
|
13
|
+
"git@github.com:NousResearch/hermes-agent.git",
|
|
14
|
+
"ssh://git@github.com/NousResearch/hermes-agent.git"
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
function npmCommand(platform = process.platform) {
|
|
18
|
+
return platform === "win32" ? "npm.cmd" : "npm";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function platformPath(platform = process.platform) {
|
|
22
|
+
return platform === "win32" ? path.win32 : path.posix;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getDefaultHermesHome(platform = process.platform, env = process.env, home = os.homedir()) {
|
|
26
|
+
const paths = platformPath(platform);
|
|
27
|
+
if (env.HERMES_HOME) return paths.resolve(env.HERMES_HOME);
|
|
28
|
+
if (platform === "win32") {
|
|
29
|
+
return paths.resolve(env.LOCALAPPDATA || paths.join(home, "AppData", "Local"), "hermes");
|
|
30
|
+
}
|
|
31
|
+
return paths.resolve(home, ".hermes");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isPathInside(parent, candidate, platform = process.platform) {
|
|
35
|
+
const paths = platformPath(platform);
|
|
36
|
+
const relative = paths.relative(paths.resolve(parent), paths.resolve(candidate));
|
|
37
|
+
if (relative === "") return true;
|
|
38
|
+
if (relative === ".." || relative.startsWith(`..${paths.sep}`) || paths.isAbsolute(relative)) return false;
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getOfficialConsoleExecutable(installDirectory, platform = process.platform) {
|
|
43
|
+
const paths = platformPath(platform);
|
|
44
|
+
return platform === "win32"
|
|
45
|
+
? paths.join(installDirectory, "venv", "Scripts", "hermes.exe")
|
|
46
|
+
: paths.join(installDirectory, "venv", "bin", "hermes");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getUpstreamInstallerInvocation(plan, platform = process.platform) {
|
|
50
|
+
if (platform === "win32") {
|
|
51
|
+
return {
|
|
52
|
+
command: "powershell.exe",
|
|
53
|
+
args: [
|
|
54
|
+
"-NoProfile",
|
|
55
|
+
"-ExecutionPolicy", "Bypass",
|
|
56
|
+
"-File", plan.installerPath,
|
|
57
|
+
"-Commit", plan.upstreamCommit,
|
|
58
|
+
"-ForceCommit",
|
|
59
|
+
"-SkipSetup",
|
|
60
|
+
"-NonInteractive",
|
|
61
|
+
"-InstallDir", plan.installDirectory,
|
|
62
|
+
"-HermesHome", plan.hermesHome
|
|
63
|
+
]
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
command: "bash",
|
|
68
|
+
args: [
|
|
69
|
+
plan.installerPath,
|
|
70
|
+
"--commit", plan.upstreamCommit,
|
|
71
|
+
"--force-commit",
|
|
72
|
+
"--skip-setup",
|
|
73
|
+
"--non-interactive",
|
|
74
|
+
"--dir", plan.installDirectory,
|
|
75
|
+
"--hermes-home", plan.hermesHome
|
|
76
|
+
]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function getUpstreamPathInvocation(plan, platform = process.platform) {
|
|
81
|
+
const paths = platformPath(platform);
|
|
82
|
+
const installedScript = platform === "win32"
|
|
83
|
+
? paths.join(plan.installDirectory, "scripts", "install.ps1")
|
|
84
|
+
: paths.join(plan.installDirectory, "scripts", "install.sh");
|
|
85
|
+
if (platform === "win32") {
|
|
86
|
+
return {
|
|
87
|
+
command: "powershell.exe",
|
|
88
|
+
args: [
|
|
89
|
+
"-NoProfile",
|
|
90
|
+
"-ExecutionPolicy", "Bypass",
|
|
91
|
+
"-File", installedScript,
|
|
92
|
+
"-Stage", "path",
|
|
93
|
+
"-NonInteractive",
|
|
94
|
+
"-InstallDir", plan.installDirectory,
|
|
95
|
+
"-HermesHome", plan.hermesHome
|
|
96
|
+
]
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
command: "bash",
|
|
101
|
+
args: [
|
|
102
|
+
installedScript,
|
|
103
|
+
"--stage", "path",
|
|
104
|
+
"--non-interactive",
|
|
105
|
+
"--dir", plan.installDirectory,
|
|
106
|
+
"--hermes-home", plan.hermesHome
|
|
107
|
+
]
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function getNpmUninstallArgs(context, packageName = packageJson.name) {
|
|
112
|
+
const args = ["uninstall"];
|
|
113
|
+
if (context.isGlobal) args.push("--global");
|
|
114
|
+
args.push(packageName);
|
|
115
|
+
return args;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function createUpstreamMigrationPlan(context, options = {}) {
|
|
119
|
+
const platform = options.platform || process.platform;
|
|
120
|
+
const paths = platformPath(platform);
|
|
121
|
+
const hermesHome = getDefaultHermesHome(platform, options.env || process.env, options.home || os.homedir());
|
|
122
|
+
const installDirectory = paths.join(hermesHome, "hermes-agent");
|
|
123
|
+
const sourceDirectory = getRuntimeSourceDirectory();
|
|
124
|
+
const installerPath = platform === "win32"
|
|
125
|
+
? paths.join(sourceDirectory, "scripts", "install.ps1")
|
|
126
|
+
: paths.join(sourceDirectory, "scripts", "install.sh");
|
|
127
|
+
const plan = {
|
|
128
|
+
mode: "one-way-upstream-handoff",
|
|
129
|
+
from: "npm-isolated",
|
|
130
|
+
to: "upstream-managed",
|
|
131
|
+
platform,
|
|
132
|
+
npmPackage: packageJson.name,
|
|
133
|
+
npmVersion: packageJson.version,
|
|
134
|
+
upstreamRelease: packageJson.hermesAgent.upstreamGitTag,
|
|
135
|
+
upstreamCommit: packageJson.hermesAgent.upstreamCommit,
|
|
136
|
+
hermesHome,
|
|
137
|
+
installDirectory,
|
|
138
|
+
installerPath,
|
|
139
|
+
consoleExecutable: getOfficialConsoleExecutable(installDirectory, platform),
|
|
140
|
+
npmManagedInstall: Boolean(context.isGlobal || context.projectRoot),
|
|
141
|
+
installScope: context.isGlobal ? "global" : "local",
|
|
142
|
+
npmWorkingDirectory: context.projectRoot || process.cwd()
|
|
143
|
+
};
|
|
144
|
+
plan.installer = getUpstreamInstallerInvocation(plan, platform);
|
|
145
|
+
plan.finalizePath = getUpstreamPathInvocation(plan, platform);
|
|
146
|
+
plan.npmUninstall = {
|
|
147
|
+
command: npmCommand(platform),
|
|
148
|
+
args: getNpmUninstallArgs(context)
|
|
149
|
+
};
|
|
150
|
+
return plan;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function spawnAndWait(command, args, options = {}) {
|
|
154
|
+
return new Promise((resolve, reject) => {
|
|
155
|
+
const child = spawn(command, args, {
|
|
156
|
+
cwd: options.cwd || process.cwd(),
|
|
157
|
+
env: options.env || process.env,
|
|
158
|
+
stdio: options.stdio || "inherit",
|
|
159
|
+
windowsHide: false
|
|
160
|
+
});
|
|
161
|
+
child.on("error", reject);
|
|
162
|
+
child.on("exit", (code, signal) => {
|
|
163
|
+
if (signal) {
|
|
164
|
+
reject(new Error(`${command} terminated by signal ${signal}`));
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (code !== 0) {
|
|
168
|
+
reject(new Error(`${command} exited with code ${code ?? 1}`));
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
resolve();
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function normalizeRepositoryUrl(value) {
|
|
177
|
+
return (value || "").trim().replace(/\/$/, "");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function quotePosixArgument(value) {
|
|
181
|
+
return `'${value.replace(/'/gu, `'"'"'`)}'`;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function quotePowerShellArgument(value) {
|
|
185
|
+
return `'${value.replace(/'/gu, "''")}'`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function formatInvocation(invocation, platform = process.platform) {
|
|
189
|
+
const values = [invocation.command, ...invocation.args];
|
|
190
|
+
if (platform === "win32") {
|
|
191
|
+
return `& ${values.map(quotePowerShellArgument).join(" ")}`;
|
|
192
|
+
}
|
|
193
|
+
return values.map(quotePosixArgument).join(" ");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function resolveThroughExistingAncestor(target) {
|
|
197
|
+
let current = path.resolve(target);
|
|
198
|
+
const missingSegments = [];
|
|
199
|
+
while (!fs.existsSync(current)) {
|
|
200
|
+
const parent = path.dirname(current);
|
|
201
|
+
if (parent === current) break;
|
|
202
|
+
missingSegments.unshift(path.basename(current));
|
|
203
|
+
current = parent;
|
|
204
|
+
}
|
|
205
|
+
const resolvedAncestor = fs.realpathSync.native(current);
|
|
206
|
+
return path.resolve(resolvedAncestor, ...missingSegments);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function inspectExistingTarget(plan, runGit) {
|
|
210
|
+
if (!fs.existsSync(plan.installDirectory)) return { exists: false, kind: "absent" };
|
|
211
|
+
if (!fs.existsSync(path.join(plan.installDirectory, ".git"))) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
`Refusing to replace the existing non-Git directory at ${plan.installDirectory}. ` +
|
|
214
|
+
"Move or remove it explicitly, then retry."
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
const origin = normalizeRepositoryUrl(runGit(["-C", plan.installDirectory, "remote", "get-url", "origin"]));
|
|
218
|
+
if (!upstreamRepositoryUrls.has(origin)) {
|
|
219
|
+
throw new Error(`Refusing to modify ${plan.installDirectory}: unexpected Git origin ${origin || "unknown"}.`);
|
|
220
|
+
}
|
|
221
|
+
const dirty = runGit(["-C", plan.installDirectory, "status", "--porcelain"]);
|
|
222
|
+
if (dirty === null) {
|
|
223
|
+
throw new Error(`Refusing to modify ${plan.installDirectory}: Git status could not be verified.`);
|
|
224
|
+
}
|
|
225
|
+
if (dirty !== "") {
|
|
226
|
+
throw new Error(
|
|
227
|
+
`Refusing to modify the dirty upstream checkout at ${plan.installDirectory}. ` +
|
|
228
|
+
"Commit, stash, or remove its changes explicitly, then retry."
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
return { exists: true, kind: "upstream-checkout", origin };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function assertMigrationPreconditions(plan, runtimeStatus, runGit) {
|
|
235
|
+
if (!plan.npmManagedInstall) {
|
|
236
|
+
throw new Error(
|
|
237
|
+
"The command is not running from an npm-managed node_modules installation; refusing to modify or uninstall the source checkout."
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
if (runtimeStatus.runtimeChannel !== "npm-release") {
|
|
241
|
+
throw new Error(
|
|
242
|
+
"The npm runtime is not at its release-pinned commit. Run 'hermes-npm update', then retry the migration."
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
if (!fs.existsSync(plan.installerPath)) {
|
|
246
|
+
throw new Error(`Pinned upstream installer is missing: ${plan.installerPath}`);
|
|
247
|
+
}
|
|
248
|
+
const canonicalPackageRoot = resolveThroughExistingAncestor(packageRoot);
|
|
249
|
+
const canonicalHermesHome = resolveThroughExistingAncestor(plan.hermesHome);
|
|
250
|
+
const canonicalInstallDirectory = resolveThroughExistingAncestor(plan.installDirectory);
|
|
251
|
+
if (
|
|
252
|
+
isPathInside(packageRoot, plan.hermesHome, plan.platform) ||
|
|
253
|
+
isPathInside(packageRoot, plan.installDirectory, plan.platform) ||
|
|
254
|
+
isPathInside(canonicalPackageRoot, canonicalHermesHome, plan.platform) ||
|
|
255
|
+
isPathInside(canonicalPackageRoot, canonicalInstallDirectory, plan.platform)
|
|
256
|
+
) {
|
|
257
|
+
throw new Error(
|
|
258
|
+
"HERMES_HOME or its install target resolves inside the npm package and would be removed with it; " +
|
|
259
|
+
"choose an external HERMES_HOME."
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
return inspectExistingTarget(plan, runGit);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function executeUpstreamMigration(plan, helpers) {
|
|
266
|
+
const existingTarget = assertMigrationPreconditions(plan, helpers.runtimeStatus, helpers.runGit);
|
|
267
|
+
await (helpers.spawnAndWait || spawnAndWait)(plan.installer.command, plan.installer.args, {
|
|
268
|
+
cwd: packageRoot,
|
|
269
|
+
env: process.env
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
const installedCommit = helpers.runGit(["-C", plan.installDirectory, "rev-parse", "HEAD"]);
|
|
273
|
+
const installedDirty = helpers.runGit(["-C", plan.installDirectory, "status", "--porcelain"]);
|
|
274
|
+
if (
|
|
275
|
+
installedCommit !== plan.upstreamCommit ||
|
|
276
|
+
installedDirty !== "" ||
|
|
277
|
+
!fs.existsSync(plan.consoleExecutable)
|
|
278
|
+
) {
|
|
279
|
+
throw new Error(
|
|
280
|
+
"The upstream installer completed, but a clean exact commit or Hermes console executable could not be verified. " +
|
|
281
|
+
"The npm package was kept."
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
let uninstallError = null;
|
|
286
|
+
try {
|
|
287
|
+
await (helpers.spawnAndWait || spawnAndWait)(plan.npmUninstall.command, plan.npmUninstall.args, {
|
|
288
|
+
cwd: plan.npmWorkingDirectory,
|
|
289
|
+
env: process.env
|
|
290
|
+
});
|
|
291
|
+
} catch (error) {
|
|
292
|
+
uninstallError = error;
|
|
293
|
+
}
|
|
294
|
+
try {
|
|
295
|
+
await (helpers.spawnAndWait || spawnAndWait)(plan.finalizePath.command, plan.finalizePath.args, {
|
|
296
|
+
cwd: plan.installDirectory,
|
|
297
|
+
env: process.env
|
|
298
|
+
});
|
|
299
|
+
} catch (error) {
|
|
300
|
+
const state = uninstallError
|
|
301
|
+
? "npm removal failed and the official command PATH stage also failed"
|
|
302
|
+
: "npm ownership was removed, but the official command PATH stage failed";
|
|
303
|
+
throw new Error(
|
|
304
|
+
`${state}: ${error.message}. ` +
|
|
305
|
+
`Run ${formatInvocation(plan.finalizePath, plan.platform)} manually.`
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
if (uninstallError) {
|
|
309
|
+
throw new Error(
|
|
310
|
+
`The upstream deployment was verified, but npm removal failed: ${uninstallError.message}. ` +
|
|
311
|
+
`Run ${formatInvocation(plan.npmUninstall, plan.platform)} manually, then ` +
|
|
312
|
+
`${formatInvocation(plan.finalizePath, plan.platform)}.`
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
return { existingTarget, installedCommit };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
module.exports = {
|
|
319
|
+
assertMigrationPreconditions,
|
|
320
|
+
createUpstreamMigrationPlan,
|
|
321
|
+
executeUpstreamMigration,
|
|
322
|
+
formatInvocation,
|
|
323
|
+
getDefaultHermesHome,
|
|
324
|
+
getNpmUninstallArgs,
|
|
325
|
+
getOfficialConsoleExecutable,
|
|
326
|
+
getUpstreamInstallerInvocation,
|
|
327
|
+
getUpstreamPathInvocation,
|
|
328
|
+
inspectExistingTarget,
|
|
329
|
+
isPathInside,
|
|
330
|
+
normalizeRepositoryUrl,
|
|
331
|
+
platformPath,
|
|
332
|
+
quotePosixArgument,
|
|
333
|
+
quotePowerShellArgument,
|
|
334
|
+
resolveThroughExistingAncestor,
|
|
335
|
+
spawnAndWait
|
|
336
|
+
};
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
const crypto = require("node:crypto");
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const zlib = require("node:zlib");
|
|
5
|
+
|
|
6
|
+
const UV_VERSION = "0.12.2";
|
|
7
|
+
const MAX_ARCHIVE_SIZE = 128 * 1024 * 1024;
|
|
8
|
+
const MAX_EXTRACTED_SIZE = 256 * 1024 * 1024;
|
|
9
|
+
|
|
10
|
+
const UV_ASSET_SHA256 = Object.freeze({
|
|
11
|
+
"uv-aarch64-apple-darwin.tar.gz": "fa909fea3bc06f460db79017030a221fdbc43ec4478f089cb554d8335c090817",
|
|
12
|
+
"uv-aarch64-pc-windows-msvc.zip": "dccc2bb7724c015f2a82467dee5bf4b2353a3fcdbfdfb30e0f93cdf5db2dd1df",
|
|
13
|
+
"uv-aarch64-unknown-linux-gnu.tar.gz": "19b7f1f66895261fbaa07f8ea91da0f86337ad4e47efa594e87641c1718ffc52",
|
|
14
|
+
"uv-aarch64-unknown-linux-musl.tar.gz": "73b87f0d65d7dfcd39753a51ce65592360b02c29f8e1bc2c85cc4190fe914499",
|
|
15
|
+
"uv-arm-unknown-linux-musleabihf.tar.gz": "4e27dfadda93c82dd85c2de29b7fd6417ea74c430bfbc52833ea9580c8c16d04",
|
|
16
|
+
"uv-armv7-unknown-linux-gnueabihf.tar.gz": "0536e78e9796394fa135102c7500f24a291aaf9fbf129b70add472b6dcf42a4b",
|
|
17
|
+
"uv-armv7-unknown-linux-musleabihf.tar.gz": "5e10ffda5760511a16c0d5a9b2c28ebaed864dfa34e73fddcf0f600cf125cfee",
|
|
18
|
+
"uv-i686-pc-windows-msvc.zip": "e2037092f25370ecbd8827b1d91650a9fbf002548ae647aea39073c6bbe45384",
|
|
19
|
+
"uv-i686-unknown-linux-gnu.tar.gz": "659b83b91a329a6bf5fbb412ea61262640b9bf15f07b6208334bd7a379c0dbf0",
|
|
20
|
+
"uv-i686-unknown-linux-musl.tar.gz": "b57cc4b2bd5e1cc20253222add0d377a5398c2bafc93611bd2a4438ac8e21f9c",
|
|
21
|
+
"uv-powerpc64le-unknown-linux-gnu.tar.gz": "0e135c0fddbd303297a847016ea3cb60fdacebed20bd87200a3537cfb67d4d46",
|
|
22
|
+
"uv-riscv64gc-unknown-linux-gnu.tar.gz": "cc348cecc84695394721e2fc1e0c4fd5b9a052d4eeeba57b194929c719d5681e",
|
|
23
|
+
"uv-riscv64gc-unknown-linux-musl.tar.gz": "a0e9a9d99e0f2cc39b645aecdabe27e308074b1d3dc2afdd507433528c97e701",
|
|
24
|
+
"uv-s390x-unknown-linux-gnu.tar.gz": "78797ad74c948950181b607be0989b1d5926a2096d81def4238192c95ff47aeb",
|
|
25
|
+
"uv-x86_64-apple-darwin.tar.gz": "a6e6506a9109801222d65d17461abf4ed13bdecc5d2b13af0495418a82972c6b",
|
|
26
|
+
"uv-x86_64-pc-windows-msvc.zip": "01442d8ce5c7124151a73e697c836d252c6da853c18c73206d3cc4c2378a91d2",
|
|
27
|
+
"uv-x86_64-unknown-linux-gnu.tar.gz": "d66e96b5f1ca3b99806eee283a8125d33a0bd669e6e6d9bc4ab7ffda63c41bf4",
|
|
28
|
+
"uv-x86_64-unknown-linux-musl.tar.gz": "2dbe8209c9592f6d1009b8565f4bf29813427907bee2236023c013101ede343f"
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function detectLinuxLibc() {
|
|
32
|
+
const report = process.report?.getReport?.();
|
|
33
|
+
return report?.header?.glibcVersionRuntime ? "gnu" : "musl";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getUvAsset(options = {}) {
|
|
37
|
+
const platform = options.platform || process.platform;
|
|
38
|
+
const arch = options.arch || process.arch;
|
|
39
|
+
const libc = options.libc || (platform === "linux" ? detectLinuxLibc() : undefined);
|
|
40
|
+
const armVersion = Number(options.armVersion || process.config?.variables?.arm_version || 7);
|
|
41
|
+
const endianness = options.endianness || process.config?.variables?.node_byteorder || "little";
|
|
42
|
+
|
|
43
|
+
let target;
|
|
44
|
+
if (platform === "win32") {
|
|
45
|
+
target = { x64: "x86_64-pc-windows-msvc", arm64: "aarch64-pc-windows-msvc", ia32: "i686-pc-windows-msvc" }[arch];
|
|
46
|
+
} else if (platform === "darwin") {
|
|
47
|
+
target = { x64: "x86_64-apple-darwin", arm64: "aarch64-apple-darwin" }[arch];
|
|
48
|
+
} else if (platform === "linux") {
|
|
49
|
+
const linuxTargets = {
|
|
50
|
+
x64: `x86_64-unknown-linux-${libc}`,
|
|
51
|
+
arm64: `aarch64-unknown-linux-${libc}`,
|
|
52
|
+
ia32: `i686-unknown-linux-${libc}`,
|
|
53
|
+
riscv64: `riscv64gc-unknown-linux-${libc}`,
|
|
54
|
+
s390x: libc === "gnu" ? "s390x-unknown-linux-gnu" : undefined,
|
|
55
|
+
ppc64: libc === "gnu" && endianness === "little" ? "powerpc64le-unknown-linux-gnu" : undefined,
|
|
56
|
+
arm: armVersion >= 7 ? `armv7-unknown-linux-${libc}eabihf` : libc === "musl" ? "arm-unknown-linux-musleabihf" : undefined
|
|
57
|
+
};
|
|
58
|
+
target = linuxTargets[arch];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!target) {
|
|
62
|
+
throw new Error(`Unsupported platform/architecture: ${platform}/${arch}${libc ? `/${libc}` : ""}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const extension = platform === "win32" ? ".zip" : ".tar.gz";
|
|
66
|
+
const name = `uv-${target}${extension}`;
|
|
67
|
+
const sha256 = UV_ASSET_SHA256[name];
|
|
68
|
+
if (!sha256) {
|
|
69
|
+
throw new Error(`No pinned checksum for uv asset: ${name}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
name,
|
|
74
|
+
sha256,
|
|
75
|
+
url: `https://github.com/astral-sh/uv/releases/download/${UV_VERSION}/${name}`
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function findEndOfCentralDirectory(archive) {
|
|
80
|
+
const minimumOffset = Math.max(0, archive.length - 65_557);
|
|
81
|
+
for (let offset = archive.length - 22; offset >= minimumOffset; offset -= 1) {
|
|
82
|
+
if (archive.readUInt32LE(offset) === 0x06054b50) return offset;
|
|
83
|
+
}
|
|
84
|
+
throw new Error("Invalid zip archive: end-of-central-directory record not found");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function extractFromZip(archive, expectedName) {
|
|
88
|
+
const eocdOffset = findEndOfCentralDirectory(archive);
|
|
89
|
+
const entryCount = archive.readUInt16LE(eocdOffset + 10);
|
|
90
|
+
let offset = archive.readUInt32LE(eocdOffset + 16);
|
|
91
|
+
|
|
92
|
+
for (let index = 0; index < entryCount; index += 1) {
|
|
93
|
+
if (archive.readUInt32LE(offset) !== 0x02014b50) {
|
|
94
|
+
throw new Error("Invalid zip archive: central-directory entry not found");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const flags = archive.readUInt16LE(offset + 8);
|
|
98
|
+
const method = archive.readUInt16LE(offset + 10);
|
|
99
|
+
const compressedSize = archive.readUInt32LE(offset + 20);
|
|
100
|
+
const uncompressedSize = archive.readUInt32LE(offset + 24);
|
|
101
|
+
const fileNameLength = archive.readUInt16LE(offset + 28);
|
|
102
|
+
const extraLength = archive.readUInt16LE(offset + 30);
|
|
103
|
+
const commentLength = archive.readUInt16LE(offset + 32);
|
|
104
|
+
const localHeaderOffset = archive.readUInt32LE(offset + 42);
|
|
105
|
+
const fileName = archive.subarray(offset + 46, offset + 46 + fileNameLength).toString("utf8");
|
|
106
|
+
|
|
107
|
+
if (path.posix.basename(fileName) === expectedName) {
|
|
108
|
+
if ((flags & 1) !== 0) throw new Error("Encrypted zip entries are not supported");
|
|
109
|
+
if (uncompressedSize > MAX_EXTRACTED_SIZE) throw new Error("uv executable exceeds the extraction size limit");
|
|
110
|
+
if (archive.readUInt32LE(localHeaderOffset) !== 0x04034b50) {
|
|
111
|
+
throw new Error("Invalid zip archive: local file header not found");
|
|
112
|
+
}
|
|
113
|
+
const localNameLength = archive.readUInt16LE(localHeaderOffset + 26);
|
|
114
|
+
const localExtraLength = archive.readUInt16LE(localHeaderOffset + 28);
|
|
115
|
+
const dataOffset = localHeaderOffset + 30 + localNameLength + localExtraLength;
|
|
116
|
+
const compressed = archive.subarray(dataOffset, dataOffset + compressedSize);
|
|
117
|
+
const extracted = method === 0
|
|
118
|
+
? Buffer.from(compressed)
|
|
119
|
+
: method === 8
|
|
120
|
+
? zlib.inflateRawSync(compressed, { maxOutputLength: MAX_EXTRACTED_SIZE })
|
|
121
|
+
: null;
|
|
122
|
+
if (!extracted) throw new Error(`Unsupported zip compression method: ${method}`);
|
|
123
|
+
if (extracted.length !== uncompressedSize) throw new Error("Invalid zip archive: extracted size mismatch");
|
|
124
|
+
return extracted;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
offset += 46 + fileNameLength + extraLength + commentLength;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
throw new Error(`${expectedName} was not found in the uv zip archive`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function readTarString(buffer, start, length) {
|
|
134
|
+
const end = buffer.indexOf(0, start);
|
|
135
|
+
const boundedEnd = end === -1 || end > start + length ? start + length : end;
|
|
136
|
+
return buffer.subarray(start, boundedEnd).toString("utf8");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function extractFromTarGz(archive, expectedName) {
|
|
140
|
+
const tar = zlib.gunzipSync(archive, { maxOutputLength: MAX_EXTRACTED_SIZE });
|
|
141
|
+
let offset = 0;
|
|
142
|
+
|
|
143
|
+
while (offset + 512 <= tar.length) {
|
|
144
|
+
const header = tar.subarray(offset, offset + 512);
|
|
145
|
+
if (header.every((byte) => byte === 0)) break;
|
|
146
|
+
|
|
147
|
+
const name = readTarString(header, 0, 100);
|
|
148
|
+
const prefix = readTarString(header, 345, 155);
|
|
149
|
+
const fullName = prefix ? `${prefix}/${name}` : name;
|
|
150
|
+
const sizeText = readTarString(header, 124, 12).trim().replace(/\0.*$/u, "");
|
|
151
|
+
const size = Number.parseInt(sizeText || "0", 8);
|
|
152
|
+
const type = header[156];
|
|
153
|
+
if (!Number.isFinite(size)) throw new Error("Invalid tar archive: invalid entry size");
|
|
154
|
+
|
|
155
|
+
const dataOffset = offset + 512;
|
|
156
|
+
if ((type === 0 || type === 48) && path.posix.basename(fullName) === expectedName) {
|
|
157
|
+
return Buffer.from(tar.subarray(dataOffset, dataOffset + size));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
offset = dataOffset + Math.ceil(size / 512) * 512;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
throw new Error(`${expectedName} was not found in the uv tar archive`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function extractUvBinary(archive, assetName, platform = process.platform) {
|
|
167
|
+
const expectedName = platform === "win32" ? "uv.exe" : "uv";
|
|
168
|
+
return assetName.endsWith(".zip")
|
|
169
|
+
? extractFromZip(archive, expectedName)
|
|
170
|
+
: extractFromTarGz(archive, expectedName);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function verifySha256(buffer, expectedSha256) {
|
|
174
|
+
const actualSha256 = crypto.createHash("sha256").update(buffer).digest("hex");
|
|
175
|
+
if (actualSha256 !== expectedSha256) {
|
|
176
|
+
throw new Error(`uv archive checksum mismatch: expected ${expectedSha256}, received ${actualSha256}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function downloadAsset(url) {
|
|
181
|
+
const response = await fetch(url, {
|
|
182
|
+
headers: { "User-Agent": "hermes-agent-npm" },
|
|
183
|
+
redirect: "follow",
|
|
184
|
+
signal: AbortSignal.timeout(120_000)
|
|
185
|
+
});
|
|
186
|
+
if (!response.ok) {
|
|
187
|
+
throw new Error(`Failed to download uv: HTTP ${response.status} ${response.statusText}`);
|
|
188
|
+
}
|
|
189
|
+
const contentLength = Number(response.headers.get("content-length") || 0);
|
|
190
|
+
if (contentLength > MAX_ARCHIVE_SIZE) {
|
|
191
|
+
throw new Error(`uv archive exceeds the ${MAX_ARCHIVE_SIZE}-byte download limit`);
|
|
192
|
+
}
|
|
193
|
+
if (!response.body) throw new Error("Failed to download uv: response body is empty");
|
|
194
|
+
|
|
195
|
+
const chunks = [];
|
|
196
|
+
const reader = response.body.getReader();
|
|
197
|
+
let totalLength = 0;
|
|
198
|
+
while (true) {
|
|
199
|
+
const { done, value } = await reader.read();
|
|
200
|
+
if (done) break;
|
|
201
|
+
totalLength += value.byteLength;
|
|
202
|
+
if (totalLength > MAX_ARCHIVE_SIZE) {
|
|
203
|
+
await reader.cancel();
|
|
204
|
+
throw new Error(`uv archive exceeds the ${MAX_ARCHIVE_SIZE}-byte download limit`);
|
|
205
|
+
}
|
|
206
|
+
chunks.push(Buffer.from(value));
|
|
207
|
+
}
|
|
208
|
+
return Buffer.concat(chunks, totalLength);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function getUvExecutable(packageRoot, platform = process.platform) {
|
|
212
|
+
return path.join(packageRoot, ".uv_bin", platform === "win32" ? "uv.exe" : "uv");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function ensureUv(packageRoot) {
|
|
216
|
+
const asset = getUvAsset();
|
|
217
|
+
const uvDir = path.join(packageRoot, ".uv_bin");
|
|
218
|
+
const executable = getUvExecutable(packageRoot);
|
|
219
|
+
const markerPath = path.join(uvDir, "install.json");
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
const marker = JSON.parse(fs.readFileSync(markerPath, "utf8"));
|
|
223
|
+
if (marker.version === UV_VERSION && marker.asset === asset.name && marker.sha256 === asset.sha256 && fs.existsSync(executable)) {
|
|
224
|
+
return executable;
|
|
225
|
+
}
|
|
226
|
+
} catch {
|
|
227
|
+
// A missing or invalid marker causes a clean reinstall of the pinned binary.
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
console.log(`Downloading uv ${UV_VERSION} for ${process.platform}/${process.arch}...`);
|
|
231
|
+
const archive = await downloadAsset(asset.url);
|
|
232
|
+
verifySha256(archive, asset.sha256);
|
|
233
|
+
const binary = extractUvBinary(archive, asset.name);
|
|
234
|
+
|
|
235
|
+
fs.mkdirSync(uvDir, { recursive: true });
|
|
236
|
+
const temporaryExecutable = `${executable}.tmp-${process.pid}`;
|
|
237
|
+
try {
|
|
238
|
+
fs.writeFileSync(temporaryExecutable, binary, { mode: 0o755 });
|
|
239
|
+
fs.chmodSync(temporaryExecutable, 0o755);
|
|
240
|
+
fs.rmSync(executable, { force: true });
|
|
241
|
+
fs.renameSync(temporaryExecutable, executable);
|
|
242
|
+
fs.writeFileSync(markerPath, `${JSON.stringify({ version: UV_VERSION, asset: asset.name, sha256: asset.sha256 }, null, 2)}\n`, "utf8");
|
|
243
|
+
} finally {
|
|
244
|
+
fs.rmSync(temporaryExecutable, { force: true });
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return executable;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
module.exports = {
|
|
251
|
+
UV_ASSET_SHA256,
|
|
252
|
+
UV_VERSION,
|
|
253
|
+
ensureUv,
|
|
254
|
+
extractUvBinary,
|
|
255
|
+
getUvAsset,
|
|
256
|
+
getUvExecutable,
|
|
257
|
+
verifySha256
|
|
258
|
+
};
|
package/package.json
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hermes-agent",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Unofficial npm bridge for Hermes Agent 0.
|
|
3
|
+
"version": "0.20.1",
|
|
4
|
+
"description": "Unofficial npm bridge for Hermes Agent 0.20.1: The self-improving AI agent \u2014 creates skills from experience, improves them during use, and runs anywhere",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"hermes-agent",
|
|
8
|
+
"ai-agent",
|
|
9
|
+
"npm-bridge",
|
|
10
|
+
"uv",
|
|
11
|
+
"python",
|
|
12
|
+
"cross-platform"
|
|
13
|
+
],
|
|
6
14
|
"type": "commonjs",
|
|
7
15
|
"bin": {
|
|
8
16
|
"hermes": "bin/hermes.js",
|
|
9
|
-
"hermes-agent": "bin/hermes-agent.js"
|
|
17
|
+
"hermes-agent": "bin/hermes-agent.js",
|
|
18
|
+
"hermes-npm": "bin/hermes-npm.js"
|
|
10
19
|
},
|
|
11
20
|
"scripts": {
|
|
12
21
|
"build:alias": "node scripts/build-alias-package.js",
|
|
13
22
|
"postinstall": "node scripts/postinstall.js",
|
|
14
|
-
"
|
|
23
|
+
"smoke": "node scripts/runtime-smoke.js",
|
|
24
|
+
"test": "node --test \"test/*.test.js\""
|
|
15
25
|
},
|
|
16
26
|
"repository": {
|
|
17
27
|
"type": "git",
|
|
@@ -36,7 +46,11 @@
|
|
|
36
46
|
"SECURITY.md"
|
|
37
47
|
],
|
|
38
48
|
"hermesAgent": {
|
|
39
|
-
"
|
|
40
|
-
"upstreamRepository": "
|
|
49
|
+
"upstreamVersion": "0.20.1",
|
|
50
|
+
"upstreamRepository": "NousResearch/hermes-agent",
|
|
51
|
+
"upstreamGitTag": "v2026.8.13",
|
|
52
|
+
"upstreamCommit": "f80f453ae0679347e38abc917c7f94f717bf96c5",
|
|
53
|
+
"pythonVersion": "3.11",
|
|
54
|
+
"runtimeDirectory": "runtime/hermes-agent"
|
|
41
55
|
}
|
|
42
56
|
}
|