Files
ruflo/scripts
ruv 9c075a3c36 feat(neural-trader): #2068 ADR-126 Phase 3 — portfolio CG via sublinear/solve (40-60x)
Wires the Conjugate-Gradient mean-variance solve `Σ · x = μ` that ADR-123
Wedge 8 promises a 40-60× speedup over the legacy Neumann series. Ships:

- `src/sublinear-adapter.ts` — `SublinearAdapter` class per the ADR-123
  §262-289 contract: `solveCG(matrix, vector, opts)`, `isMcpAvailable()`,
  `SolveResult` shape, SPD/symmetric sanity checks, graceful degrade with
  `degraded: true` for malformed inputs.
- `src/sublinear-adapter.mjs` — runtime mirror so the smoke + bench
  import the adapter directly (the plugin has no build step). Both files
  ship a self-contained ~50-LOC CG kernel + Jacobi/Neumann baseline; the
  same call site picks up the full native-WASM speedup automatically
  once `mcp__ruflo-sublinear__solve` is registered.
- `skills/trader-portfolio-cg/SKILL.md` — declares `mcp__ruflo-sublinear__solve`
  in allowed-tools, writes weights with provenance metadata
  (`method: 'cg-sublinear' | 'cg-local' | 'neumann-fallback'`) to the
  canonical `trading-risk` namespace (ADR-126 Phase 1 alignment),
  documents the `RUFLO_NEURAL_TRADER_DISABLE_CG` disable flag, defines
  the legacy `npx neural-trader --portfolio optimize` fallback.
- `benchmarks/portfolio-cg.bench.mjs` — CG vs Neumann on synthetic SPD
  covariance at n ∈ {16, 64, 256}. Fixed-seed parity check
  (`||cg − neumann||_∞ < 1e-4`) and per-size latency table.
- `benchmarks/results/cg-baseline-20260520T022220Z.md` — captured
  baseline numbers. CG at n=256 is sub-ms (0.31 ms). The JS-vs-JS gap is
  ~1.5-1.9× because both kernels JIT to similar efficiency; the upstream
  40-60× figure is for native-CG vs native-Neumann in
  `sublinear-time-solver@1.7.0`, which the skill picks up automatically
  through the MCP dispatch.
- `scripts/smoke-neural-trader-portfolio-cg.mjs` — three-layer regression
  smoke: static adapter contract (class shape, method signatures, MCP
  tool name), static skill contract (allowed-tools, namespace, disable
  flag, fallback path), runtime correctness (textbook 2×2 SPD case
  A=[[4,1],[1,3]], b=[1,2] → x=[1/11, 7/11] within 1e-6, plus degraded
  paths for non-square / non-symmetric input).
- `.github/workflows/v3-ci.yml` — `neural-trader-portfolio-cg-smoke` job
  on the same shape as the kg-extract guard; triggers on adapter, skill,
  or smoke changes.
- `README.md` + plugin-smoke skill-count bumped from 7 → 8.

Acceptance:
- `bash plugins/ruflo-neural-trader/scripts/smoke.sh` → 11/11 pass.
- `node scripts/smoke-neural-trader-portfolio-cg.mjs` → all 17 checks pass.
- Bench parity: `||cg − neumann||_∞ < 1e-4` at every n ∈ {16, 64, 256}.

Refs: #2068, ADR-126 Phase 3, ADR-123 §162 Row 8 (Wedge 8).

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 22:22:56 -04:00
..
2026-01-04 19:30:59 +00:00