Environment:3641397194 wq Gpt6 Astra npm
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Package_Management |
| Last Updated | 2026-10-26 14:00 GMT |
Overview
npm package manager environment for isolated, supply-chain-safe dependency preparation of the REA (Remote Execution Agent) upstream runtime.
Description
This environment defines the npm CLI requirements for the REA upstream launcher (`rea-launcher.cjs`). The launcher performs an isolated `npm ci` with `--omit=dev --omit=optional --ignore-scripts --no-audit --no-fund` to install locked dependencies into a sandboxed runtime directory. The npm CLI is located via `findNpmCli()`, which searches near the Node.js executable, resolves realpaths, and scans the first 256 PATH segments. The environment is fully isolated: user npmrc files are ignored, `NODE_OPTIONS`/`NODE_PATH`/`NPM_TOKEN` are stripped, and npm config is redirected to empty project-owned config files.
Usage
Use this environment for the prepareRea implementation, which runs `npm ci` to install REA runtime dependencies (`rea-agents@6.7.0` with core dependencies `zod` and `@modelcontextprotocol/server`). This is the mandatory prerequisite for the Upstream_REA_Prepare workflow.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Windows / macOS / Linux | npm CLI resolved per platform |
| Node.js | \| ^24.11.0 \|\| >=26.0.0 | Validated by `supportedNode()` |
| npm | Bundled with Node.js | `npm-cli.js` must be locatable via `findNpmCli()` |
| Disk | 200 MB for node_modules | REA runtime dependencies |
| Network | Outbound HTTPS to npm registry | For `npm ci` package download |
Dependencies
System Packages
- Node.js (with bundled npm)
- `npm-cli.js` — located via `findNpmCli()` searching near `process.execPath`, `npm_execpath` env, and PATH
npm CLI Arguments
npm ci --omit=dev --omit=optional --ignore-scripts --no-audit --no-fund
REA Core Dependencies
- `rea-agents` = 6.7.0 (the package being prepared)
- `zod` (core dependency, verified via import)
- `@modelcontextprotocol/server` (core dependency, verified via import)
Credentials
- `NPM_TOKEN` / `NODE_AUTH_TOKEN` — Stripped from the child process environment for security
- `NODE_OPTIONS` / `NODE_PATH` / `NODE_V8_COVERAGE` — Stripped to prevent injection
No npm credentials are passed to the isolated prepare environment. The npm registry is accessed anonymously.
Quick Install
# Verify Node.js and npm are available
node --version # must match ^22.19.0 || ^24.11.0 || >=26.0.0
npm --version # npm is bundled with Node.js
# The REA launcher finds npm-cli.js automatically:
# node rea-launcher.cjs --prepare
Code Evidence
npm CLI location from `rea-launcher.cjs:197-222`:
function findNpmCli({ execPath = process.execPath, env = process.env, platform = process.platform, npmCli } = {}) {
const candidates = [];
function near(file) {
if (!file) return;
const directory = path.dirname(file);
candidates.push(path.join(directory, 'node_modules/npm/bin/npm-cli.js'),
path.join(directory, '../lib/node_modules/npm/bin/npm-cli.js'));
try { const real = fs.realpathSync(file); if (path.basename(real).toLowerCase() === 'npm-cli.js') candidates.push(real); } catch {}
}
// ... searches candidates, returns first valid npm-cli.js
throw new ReaError('REA_NPM_MISSING', '找不到 npm-cli.js;请使用包含 npm 的 Node.js 安装,然后重试。');
}
Isolated npm arguments from `rea-launcher.cjs:17`:
const NPM_ARGS = ['ci', '--omit=dev', '--omit=optional', '--ignore-scripts', '--no-audit', '--no-fund'];
Environment stripping from `rea-launcher.cjs:169-194`:
function prepareEnvironment(base, source = process.env, { forMcp = false } = {}) {
const env = {};
for (const [key, value] of Object.entries(source)) {
if (/^(NODE_OPTIONS|NODE_PATH|NODE_V8_COVERAGE|NPM_CONFIG_.*|NPM_TOKEN|NODE_AUTH_TOKEN)$/i.test(key)) continue;
// ... only allow specific safe environment variables
}
// ... redirects HOME, APPDATA, cache to isolated directories
env.npm_config_cache = cache;
env.npm_config_ignore_scripts = 'true';
env.npm_config_audit = 'false';
env.npm_config_fund = 'false';
}
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `REA_NPM_MISSING` / `找不到 npm-cli.js` | npm CLI not found near Node.js | Use a Node.js installation that includes npm |
| `REA_NPM_FAILED` | `npm ci` exited non-zero | Check network; retry; existing skill files preserved |
| `REA_NODE_UNSUPPORTED` | Node.js version outside range | \| ^24.11.0 \|\| >=26.0.0 |
| `REA_PREPARE_TIMEOUT` | npm ci exceeded timeout (default 8 min) | Retry; skill files preserved |
| `REA_PATH_ESCAPE` / `REA 锁文件包含本地路径或链接依赖` | package-lock.json contains local/link deps | Re-vendor with clean locked dependencies |
Compatibility Notes
- Windows: Searches for `npm.cmd`, `npm.exe`, `npm` in PATH; uses `;` as PATH separator.
- macOS/Linux: Searches for `npm` in PATH; uses `:` as PATH separator.
- PATH scanning limit: Only the first 256 PATH segments are scanned to bound search time.
- npm shell avoidance: npm is always invoked via `npm-cli.js` with `shell: false` — never through `npm.cmd` via an interpolated shell.
- Lockfile requirement: Requires npm package-lock.json v2 or v3 with no local path or link dependencies.