@ruso-0/nreki 8.3.0 → 8.6.2

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.
package/README.md CHANGED
@@ -47,11 +47,27 @@ npx @ruso-0/nreki init
47
47
 
48
48
  ---
49
49
 
50
+ ## ⚡ The "Zero-Config" Promise (80% of the value instantly)
51
+
52
+ NREKI is designed to be plug-and-play. You don't need a PhD in graph theory to use it.
53
+
54
+ Out of the box, NREKI automatically provides:
55
+
56
+ 1. **Tree-sitter AST Shield (Layer 1):** Instantly catches missing commas, unclosed brackets, and hallucinated syntax in TS, JS, Python, and Go *before* they hit your disk. Zero native dependencies.
57
+ 2. **TypeScript VFS (Layer 2):** Full cross-file type checking and CodeFix Auto-Healing in RAM using your existing `tsconfig.json`.
58
+ 3. **TFC-Ultra Compression:** Bounding parafoveal overhead to O(1), saving 85-98% of tokens on file reads while keeping the LLM laser-focused on the exact method it needs to edit.
59
+
60
+ **What about Go and Python LSPs? (Graceful Degradation)**
61
+
62
+ If you happen to have `gopls` or `pyright` in your PATH, NREKI will silently detect them and upgrade Go/Python to Layer 2 (Cross-file semantics & LSP Auto-Healing). **If you don't have them, NREKI gracefully degrades to Layer 1.** Your agent never breaks. You get the core value with zero installation friction.
63
+
64
+ ---
65
+
50
66
  ## What It Actually Does
51
67
 
52
68
  | Without NREKI | With NREKI | Result |
53
69
  |---------------|-----------|--------|
54
- | `cat file.ts` dumps entire file | `nreki_code action:"read"` compresses to signatures | 60-80% fewer tokens |
70
+ | `cat huge_file.ts` (burns 20k tokens) | `compress focus:"<method>"` (TFC-Ultra) | **82% to 98.2% Token Savings** |
55
71
  | Agent writes broken code to disk | Edit validated in RAM before write | Zero broken files on disk |
56
72
  | Error -> read output -> guess fix -> retry -> repeat | Auto-Healing fixes structural errors in RAM | Zero doom loop tokens |
57
73
  | Agent manages 16+ tool calls | 3 tools, 20 actions | 85% less tool overhead |
@@ -62,6 +78,13 @@ npx @ruso-0/nreki init
62
78
 
63
79
  ---
64
80
 
81
+ ## 🔬 Pro Features: Architecture Intelligence
82
+ *(For Staff Engineers, Tech Leads, and complex refactors)*
83
+
84
+ Under the hood, NREKI doesn't just read text; it builds a mathematical graph of your repository. It computes the combinatorial Laplacian of the file-level dependency graph to unlock advanced architectural insights that act as a passive radar for your team. **You don't need to understand any of this to get the Zero-Config benefits above** — these features kick in when you opt-in to them for complex refactors.
85
+
86
+ ---
87
+
65
88
  ## What's New in v8 (Antigravity)
66
89
 
67
90
  ### Spectral Clustering
