@ruso-0/nreki 8.0.2 → 8.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +117 -3
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <p align="center">
4
4
  <img src="https://img.shields.io/npm/v/@ruso-0/nreki?style=for-the-badge&color=blue" alt="npm version">
5
- <img src="https://img.shields.io/badge/Tests-712-brightgreen?style=for-the-badge" alt="712 Tests">
5
+ <img src="https://img.shields.io/badge/Tests-713-brightgreen?style=for-the-badge" alt="713 Tests">
6
6
  <img src="https://img.shields.io/badge/AHI-9.7%2F10-brightgreen?style=for-the-badge" alt="AHI 9.7/10">
7
7
  <img src="https://img.shields.io/badge/Languages-TS%20%7C%20JS%20%7C%20Go%20%7C%20Python-blue?style=for-the-badge" alt="Multi-language">
8
8
  <img src="https://img.shields.io/badge/Cloud-Zero-orange?style=for-the-badge" alt="Zero Cloud">
@@ -24,7 +24,7 @@ AI proposes edit -> NREKI intercepts in RAM -> Compiler/LSP validates
24
24
  | Some remain? ------> Full rollback. Disk untouched. Errors returned to agent.
25
25
  ```
26
26
 
27
- 3 tools. 712 tests. 4 languages. Works with any MCP-compatible agent. Apache 2.0.
27
+ 3 tools. 713 tests. 4 languages. Works with any MCP-compatible agent. Apache 2.0.
28
28
 
29
29
  ---
30
30
 
@@ -147,6 +147,120 @@ True topological circuit rank via Union-Find on the type constraint graph. `beta
147
147
 
148
148
  ---
149
149
 
