fix(js): refuse npm installs in the JS workspaces, keep npx and npm run

Inside a workspace folder npm treats the folder as its own project and
resolves it from the registry, past pnpm-workspace.yaml's overrides and
release-age gate; the root preinstall never runs there, and
--ignore-scripts skips it at the root. Each workspace folder and the root
now carry an .npmrc with engine-strict=true and an engines.npm that no
npm satisfies. npm checks engines only when it builds a dependency tree,
so install (with --ignore-scripts, --package-lock-only or --force), ci,
update, dedupe, uninstall and link fail with EBADENGINE on npm 10 to 12,
while npx, npm exec and npm run work. pnpm reads neither.

The root refusal needs the root devEngines gone (npm skips root engines
while it is set), so this builds on the single-source pnpm pin. The root
.npmrc also makes npx strict about engines anywhere in the checkout.
npm-shrinkwrap.json joins package-lock.json in .gitignore.
This commit is contained in:
Maciej Lisiewski
2026-11-06 17:24:14 +01:00
committed by Hermes Agent
parent 787ee808ae
commit d4c15db2ba
23 changed files with 200 additions and 3 deletions

8
.gitignore vendored
View File

@@ -63,6 +63,14 @@ MagicMock/
# symlink node_modules to the main checkout; the dir-only pattern let one
# slip into a commit and break `npm ci` on CI with ENOTDIR).
node_modules
# pnpm-lock.yaml is the workspaces' only lock: an npm run anywhere in the tree must not add
# another (npm 11's `npm shrinkwrap` is not refused). The standalone npm projects keep theirs;
# a new standalone npm project must add its own `!` line here, or git silently skips its lock.
**/package-lock.json
**/npm-shrinkwrap.json
!/website/package-lock.json
!/scripts/whatsapp-bridge/package-lock.json
!/plugins/platforms/photon/sidecar/package-lock.json
browser-use/
agent-browser/
# Private keys

8
.npmrc Normal file
View File

@@ -0,0 +1,8 @@
# npm treats this folder as a project of its own and would resolve it from the registry,
# past pnpm-workspace.yaml's overrides and release-age gate. engines.npm in package.json is
# no valid range, and engine-strict turns that into a refusal for every command that builds
# a dependency tree here (install, ci, update, dedupe, uninstall, link, --package-lock-only,
# --ignore-scripts, --force). npx, npm exec and npm run do not check it. pnpm ignores both.
# This root file also covers every checkout folder without a package.json (agent/, tools/,
# Docker's /opt/hermes): there npx refuses, not warns, a package whose engines.node fails.
engine-strict=true

View File