@@ -147,6 +170,68 @@ True topological circuit rank via Union-Find on the type constraint graph. `beta
147
170
 
148
171
  ---
149
172
 
173
+ ## What's New in v8.6 (TFC-Ultra)
174
+
175
+ **Topological Foveal Compression (TFC-Ultra)** — Hyper-causal context sculpting for frontier LLMs (Opus 4.6 / Gemini 3.1 Pro). Point TFC-Ultra at a specific method or function inside a monolith, and it extracts the target symbol at 100% resolution plus its causal dependencies (upstream callers, downstream deps, resolved external imports, blast radius), while annihilating orthogonal "dark matter" code.
176
+
177
+ ```bash
178
+ nreki_code action:"compress" path:"src/huge-file.ts" focus:"criticalMethod"
179
+ ```
180
+
181
+ ### The Physics of TFC-Ultra (Empirically Benchmarked)
182
+
183
+ We benchmarked TFC against NREKI's own `src/` directory (15 focus probes on operational methods, plus 15 boundary probes on minimal getters). No marketing fluff. Just math.
184
+
185
+ **The Asymptotic Boundary (Theoretical Ceiling):**
186
+
187
+ - **Max Compression Observed: 98.2% (55x)**
188
+ - **Context:** Focus on a 3-line getter (`isBooted`) inside an 82 KB, 1,640-line monolith (`nreki-kernel.ts`). 1,605 orthogonal lines annihilated.
189
+ - **The Amdahl Law of Context:** The compression ratio scales inversely with the focus-to-file size ratio. The larger the monolith and the smaller the target, the more devastating the compression.
190
+
191
+ **The Operational Case (Medium-to-large methods):**
192
+
193
+ - **Avg Compression: 82.2%** (~5.6x smaller)
194
+ - **p95 Compression: 89.9%** (~10x smaller)
195
+ - **Fovea Fidelity: 100%** — Target symbol preserved verbatim for zero-loss reasoning.
196
+ - **LRU Cache Speedup: 33x faster on average** (1,819ms → 11.7ms) via True LRU AST Cache. **142x in extreme cases.**
197
+
198
+ ### Zero-Regression Density Shield
199
+
200
+ What happens if the LLM gets lazy and aims TFC at a 1,500-line "God Class"? The parafoveal overhead (callers, deps, metadata) would make the output larger than reading the file raw.
201
+
202
+ TFC-Ultra prevents this. If it cannot mathematically guarantee at least **15% real compression** (ratio < 0.85), it aborts silently in RAM and gracefully degrades to the Legacy Aggressive compressor. **The user never receives an output worse than the baseline.**
203
+
204
+ ### Prompt Cache Inversion
205
+
206
+ TFC-Ultra forces a topological inversion of the output:
207
+
208
+ ```
209
+ [Static Preamble] -> [Dark Matter Tombstones] -> [External Contracts] -> [Upstream/Downstream] -> [VOLATILE FOVEA]
210
+ ```
211
+
212
+ By placing the volatile target code at the absolute bottom of the payload, the top 90% of the prompt remains static across subsequent iterative edits. This guarantees **Anthropic Prefix Cache hits**, saving users up to **90% in API costs**.
213
+
214
+ ### TFC-Pro Enforcer (Cognitive Bouncer)
215
+
216
+ When a file exceeds 3,000 tokens and the agent tries to read it raw, NREKI's `PreToolUseHook` intercepts the call, blocking context-window suicide. It forces the agent to use outline + focus-driven compression instead.
217
+
218
+ **This is not marketing. This is physics.** See [BENCH-TFC.md](BENCH-TFC.md) for the raw dogfooding benchmark with per-file breakdowns.
219
+
220
+ ---
221
+
222
+ ## What's New in v8.5 (Engine Decomposition)
223
+
224
+ The 878-line `engine.ts` God Object was decomposed into a clean facade pattern:
225
+
226
+ - `engine-types.ts` — shared type definitions (SearchResult, EngineConfig, SessionReport, IndexStats)
227
+ - `engine/indexer.ts` — `IndexPipeline` class (write side: AST parsing, embedding, batch storage)
228
+ - `engine/searcher.ts` — `SearchEngine` class (read side: T-RAG Tectonic Relevance Scoring)
229
+ - `engine.ts` — thin orchestrator facade (~520 lines)
230
+
231
+ 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).
232
+
233
+ ---
234
+
150
235
  ## What's New in v8.3
151
236
 
152
237
  ### Kernel Decomposition (v8.1)
@@ -367,6 +452,8 @@ Re-injects 4-layer session state every ~15 tool calls to survive context compact
367
452
  |--------|-------|
368
453
  | Tests | 713 (44 suites) |
369
454
  | Architecture Health Index | 9.7/10 (self-scored) |
455
+ | **Max TFC-Ultra Compression** | **98.2% (55x)** |
456
+ | **TFC LRU Cache Speedup** | **34x avg (11.7ms latency)** |
370
457
  | Languages | 4 (TypeScript, JavaScript, Go, Python) |
371
458
  | Failure modes sealed | 32 (P1-P32) |
372
459
  | Audit findings resolved | 30/30 + 22 additional |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruso-0/nreki",
3
- "version": "8.3.0",
3
+ "version": "8.6.2",
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",
@@ -1,21 +1,48 @@
1
- # NREKI Active
2
-
3
- This workspace has the NREKI MCP plugin installed. It extends your capabilities with AST-aware tools that protect your context window and prevent syntax errors before they reach disk.
4
-
5
- ## Optimal Workflow
6
-
7
- 1. **Run tests & commands freely.** Use Bash for npm test, builds, git - NREKI doesn't interfere with your terminal.
8
- 2. **Navigate with AST precision.** Prefer `nreki_navigate` over grep/glob. It returns exact structural matches (functions, classes, references) without flooding your context with noise.
9
- 3. **Read files efficiently.** ALWAYS prefer `nreki_code action:"read"` over native Read. Native Read dumps the entire file into your context - a 2,000-line file burns ~5,000 tokens in one call. `nreki_code read` auto-compresses to ~1,200 tokens while keeping all structural context. This is the single biggest token saver available to you.
10
- 4. **Debugging? Read uncompressed.** If you need to understand a function's internal logic (not just its signature), use `nreki_code action:"read" compress:false`. Compression hides function bodies to save tokens - great for navigation, but not for debugging.
11
- 5. **Edit surgically.** Prefer `nreki_code action:"edit"` for modifying existing functions/classes. It validates the AST before writing to disk - if your code has a syntax error, the file stays untouched and you get the exact line/column to fix.
12
- 6. **Multi-file refactors? Use batch_edit.** `nreki_code action:"batch_edit" edits:[...]` edits multiple files atomically. If ANY file has a syntax error, NOTHING is written to disk. All-or-nothing safety.
13
- 7. **Renaming a symbol? Use prepare_refactor first.** `nreki_navigate action:"prepare_refactor" symbol:"OldName"` analyzes every occurrence and classifies it as "high confidence" (safe to rename) or "review" (might be a string, comment, or object key). Then use batch_edit to apply the renames.
14
- 8. **Watch for blast radius warnings.** When you change a function's signature, NREKI automatically warns you which files import it. Fix those files before running tests.
15
- 9. **The repo map shows architecture tiers.** `nreki_navigate action:"map"` now classifies files as CORE (high import count - modify with caution), BUSINESS LOGIC (medium), or LEAF (safe to experiment).
16
- 10. **Create new files normally.** Use native Write for brand new files that don't exist yet.
17
- 11. **Pin rules that matter.** Use `nreki_guard action:"pin"` to persist instructions across messages (e.g., "always use fetch, not axios").
18
- 12. **Anchor your plan.** If you're working on a complex task with strict schemas or architectural constraints, use `nreki_guard action:"set_plan" text:"PLAN.md"` at the start. NREKI will silently re-inject your plan every ~15 tool calls to survive context compaction. Use `nreki_guard action:"memorize" text:"your progress notes"` to leave notes for yourself.
19
- 13. **If the circuit breaker triggers, follow its instructions.** It detected a doom loop and is protecting your session from burning tokens on repeated failures.
20
-
21
- NREKI handles the context heavy-lifting so you can focus on writing correct code on the first try.
1
+ # 🛡️ NREKI SYSTEM ACTIVE: AI DIRECTIVES
2
+
3
+ This workspace is protected by NREKI, an AST-aware context firewall.
4
+
5
+ ## 0. 🚨 EMERGENCY FALLBACK (MCP FAILURE)
6
+ If the `nreki_*` tools fail to load, timeout, or return connection errors:
7
+ 1. **DO NOT PANIC or freeze.**
8
+ 2. **TEMPORARILY SUSPEND** the "NEVER use Native Read/Write" rules below.
9
+ 3. Fall back to your native `Read File`, `Write`, and `Replace` tools to complete the task.
10
+ 4. Inform the user: *"NREKI connection lost. Proceeding with native tools (AST safety disabled)."*
11
+
12
+ *(Assuming NREKI is online, strictly obey the following laws):*
13
+
14
+ ## 1. 📖 READING & DISCOVERY (The TFC-Ultra Protocol)
15
+ * **NEVER use Native `Read File` for existing files** (unless in Emergency Fallback). It dumps raw text, triggers "Attention Sinks", and burns context.
16
+ * **MANDATORY TFC-ULTRA FOR EDITS:** To understand or edit a specific logic block in a large file (>3000 tokens):
17
+ 1. Run `nreki_navigate action:"outline" path:"<file>"` to map the structure.
18
+ 2. Identify the exact **METHOD or FUNCTION** you need (DO NOT target entire classes).
19
+ 3. Run `nreki_code action:"compress" path:"<file>" focus:"<method_name>"`.
20
+ *NREKI will isolate your target at 100% resolution, resolve causal dependencies, and annihilate up to 98% of orthogonal noise.*
21
+ * **GENERAL EXPLORATION:** If skimming a smaller file, use `nreki_code action:"read"`.
22
+ * **NAVIGATION:** Do not use grep/glob. Use `nreki_navigate` (`search`, `definition`, `references`, `outline`, `map`) for zero-noise discovery.
23
+
24
+ ## 2. ✍️ SURGICAL EDITING & REFACTORING
25
+ * **NEVER use Native `Write` or `Replace` to modify existing files.** It bypasses the RAM safety shield.
26
+ * **SINGLE EDITS:** ALWAYS use `nreki_code action:"edit" symbol:"<Name>"`.
27
+ * **MULTI-FILE EDITS:** ALWAYS use `nreki_code action:"batch_edit"`. It is a strict ACID transaction.
28
+ * **NEW FILES:** Use Native `Write` ONLY for creating brand-new files.
29
+ * **RENAMING:** Run `nreki_navigate action:"prepare_refactor"` before renaming.
30
+
31
+ ## 3. 🏗️ BLAST RADIUS & ARCHITECTURE
32
+ * **RESPECT THE BLAST RADIUS:** When changing a signature, NREKI warns you of downstream dependent files. You **MUST** fix them in the SAME `batch_edit` transaction.
33
+ * **AUTO-HEALER:** If NREKI injects an import or fixes syntax, it will notify you: `[Auto-Heal applied]`. **DO NOT PANIC.** Do not manually revert it.
34
+
35
+ ## 4. 🧠 CONTEXT SURVIVAL
36
+ * **ANCHOR PLANS:** Start complex tasks with `nreki_guard action:"set_plan" text:"PLAN.md"`. NREKI silently re-injects this plan every ~15,000 tokens so you never forget it.
37
+ * **BREADCRUMBS:** Use `nreki_guard action:"memorize" text:"<notes>"` to save your progress state.
38
+
39
+ ## 5. 🚨 TERMINAL & SYSTEM ALERTS
40
+ * Run `npm test`, builds, and `git` normally via Bash. If logs are massive, use `nreki_code action:"filter_output"`.
41
+ * **CIRCUIT BREAKER:** If NREKI triggers the Circuit Breaker, you are in a token-burning doom loop. **STOP IMMEDIATELY.** Read the instructions.
42
+
43
+ ## 6. 🔍 ARCHITECTURAL HEALTH (Passive Radar)
44
+ * **THE RULE:** NREKI monitors the codebase for "God Files" (Bus Factor) and "Spaghetti Code" (Coupling). If your refactor triggers a CRITICAL alert in an audit, treat it as a strong architectural hint to decouple, but **prioritize fixing syntax/logic first**.
45
+
46
+ ## 7. 🐍🐹 MULTI-LANGUAGE & LSP SIDECARS
47
+ * **NATIVE SHIELD:** NREKI natively shields TS/JS. For Go/Python, it attempts to spawn `gopls`/`pyright` for Layer 2 Semantic validation.
48
+ * **MISSING BINARY?** If an LSP is not installed, NREKI gracefully degrades to Layer 1 (Syntax-Only AST Validation). **DO NOT PANIC.** Do NOT ask the user to install them. Acknowledge the downgrade silently and proceed with syntax-level confidence.