150
+ ## What's New in v8.6 (TFC-Ultra)
151
+
152
+ **Topological Foveal Compression** — Hyper-causal context sculpting for frontier LLMs. Point TFC-Ultra at a specific method or function inside a file, and it extracts the target symbol at 100% resolution plus its causal dependencies (upstream callers, downstream deps, resolved imports, blast radius), while annihilating orthogonal "dark matter" code.
153
+
154
+ ```bash
155
+ nreki_code action:"compress" path:"src/huge-file.ts" focus:"criticalMethod"
156
+ ```
157
+
158
+ ### Empirical results (benchmarked against NREKI src/ — 5 files, 15 focus probes + 15 boundary probes)
159
+
160
+ **Operational case** (methods of medium-to-large size):
161
+
162
+ | Metric | Value |
163
+ |--------|-------|
164
+ | **Avg compression** | **82.2%** (~5.6x) |
165
+ | **p50 compression** | **84.8%** |
166
+ | **p95 compression** | **89.9%** (~10x) |
167
+ | **Advantage vs legacy tier-3** | **+9.8pp** (consistent) |
168
+ | **Fovea fidelity** | **100%** — target symbol preserved verbatim for zero-loss reasoning |
169
+ | **True LRU AST cache** | **34x avg speedup**, **137x in extreme cases** (1,819ms → 13.3ms on 82 KB file) |
170
+ | **Fallback rate (Density Shield)** | **13.3%** — when TFC can't beat 15% compression, falls through to legacy aggressive |
171
+
172
+ **Best case boundary** (theoretical ceiling — small focus inside large file):
173
+
174
+ | Metric | Value |
175
+ |--------|-------|
176
+ | **Max compression observed** | **98.2%** (**55x**) |
177
+ | **Context** | focus `isBooted` (3-line getter) inside `nreki-kernel.ts` (82 KB, 1,640 lines) |
178
+ | **Boundary probes** | 15 (top-3 smallest symbols per file), **0 fallbacks**, compression range: **30x–55x** |
179
+
180
+ ### The Amdahl law of focused compression
181
+
182
+ TFC compression ratio follows an asymptotic limit:
183
+
184
+ ```
185
+ Ratio ≈ 1 − (Preamble + Fovea + Markov_Mantle_O(1)) / TotalFileSize
186
+ ```
187
+
188
+ - When the Fovea is a small getter (3 lines) inside a 1,640-line file, the numerator is minuscule vs. the denominator. **Ratio approaches 100%. Empirical ceiling: 98.2% (55x).**
189
+ - When the Fovea is a large operational method (500 lines), the numerator grows. **Ratio drops to 70-80%.** Still preserves 100% of the causal information the agent needs.
190
+ - When the Fovea is a God Class (entire file), the numerator **exceeds** the denominator due to parafovea overhead. **The Density Shield detects this and falls through to legacy aggressive**, guaranteeing the output is never worse than baseline.
191
+
192
+ **This is not marketing. This is physics.** See [BENCH-TFC.md](BENCH-TFC.md) for the raw dogfooding benchmark with per-file breakdowns.
193
+
194
+ ### How it works
195
+
196
+ - **Fovea**: the target symbol is preserved byte-for-byte at 100% resolution
197
+ - **Upstream vectorial collapse** (O(1)): N local callers condensed to a single line of names
198
+ - **Downstream event horizon** (O(1)): top-10 local dependencies + `cleanSignature` to strip JSDoc waste
199
+ - **External parafovea**: BM25-resolved signatures of imported symbols used inside the fovea
200
+ - **Blast radius**: dependents from the project-wide import graph
201
+ - **Dark matter**: everything else in the file is omitted as a single annotation line
202
+ - **Density Shield 0.85**: if TFC can't achieve ≥15% real compression (e.g. when the agent aims at a God Class and pulls the entire file into the fovea), the compressor returns `null` and the system falls through to the legacy aggressive compressor — **mathematically guarantees you never perform worse than baseline**
203
+
204
+ ### TFC-Pro Enforcer (auto-guard on `read`)
205
+
206
+ When a file exceeds 3,000 tokens and the agent tries to read it raw, NREKI's hook intercepts the call and instructs the agent to use outline + focus-driven compression instead. This eliminates context-window suicide before it happens.
207
+
208
+ ---
209
+
210
+ ## What's New in v8.5 (Engine Decomposition)
211
+
212
+ The 878-line `engine.ts` God Object was decomposed into a clean facade pattern:
213
+
214
+ - `engine-types.ts` — shared type definitions (SearchResult, EngineConfig, SessionReport, IndexStats)
215
+ - `engine/indexer.ts` — `IndexPipeline` class (write side: AST parsing, embedding, batch storage)
216
+ - `engine/searcher.ts` — `SearchEngine` class (read side: T-RAG Tectonic Relevance Scoring)
217
+ - `engine.ts` — thin orchestrator facade (~520 lines)
218
+
219
+ Zero API changes. All 28 public methods on `NrekiEngine` preserved. `sql.js` intentionally kept (migration to `node:sqlite` postponed to v9.0 to avoid breaking users on Node 20 LTS or forcing the `--experimental-sqlite` flag).
220
+
221
+ ---
222
+
223
+ ## What's New in v8.3
224
+
225
+ ### Kernel Decomposition (v8.1)
226
+
227
+ The 2,080-line God Object `nreki-kernel.ts` was decomposed into 4 focused modules:
228
+
229
+ - `mutex.ts` — AsyncMutex FIFO with timeout protection
230
+ - `types.ts` — All interfaces + IoC contracts (`TsHealingContext`, `LspHealingContext`)
231
+ - `ttrd.ts` — Pure functions: `extractRawSignatures`, `detectSignatureRegression`, `isToxicType`
232
+ - `healer.ts` — Both healers rewritten with Inversion of Control — healers no longer touch VFS, vfsClock, or tsBackend directly. Testable in isolation.
233
+
234
+ ### Production Hardening (v8.2)
235
+
236
+ - **Token Drift Heartbeat** — Replaced call-count heuristic (15 calls) with token-physics (15,000 tokens default). ENV override: `NREKI_DRIFT_THRESHOLD`. Telemetry injected into header: `(Drift: X tokens | Limit: Y)`.
237
+ - **Search Engine Segregation** — `VectorIndex` and `KeywordIndex` extracted to `src/search/`. Pure JavaScript, zero SQLite coupling. Ready for `node:sqlite` migration in v9.0.
238
+ - **Handler Barrel Pattern** — 1,119-line `handlers/code.ts` split into `code/kernel-bridge.ts`, `code/read.ts`, `code/edit.ts`, `code/utils.ts`. Rate limiter stays in router (correct layer separation).
239
+ - **WASM Deps Frozen** — `sql.js` and `tree-sitter-wasms` pinned to exact versions. No silent breakage from upstream updates.
240
+
241
+ ### Rayleigh Residual Guard (v8.3)
242
+
243
+ Added a 4th defense layer to the spectral power iteration. Post-convergence, the solver computes `||Mv - μv||∞` and dies with `NaN` if the residual exceeds `1e-3`. This traps silent IEEE 754 drift that slips past the 3 existing guards (thermal, divergence, numerical sanity firewall).
244
+
245
+ ### interceptAtomicBatch Phase Extraction (v8.3)
246
+
247
+ The 520-line ACID orchestrator was flattened into 3 private methods within `NrekiKernel`:
248
+
249
+ - `phase1_injectVfs` — Path jail + VFS injection
250
+ - `phase2_validateSidecars` — Go/Python LSP validation
251
+ - `phase4_healingCascade` — Dual healer cascade (TS CodeFix API + LSP codeAction)
252
+
253
+ Catch path untouched. ACID rollback semantics intact. The orchestrator now reads like a document.
254
+
255
+ ### engine.ts Flattening (v8.3)
256
+
257
+ - **SessionTracker class** — Session state (`sessionSavings`) encapsulated. Saves one `Embedder.estimateTokens(content)` call per compression.
258
+ - **`indexFile` split** — 124-line method → 28-line orchestrator + `indexPlaintextFallback` + `indexAstChunks`.
259
+ - **`search` split** — 93-line method → 27-line orchestrator + `applyTectonicRelevanceScoring`.
260
+ - **DB Facade grouping** — Delegation wrappers visually grouped under explicit `Facade` section headers.
261
+
262
+ ---
263
+
150
264
  ## The Architecture
