Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(neural-trader): mitigate upstream fork-bomb on install + CI guard (#1974) (#1976)

rUv4bd194554dca
diff --git a/.github/workflows/v3-ci.yml b/.github/workflows/v3-ci.yml
index 4e1e3cc140..660f12cd14 100644
--- a/.github/workflows/v3-ci.yml
+++ b/.github/workflows/v3-ci.yml
@@ -553,6 +553,10 @@ jobs:
shell: bash
run: node scripts/audit-fix-invariants.mjs
+ - name: Run neural-trader install-safety audit (#1974)
+ shell: bash
+ run: node scripts/audit-neural-trader-safety.mjs
+
- name: Lint the ruflo-hook shims
shell: bash
run: |
diff --git a/plugins/ruflo-neural-trader/README.md b/plugins/ruflo-neural-trader/README.md
index 6700982614..c867a814aa 100644
--- a/plugins/ruflo-neural-trader/README.md
+++ b/plugins/ruflo-neural-trader/README.md
@@ -10,10 +10,35 @@ Heavy jobs β€” multi-year walk-forward backtests, large Monte-Carlo runs, parame
## Prerequisites
+> ⚠️ **Critical install advisory β€” #1974**
+>
+> `[email protected]` (and every earlier published version we audited) has a
+> dangerous `install` lifecycle script that **recursively invokes `npm install`
+> from inside the install hook**. On any non-`linux-x64` host (macOS Apple
+> Silicon, Windows, linux-arm64) the recursion is unbounded β€” one report saw
+> 3,049 stuck processes consuming ~120 GB of RAM in ~80 minutes before manual
+> intervention. The platform-binary subpackages it advertises in
+> `optionalDependencies` (`neural-trader-darwin-arm64`, etc.) are **not
+> published to npm**, which is what triggers the fallback path.
+>
+> Until upstream ships a fix, always install neural-trader with
+> `--ignore-scripts` to skip the malicious install hook. The `linux-x64`
+> binary is hardcoded inline in the tarball, so on `linux-x64` the package
+> still works after `--ignore-scripts`. On other platforms `--ignore-scripts`
+> at least won't fork-bomb your machine; whether the runtime works depends on
+> upstream publishing the platform binary.
+
```bash
-npm install neural-trader
+# SAFE β€” skips the upstream install script that fork-bombs on non-linux-x64
+npm install --ignore-scripts neural-trader
+
+# DO NOT run `npm install neural-trader` (no flags) on macOS / Windows /
+# linux-arm64 until #1974 is resolved upstream.
```
+Set the env var `npm_config_ignore_scripts=1` in your shell rc to make this
+the default for all subsequent `npx neural-trader` calls.
+
## Installation
```bash
diff --git a/plugins/ruflo-neural-trader/agents/trading-strategist.md b/plugins/ruflo-neural-trader/agents/trading-strategist.md
index be8d70220e..998dfbded8 100644
--- a/plugins/ruflo-neural-trader/agents/trading-strategist.md
+++ b/plugins/ruflo-neural-trader/agents/trading-strategist.md
@@ -10,8 +10,9 @@ You are a trading strategist agent that orchestrates the `neural-trader` npm pac
All trading operations go through the `neural-trader` CLI. Install once, then invoke via npx:
```bash
-# Ensure installed
-npm ls neural-trader 2>/dev/null || npm install neural-trader
+# Ensure installed. --ignore-scripts skips the upstream `install` hook that
+# fork-bombs on non-linux-x64 hosts β€” see #1974 + the README's prereq.
+npm ls neural-trader 2>/dev/null || npm install --ignore-scripts neural-trader
# Core commands
npx neural-trader --strategy <type> --symbol <TICKER> [options]
diff --git a/plugins/ruflo-neural-trader/skills/trader-backtest/SKILL.md b/plugins/ruflo-neural-trader/skills/trader-backtest/SKILL.md
index 212df65039..38e3ddb4f2 100644
--- a/plugins/ruflo-neural-trader/skills/trader-backtest/SKILL.md
+++ b/plugins/ruflo-neural-trader/skills/trader-backtest/SKILL.md
@@ -8,7 +8,7 @@ Run a historical backtest using the `neural-trader` Rust/NAPI engine.
Steps:
1. Ensure neural-trader is available:
- `npm ls neural-trader 2>/dev/null || npm install neural-trader`
+ `npm ls neural-trader 2>/dev/null || npm install --ignore-scripts neural-trader`
2. Check for saved strategy config:
`mcp__claude-flow__memory_retrieve({ key: "strategy-STRATEGY_NAME", namespace: "trading-strategies" })`
If not found, list available: `mcp__claude-flow__memory_search({ query: "strategy", namespace: "trading-strategies", limit: 10 })`
diff --git a/plugins/ruflo-neural-trader/skills/trader-cloud-backtest/SKILL.md b/plugins/ruflo-neural-trader/skills/trader-cloud-backtest/SKILL.md
index b517f63b16..1c60c3fea4 100644
--- a/plugins/ruflo-neural-trader/skills/trader-cloud-backtest/SKILL.md
+++ b/plugins/ruflo-neural-trader/skills/trader-cloud-backtest/SKILL.md
@@ -30,7 +30,7 @@ Prereq: `ANTHROPIC_API_KEY` (or `CLAUDE_API_KEY`) + Managed Agents beta access.
system: "You operate the `neural-trader` CLI in this container. Run exactly the commands asked, report the metrics, write requested artifacts, then stop.",
networking: "unrestricted", // or "restricted" pinned to your data host
packages: { npm: ["neural-trader"] }, // add apt:["build-essential"] ONLY if there's no prebuilt NAPI binary for the arch (neural-trader ships prebuilds β†’ usually omit)
- initScript: "npm install -g neural-trader >/dev/null 2>&1 || npx -y neural-trader --version >/dev/null 2>&1 || true"
+ initScript: "npm install -g --ignore-scripts neural-trader >/dev/null 2>&1 || npx -y neural-trader --version >/dev/null 2>&1 || true"
})
β†’ { sessionId, agentId, environmentId }
```
@@ -74,7 +74,7 @@ Prereq: `ANTHROPIC_API_KEY` (or `CLAUDE_API_KEY`) + Managed Agents beta access.
## Quick example
```
-managed_agent_create { "name":"nt-cloud", "model":"claude-haiku-4-5-20251001", "packages":{"npm":["neural-trader"]}, "initScript":"npm install -g neural-trader >/dev/null 2>&1 || true" }
+managed_agent_create { "name":"nt-cloud", "model":"claude-haiku-4-5-20251001", "packages":{"npm":["neural-trader"]}, "initScript":"npm install -g --ignore-scripts neural-trader >/dev/null 2>&1 || true" }
β†’ { sessionId:"sesn_…", environmentId:"env_…" }
managed_agent_prompt { "sessionId":"sesn_…", "message":"Run `npx neural-trader --backtest --strategy multi-indicator --symbol SPY --period 2020-2024 --walk-forward --mc-paths 1000`. Report Sharpe/Sortino/max-DD/win-rate/CVaR; write /tmp/equity.csv. Then stop.", "maxWaitMs":600000 }
β†’ { finished:true, status:"idle", assistantText:"<metrics>", toolUses:[{bash:"npx neural-trader --backtest …"}] }
diff --git a/plugins/ruflo-neural-trader/skills/trader-portfolio/SKILL.md b/plugins/ruflo-neural-trader/skills/trader-portfolio/SKILL.md
index e6fbda616b..58a75b7fbe 100644
--- a/plugins/ruflo-neural-trader/skills/trader-portfolio/SKILL.md
+++ b/plugins/ruflo-neural-trader/skills/trader-portfolio/SKILL.md
@@ -8,7 +8,7 @@ Optimize portfolio allocation using neural-trader's portfolio engine.
Steps:
1. Ensure neural-trader is available:
- `npm ls neural-trader 2>/dev/null || npm install neural-trader`
+ `npm ls neural-trader 2>/dev/null || npm install --ignore-scripts neural-trader`
2. Load current portfolio:
`mcp__claude-flow__memory_search({ query: "current portfolio holdings", namespace: "trading-portfolio" })`
3. Run portfolio optimization:
diff --git a/plugins/ruflo-neural-trader/skills/trader-regime/SKILL.md b/plugins/ruflo-neural-trader/skills/trader-regime/SKILL.md
index f8904bb1d3..e59ed7e377 100644
--- a/plugins/ruflo-neural-trader/skills/trader-regime/SKILL.md
+++ b/plugins/ruflo-neural-trader/skills/trader-regime/SKILL.md
@@ -8,7 +8,7 @@ Detect the current market regime using neural-trader's regime detection engine.
Steps:
1. Ensure neural-trader is available:
- `npm ls neural-trader 2>/dev/null || npm install neural-trader`
+ `npm ls neural-trader 2>/dev/null || npm install --ignore-scripts neural-trader`
2. Run regime detection:
```bash
npx neural-trader --regime-detect --symbol TICKER
diff --git a/plugins/ruflo-neural-trader/skills/trader-risk/SKILL.md b/plugins/ruflo-neural-trader/skills/trader-risk/SKILL.md
index 6e0302203f..d2a407caf1 100644
--- a/plugins/ruflo-neural-trader/skills/trader-risk/SKILL.md
+++ b/plugins/ruflo-neural-trader/skills/trader-risk/SKILL.md
@@ -8,7 +8,7 @@ Assess portfolio and position risk using neural-trader's risk engine.
Steps:
1. Ensure neural-trader is available:
- `npm ls neural-trader 2>/dev/null || npm install neural-trader`
+ `npm ls neural-trader 2>/dev/null || npm install --ignore-scripts neural-trader`
2. Run risk assessment:
```bash
# Single position
diff --git a/plugins/ruflo-neural-trader/skills/trader-signal/SKILL.md b/plugins/ruflo-neural-trader/skills/trader-signal/SKILL.md
index cec08dcfe9..a59612e996 100644
--- a/plugins/ruflo-neural-trader/skills/trader-signal/SKILL.md
+++ b/plugins/ruflo-neural-trader/skills/trader-signal/SKILL.md
@@ -8,7 +8,7 @@ Generate trading signals using neural-trader's anomaly detection engine.
Steps:
1. Ensure neural-trader is available:
- `npm ls neural-trader 2>/dev/null || npm install neural-trader`
+ `npm ls neural-trader 2>/dev/null || npm install --ignore-scripts neural-trader`
2. Scan for signals:
```bash
npx neural-trader --signal scan --symbols <TICKERS>
diff --git a/plugins/ruflo-neural-trader/skills/trader-train/SKILL.md b/plugins/ruflo-neural-trader/skills/trader-train/SKILL.md
index 2705f06835..04b362ba34 100644
--- a/plugins/ruflo-neural-trader/skills/trader-train/SKILL.md
+++ b/plugins/ruflo-neural-trader/skills/trader-train/SKILL.md
@@ -8,7 +8,7 @@ Train neural prediction models using neural-trader's ML engine.
Steps:
1. Ensure neural-trader is available:
- `npm ls neural-trader 2>/dev/null || npm install neural-trader`
+ `npm ls neural-trader 2>/dev/null || npm install --ignore-scripts neural-trader`
2. Train the specified model:
```bash
npx neural-trader --model lstm --symbol TICKER --confidence 0.95
diff --git a/scripts/audit-neural-trader-safety.mjs b/scripts/audit-neural-trader-safety.mjs
new file mode 100755
index 0000000000..86760b1594
--- /dev/null
+++ b/scripts/audit-neural-trader-safety.mjs
@@ -0,0 +1,116 @@
+#!/usr/bin/env node
+/**
+ * Neural-trader install-safety audit (regression guard for #1974).
+ *
+ * The upstream `neural-trader` npm package (verified across versions
+ * 2.6.3, 2.7.0, 2.7.1) ships a malicious-by-accident `install` lifecycle
+ * script that recursively invokes `npm install` from inside the install
+ * hook. On any non-`linux-x64` host the recursion is unbounded β€” one
+ * report saw 3,049 stuck processes consuming ~120 GB of RAM in ~80
+ * minutes before manual intervention.
+ *
+ * Until the upstream package is patched, every recommended invocation of
+ * `npm install neural-trader` in THIS repo must pass `--ignore-scripts`
+ * (or use the env equivalent `npm_config_ignore_scripts=1`) to skip the
+ * fork-bombing install hook. This audit fails CI if a raw `npm install
+ * neural-trader` slips back in.
+ *
+ * Scope: scans tracked markdown / shell / json files in
+ * - plugins/ruflo-neural-trader/
+ * - any agent / skill that mentions neural-trader
+ * Exclusions: this script itself (the pattern is the literal we're
+ * guarding against) plus the README's "DO NOT" example block.
+ *
+ * Usage:
+ * node scripts/audit-neural-trader-safety.mjs # exit 1 on hit
+ * node scripts/audit-neural-trader-safety.mjs --json # machine-readable
+ */
+
+import { readFileSync, readdirSync, statSync } from 'node:fs';
+import { join, relative } from 'node:path';
+
+const REPO_ROOT = process.cwd();
+const JSON_OUT = process.argv.includes('--json');
+
+// Catches `npm install neural-trader` / `npm i neural-trader` (with or
+// without preceding `||`/`&&`/whitespace). Lines that include
+// `--ignore-scripts` anywhere on the same line are checked separately
+// below (regex-only lookahead doesn't catch `--ignore-scripts` placed
+// BEFORE the package name, which is the common form).
+const BAD = /(^|[\s|&;])npm\s+(?:install|i)\s+(?:[^|&\n]*\s)?neural-trader\b/;
+
+const ROOTS = [
+ 'plugins/ruflo-neural-trader',
+ // future: add other plugins / docs if they ever recommend neural-trader
+];
+const SKIP_DIRS = new Set(['node_modules', 'dist', '.git', 'target']);
+const EXT_OK = new Set(['.md', '.mdx', '.sh', '.bash', '.zsh', '.json']);
+
+// Lines that are deliberately bad (e.g. the README's "DO NOT" example).
+// Match by exact substring on the line so the marker is auditable.
+const ALLOWLIST_MARKERS = [
+ 'DO NOT run',
+ 'do not run',
+];
+
+function walk(dir, out = []) {
+ let entries;
+ try { entries = readdirSync(dir, { withFileTypes: true }); } catch { return out; }
+ for (const e of entries) {
+ if (SKIP_DIRS.has(e.name)) continue;
+ if (e.name.startsWith('.') && e.name !== '.claude-plugin') continue;
+ const p = join(dir, e.name);
+ let s;
+ try { s = statSync(p); } catch { continue; }
+ if (s.isDirectory()) walk(p, out);
+ else if (s.isFile()) {
+ const dot = e.name.lastIndexOf('.');
+ const ext = dot >= 0 ? e.name.slice(dot) : '';
+ if (EXT_OK.has(ext)) out.push(p);
+ }
+ }
+ return out;
+}
+
+const offenders = [];
+for (const root of ROOTS) {
+ for (const file of walk(join(REPO_ROOT, root))) {
+ let src;
+ try { src = readFileSync(file, 'utf8'); } catch { continue; }
+ const lines = src.split('\n');
+ for (let i = 0; i < lines.length; i++) {
+ const line = lines[i];
+ if (!BAD.test(line)) continue;
+ // Safe: line opts out of the install script via --ignore-scripts
+ // (placement before OR after the package name is fine).
+ if (line.includes('--ignore-scripts')) continue;
+ // Skip lines marked as deliberately-bad examples.
+ const context = lines.slice(Math.max(0, i - 2), i + 1).join('\n');
+ if (ALLOWLIST_MARKERS.some((m) => context.includes(m))) continue;
+ offenders.push({
+ file: relative(REPO_ROOT, file),
+ line: i + 1,
+ text: line.trim(),
+ });
+ }
+ }
+}
+
+if (JSON_OUT) {
+ process.stdout.write(JSON.stringify({ offenders }, null, 2) + '\n');
+ process.exit(offenders.length === 0 ? 0 : 1);
+}
+
+console.log('neural-trader install-safety audit β€” guard for #1974');
+console.log(` scanned ${ROOTS.join(', ')}`);
+if (offenders.length === 0) {
+ console.log(' βœ“ no raw `npm install neural-trader` (all use --ignore-scripts or are in allowlisted DO-NOT examples)');
+ process.exit(0);
+}
+console.error(`\n βœ— ${offenders.length} unsafe invocation(s) β€” #1974 regression:`);
+for (const o of offenders) {
+ console.error(` ${o.file}:${o.line}`);
+ console.error(` ${o.text}`);
+}
+console.error('\n Fix: add `--ignore-scripts` to the `npm install`, OR add a "DO NOT" marker on the line above if the example is deliberately showing the unsafe form.');
+process.exit(1);