@@ -218,6 +218,21 @@ npm ci --prefix website
npm run build:fast --prefix website
```
In the repository root and the JS workspace folders, npm refuses every command that
installs or resolves dependencies (`npm install` with or without `--ignore-scripts`,
`--package-lock-only` or `--force`, `npm ci`, `update`, `dedupe`, `uninstall`,
`link`): each of these folders has an `.npmrc` with `engine-strict=true`, and its
`package.json` declares an `engines.npm` that no npm satisfies. `npm rebuild` and
`npm pkg set` are not refused. An explicit `--engine-strict=false` overrides the
refusal.
`npx`, `npm exec` and `npm run` keep working, so MCP servers and tools still start.
But `engine-strict` applies anywhere in the checkout: in these folders, and through
the root `.npmrc` in every folder without a `package.json` of its own (`agent/`,
`tools/`, the Docker image's `/opt/hermes`). There `npx` refuses a package whose own
`engines` the current Node does not satisfy, where it would only warn outside the
checkout.
Use a Node version accepted by the corresponding `package.json` engines.
Native desktop dependencies can also require the platform build toolchain.

View File

@@ -0,0 +1,6 @@
# npm treats this folder as a project of its own and would resolve it from the registry,
# past pnpm-workspace.yaml's overrides and release-age gate. engines.npm in package.json is
# no valid range, and engine-strict turns that into a refusal for every command that builds
# a dependency tree here (install, ci, update, dedupe, uninstall, link, --package-lock-only,
# --ignore-scripts, --force). npx, npm exec and npm run do not check it. pnpm ignores both.
engine-strict=true

View File

@@ -1,6 +1,9 @@
{
"name": "@hermes/bootstrap-installer",
"private": true,
"engines": {
"npm": "npm is refused here: run pnpm install --frozen-lockfile at the repository root"
},
"version": "0.0.0",
"description": "Hermes Setup — signed installer that drives scripts/install.ps1 with a polished native UI.",
"type": "module",

6
apps/desktop/.npmrc Normal file
View File

@@ -0,0 +1,6 @@
# npm treats this folder as a project of its own and would resolve it from the registry,
# past pnpm-workspace.yaml's overrides and release-age gate. engines.npm in package.json is
# no valid range, and engine-strict turns that into a refusal for every command that builds
# a dependency tree here (install, ci, update, dedupe, uninstall, link, --package-lock-only,
# --ignore-scripts, --force). npx, npm exec and npm run do not check it. pnpm ignores both.
engine-strict=true

View File

@@ -12,7 +12,8 @@
"type": "module",
"main": "dist/electron-main.mjs",
"engines": {
"node": ">=26"
"node": ">=26",
"npm": "npm is refused here: run pnpm install --frozen-lockfile at the repository root"
},
"scripts": {
"clean": "pnpm run clean:e2e && pnpm run clean:renderer && pnpm run clean:electron",

View File

@@ -22,7 +22,7 @@ import { zhHantOverrides } from './zh-hant'
// locale's own overlay. overlay-gaps.json maps each English key to the locales that
// lacked it when this check landed. It only ratchets: translating a listed key passes
// untouched, while a key missing from a locale and not listed fails. Prune it with
// `OVERLAY_GAPS_UPDATE=1 npx vitest run src/i18n/overlay-completeness.test.ts`.
// `OVERLAY_GAPS_UPDATE=1 pnpm exec vitest run src/i18n/overlay-completeness.test.ts`.
const OVERLAYS = {
ar: arOverrides,
de: deOverrides,

6
apps/shared/.npmrc Normal file
View File

@@ -0,0 +1,6 @@
# npm treats this folder as a project of its own and would resolve it from the registry,
# past pnpm-workspace.yaml's overrides and release-age gate. engines.npm in package.json is
# no valid range, and engine-strict turns that into a refusal for every command that builds
# a dependency tree here (install, ci, update, dedupe, uninstall, link, --package-lock-only,
# --ignore-scripts, --force). npx, npm exec and npm run do not check it. pnpm ignores both.
engine-strict=true

View File

@@ -1,6 +1,9 @@
{
"name": "@hermes/shared",
"private": true,
"engines": {
"npm": "npm is refused here: run pnpm install --frozen-lockfile at the repository root"
},
"version": "0.0.0",
"type": "module",
"exports": {

View File

@@ -42,7 +42,8 @@
},
"engines": {
"node": ">=26",
"pnpm": "^12"
"pnpm": "^12",
"npm": "npm is refused here: run pnpm install --frozen-lockfile at the repository root"
},
"dependencies": {
"js-yaml": "4.3.2",

6
tests-js/.npmrc Normal file
View File

@@ -0,0 +1,6 @@
# npm treats this folder as a project of its own and would resolve it from the registry,
# past pnpm-workspace.yaml's overrides and release-age gate. engines.npm in package.json is
# no valid range, and engine-strict turns that into a refusal for every command that builds
# a dependency tree here (install, ci, update, dedupe, uninstall, link, --package-lock-only,
# --ignore-scripts, --force). npx, npm exec and npm run do not check it. pnpm ignores both.
engine-strict=true

View File

@@ -0,0 +1,70 @@
import { spawnSync } from 'node:child_process'
import { cpSync, existsSync, globSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { dirname, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { load } from 'js-yaml'
import { afterAll, expect, test } from 'vitest'
const repo = resolve(dirname(fileURLToPath(import.meta.url)), '..')
const { packages } = load(readFileSync(join(repo, 'pnpm-workspace.yaml'), 'utf8'))
const workspaces = packages.flatMap(pattern => globSync(pattern, { cwd: repo }))
.filter(dir => existsSync(join(repo, dir, 'package.json'))).sort()
// The root too: its preinstall does not stop `npm install --ignore-scripts`.
const folders = ['.', ...workspaces]
const scratch = mkdtempSync(join(tmpdir(), 'npm in a workspace-'))
afterAll(() => rmSync(scratch, { recursive: true, force: true }))
const userconfig = join(scratch, 'empty-npmrc')
writeFileSync(userconfig, '')
// A scratch copy of the workspace's own npm inputs (package.json and .npmrc) with
// its dependencies dropped: npm then resolves nothing, so it runs offline and any
// refusal comes from the folder's npm config, not from a `workspace:` spec.
function folder(workspace) {
const dir = join(scratch, workspace === '.' ? 'root' : workspace.replaceAll('/', '_'))
mkdirSync(dir, { recursive: true })
const manifest = JSON.parse(readFileSync(join(repo, workspace, 'package.json'), 'utf8'))
for (const field of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) delete manifest[field]
writeFileSync(join(dir, 'package.json'), JSON.stringify(manifest))
if (existsSync(join(repo, workspace, '.npmrc'))) cpSync(join(repo, workspace, '.npmrc'), join(dir, '.npmrc'))
return dir
}
// Only the folder's config counts: an empty user npmrc and no inherited npm_config_*
// (npm_config_force or npm_config_engine_strict would change the answer).
function npm(cwd, args) {
const env = Object.fromEntries(Object.entries(process.env).filter(([name]) => !/^npm_config_/i.test(name)))
return spawnSync('npm', args, {
cwd, encoding: 'utf8', shell: process.platform === 'win32', timeout: 120_000,
env: { ...env, npm_config_userconfig: userconfig, npm_config_cache: join(scratch, 'npm-cache'),
npm_config_logs_dir: join(scratch, 'npm-logs'), npm_config_offline: 'true', npm_config_update_notifier: 'false',
npm_config_audit: 'false', npm_config_fund: 'false' },
})
}
// The root preinstall never runs for `npm install` inside a workspace folder, and
// --ignore-scripts skips it anyway: npm treats the folder as a project of its own
// and resolves it from the registry, past pnpm-workspace.yaml's overrides and
// release-age gate, into a stray package-lock.json.
test.each(folders)('npm refuses to install or lock inside %s', workspace => {
const cwd = folder(workspace)
for (const args of [['install', '--package-lock-only', '--ignore-scripts', '--force'], ['install', '--ignore-scripts']]) {
const run = npm(cwd, args)
expect(run.error).toBeUndefined()
expect(run.stderr).toMatch(/EBADENGINE[\s\S]*run pnpm install --frozen-lockfile at the repository root/)
expect(run.status).not.toBe(0)
expect(existsSync(join(cwd, 'package-lock.json'))).toBe(false)
expect(existsSync(join(cwd, 'node_modules'))).toBe(false)
}
}, 60_000)
// Tools and MCP servers started with a workspace folder as their cwd go through npx.
test.each(folders)('npm exec (npx) and npm run still work inside %s', workspace => {
const cwd = folder(workspace)
for (const args of [['exec', '--', 'node', '--version'], ['run']]) {
const run = npm(cwd, args)
expect(run.error).toBeUndefined()
expect(run.stderr).not.toMatch(/EBADENGINE|EBADDEVENGINES/)
expect(run.status).toBe(0)
}
}, 60_000)

View File

@@ -1,6 +1,9 @@
{
"name": "@hermes/root-tests",
"private": true,
"engines": {
"npm": "npm is refused here: run pnpm install --frozen-lockfile at the repository root"
},
"type": "module",
"scripts": {
"typecheck": "tsc --noEmit -p tsconfig.json",

6
ui-tui/.npmrc Normal file
View File

@@ -0,0 +1,6 @@
# npm treats this folder as a project of its own and would resolve it from the registry,
# past pnpm-workspace.yaml's overrides and release-age gate. engines.npm in package.json is
# no valid range, and engine-strict turns that into a refusal for every command that builds
# a dependency tree here (install, ci, update, dedupe, uninstall, link, --package-lock-only,
# --ignore-scripts, --force). npx, npm exec and npm run do not check it. pnpm ignores both.
engine-strict=true

View File

@@ -2,6 +2,9 @@
"name": "hermes-tui",
"version": "0.0.1",
"private": true,
"engines": {
"npm": "npm is refused here: run pnpm install --frozen-lockfile at the repository root"
},
"type": "module",
"scripts": {
"dev": "pnpm run build:ink && tsx --watch src/entry.tsx",

View File

@@ -0,0 +1,6 @@
# npm treats this folder as a project of its own and would resolve it from the registry,
# past pnpm-workspace.yaml's overrides and release-age gate. engines.npm in package.json is
# no valid range, and engine-strict turns that into a refusal for every command that builds
# a dependency tree here (install, ci, update, dedupe, uninstall, link, --package-lock-only,
# --ignore-scripts, --force). npx, npm exec and npm run do not check it. pnpm ignores both.
engine-strict=true

View File

@@ -2,6 +2,9 @@
"name": "@hermes/ink",
"version": "0.0.1",
"private": true,
"engines": {
"npm": "npm is refused here: run pnpm install --frozen-lockfile at the repository root"
},
"type": "module",
"scripts": {
"build": "esbuild src/entry-exports.ts --bundle --platform=node --format=esm --packages=external --outdir=dist",

6
web/.npmrc Normal file
View File

@@ -0,0 +1,6 @@
# npm treats this folder as a project of its own and would resolve it from the registry,
# past pnpm-workspace.yaml's overrides and release-age gate. engines.npm in package.json is
# no valid range, and engine-strict turns that into a refusal for every command that builds
# a dependency tree here (install, ci, update, dedupe, uninstall, link, --package-lock-only,
# --ignore-scripts, --force). npx, npm exec and npm run do not check it. pnpm ignores both.
engine-strict=true

View File

@@ -1,6 +1,9 @@
{
"name": "web",
"private": true,
"engines": {
"npm": "npm is refused here: run pnpm install --frozen-lockfile at the repository root"
},
"version": "0.0.0",
"type": "module",
"scripts": {

View File

@@ -240,6 +240,21 @@ npm ci --prefix website
npm run build:fast --prefix website
```
In the repository root and the JS workspace folders, npm refuses every command that
installs or resolves dependencies (`npm install` with or without `--ignore-scripts`,
`--package-lock-only` or `--force`, `npm ci`, `update`, `dedupe`, `uninstall`,
`link`): each of these folders has an `.npmrc` with `engine-strict=true`, and its
`package.json` declares an `engines.npm` that no npm satisfies. `npm rebuild` and
`npm pkg set` are not refused. An explicit `--engine-strict=false` overrides the
refusal.
`npx`, `npm exec` and `npm run` keep working, so MCP servers and tools still start.
But `engine-strict` applies anywhere in the checkout: in these folders, and through
the root `.npmrc` in every folder without a `package.json` of its own (`agent/`,
`tools/`, the Docker image's `/opt/hermes`). There `npx` refuses a package whose own
`engines` the current Node does not satisfy, where it would only warn outside the
checkout.
Use a Node version accepted by the corresponding `package.json` engines.
Native desktop dependencies can also require the platform build toolchain.

View File

@@ -451,6 +451,21 @@ which install it with the pinned pnpm under `--frozen-lockfile` (with
the manifests and the release-age policy, not which pnpm wrote it. A user agent
overridden through `pnpm_config_user_agent` is refused as well.
In the repository root and the JS workspace folders, npm refuses every command that
installs or resolves dependencies (`npm install` with or without `--ignore-scripts`,
`--package-lock-only` or `--force`, `npm ci`, `update`, `dedupe`, `uninstall`,
`link`): each of these folders has an `.npmrc` with `engine-strict=true`, and its
`package.json` declares an `engines.npm` that no npm satisfies. `npm rebuild` and
`npm pkg set` are not refused. An explicit `--engine-strict=false` overrides the
refusal.
`npx`, `npm exec` and `npm run` keep working, so MCP servers and tools still start.
But `engine-strict` applies anywhere in the checkout: in these folders, and through
the root `.npmrc` in every folder without a `package.json` of its own (`agent/`,
`tools/`, the Docker image's `/opt/hermes`). There `npx` refuses a package whose own
`engines` the current Node does not satisfy, where it would only warn outside the
checkout.
The website is a separate npm project: `npm ci --prefix website`, then
`npm run build:fast --prefix website`. PM activation supplies tools, not these
`node_modules` directories or built assets. Native desktop builds have additional

View File

@@ -90,6 +90,10 @@ npm ci --prefix website
npm run build:fast --prefix website
```
在仓库根目录和各 JS workspace 目录中,npm 会拒绝所有安装或解析依赖的命令(`npm install`,无论是否带 `--ignore-scripts`、`--package-lock-only` 或 `--force`,以及 `npm ci`、`update`、`dedupe`、`uninstall`、`link`):这些目录各有一个设置了 `engine-strict=true` 的 `.npmrc`,其 `package.json` 声明了任何 npm 都无法满足的 `engines.npm`。`npm rebuild` 和 `npm pkg set` 不会被拒绝。显式传入 `--engine-strict=false` 可绕过该拒绝。
`npx`、`npm exec` 和 `npm run` 仍可使用,因此 MCP 服务器和工具照常启动。但 `engine-strict` 作用于整个检出目录:这些目录本身,以及通过根目录 `.npmrc` 作用于所有没有自己 `package.json` 的位置(`agent/`、`tools/`、Docker 镜像的 `/opt/hermes`)。在这些位置 `npx` 会拒绝自身 `engines` 与当前 Node 不符的包,而在检出目录之外只会警告。
图标从 `assets/nous-girl-*.svg` 和 `assets/backgrounds/` 生成。
`node scripts/generate-icons.mjs` 使用 Hermes 运行时 Python(`HERMES_PYTHON`,否则为 PATH 上的 `python`)渲染图标:Pillow 和 resvg-py 是核心依赖。不要提交生成的 PNG/ICO/ICNS 文件。