diff --git a/.gitignore b/.gitignore index 3ccc45bae6..aa9b27899a 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000000..ce3e240734 --- /dev/null +++ b/.npmrc @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 55ba4f33e9..885e398715 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/apps/bootstrap-installer/.npmrc b/apps/bootstrap-installer/.npmrc new file mode 100644 index 0000000000..9cc8843d4c --- /dev/null +++ b/apps/bootstrap-installer/.npmrc @@ -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 diff --git a/apps/bootstrap-installer/package.json b/apps/bootstrap-installer/package.json index 709d920abb..2e5401db80 100644 --- a/apps/bootstrap-installer/package.json +++ b/apps/bootstrap-installer/package.json @@ -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", diff --git a/apps/desktop/.npmrc b/apps/desktop/.npmrc new file mode 100644 index 0000000000..9cc8843d4c --- /dev/null +++ b/apps/desktop/.npmrc @@ -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 diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 9ce8561374..45efaadd98 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -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", diff --git a/apps/desktop/src/i18n/overlay-completeness.test.ts b/apps/desktop/src/i18n/overlay-completeness.test.ts index 11c012739e..730d5784c6 100644 --- a/apps/desktop/src/i18n/overlay-completeness.test.ts +++ b/apps/desktop/src/i18n/overlay-completeness.test.ts @@ -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, diff --git a/apps/shared/.npmrc b/apps/shared/.npmrc new file mode 100644 index 0000000000..9cc8843d4c --- /dev/null +++ b/apps/shared/.npmrc @@ -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 diff --git a/apps/shared/package.json b/apps/shared/package.json index 6a46d00af7..4696d8003e 100644 --- a/apps/shared/package.json +++ b/apps/shared/package.json @@ -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": { diff --git a/package.json b/package.json index d6eba3da00..124a144429 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests-js/.npmrc b/tests-js/.npmrc new file mode 100644 index 0000000000..9cc8843d4c --- /dev/null +++ b/tests-js/.npmrc @@ -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 diff --git a/tests-js/npm-refused-in-workspaces.test.mjs b/tests-js/npm-refused-in-workspaces.test.mjs new file mode 100644 index 0000000000..c4877630a9 --- /dev/null +++ b/tests-js/npm-refused-in-workspaces.test.mjs @@ -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) diff --git a/tests-js/package.json b/tests-js/package.json index 6f34027d44..57fd5d9466 100644 --- a/tests-js/package.json +++ b/tests-js/package.json @@ -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", diff --git a/ui-tui/.npmrc b/ui-tui/.npmrc new file mode 100644 index 0000000000..9cc8843d4c --- /dev/null +++ b/ui-tui/.npmrc @@ -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 diff --git a/ui-tui/package.json b/ui-tui/package.json index 44c8d12f63..3c2369557a 100644 --- a/ui-tui/package.json +++ b/ui-tui/package.json @@ -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", diff --git a/ui-tui/packages/hermes-ink/.npmrc b/ui-tui/packages/hermes-ink/.npmrc new file mode 100644 index 0000000000..9cc8843d4c --- /dev/null +++ b/ui-tui/packages/hermes-ink/.npmrc @@ -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 diff --git a/ui-tui/packages/hermes-ink/package.json b/ui-tui/packages/hermes-ink/package.json index 318cd42bbf..33acd77e64 100644 --- a/ui-tui/packages/hermes-ink/package.json +++ b/ui-tui/packages/hermes-ink/package.json @@ -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", diff --git a/web/.npmrc b/web/.npmrc new file mode 100644 index 0000000000..9cc8843d4c --- /dev/null +++ b/web/.npmrc @@ -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 diff --git a/web/package.json b/web/package.json index 0e6538f727..835dfeaaa4 100644 --- a/web/package.json +++ b/web/package.json @@ -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": { diff --git a/website/docs/developer-guide/contributing.md b/website/docs/developer-guide/contributing.md index 1262d66112..43cfe6c55f 100644 --- a/website/docs/developer-guide/contributing.md +++ b/website/docs/developer-guide/contributing.md @@ -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. diff --git a/website/docs/reference/package-management.md b/website/docs/reference/package-management.md index 28badcf862..bb50f51fb1 100644 --- a/website/docs/reference/package-management.md +++ b/website/docs/reference/package-management.md @@ -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 diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/contributing.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/contributing.md index d72dd17c63..2f9e62ae13 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/contributing.md +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/developer-guide/contributing.md @@ -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 文件。