151
265
 
152
266
  NREKI has 3 validation layers with multi-language support:
@@ -324,7 +438,7 @@ Re-injects 4-layer session state every ~15 tool calls to survive context compact
324
438
 
325
439
  | Metric | Value |
326
440
  |--------|-------|
327
- | Tests | 712 (44 suites) |
441
+ | Tests | 713 (44 suites) |
328
442
  | Architecture Health Index | 9.7/10 (self-scored) |
329
443
  | Languages | 4 (TypeScript, JavaScript, Go, Python) |
330
444
  | Failure modes sealed | 32 (P1-P32) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruso-0/nreki",
3
- "version": "8.0.2",
3
+ "version": "8.6.1",
4
4
  "description": "MCP plugin that validates AI agent edits in RAM before they touch disk. Spectral clustering, architecture diffs, bridge detection, dead code oracle, and cross-file semantic checks for TypeScript, Go (gopls), and Python (pyright). Zero cloud dependencies.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -60,8 +60,8 @@
60
60
  "@modelcontextprotocol/sdk": "^1.12.1",
61
61
  "chokidar": "^4.0.3",
62
62
  "picomatch": "^4.0.3",
63
- "sql.js": "^1.12.0",
64
- "tree-sitter-wasms": "^0.1.13",
63
+ "sql.js": "1.14.1",
64
+ "tree-sitter-wasms": "0.1.13",
65
65
  "web-tree-sitter": "^0.24.7",
66
66
  "zod": "^3.24.2"
67
67
  },