react-state-basis 0.6.1 → 0.6.3

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
@@ -25,9 +25,11 @@ npm i react-state-basis
25
25
  ```
26
26
 
27
27
  ### 2. Setup (Vite)
28
- Add the plugin to your `vite.config.ts`. The Babel plugin auto-labels your hooksyou continue importing from `react` as normal.
28
+ Add the plugin to your `vite.config.ts`. The Babel plugin auto-labels your hooks - you continue importing from `react` as normal.
29
29
 
30
30
  ```ts
31
+ import { defineConfig } from 'vite';
32
+ import react from '@vitejs/plugin-react';
31
33
  import { basis } from 'react-state-basis/vite';
32
34
 
33
35
  export default defineConfig({
@@ -55,7 +57,7 @@ root.render(
55
57
  ```
56
58
 
57
59
  ### 4. Verify the Signal
58
- Drop this pattern into any component. Basis will identify the rhythm of the debt within ~100ms.
60
+ Drop this pattern into any component. For this pattern, Basis typically flags the rhythm of the debt within ~100ms; detection latency can vary for other patterns.
59
61
 
60
62
  ```tsx
61
63
  const [a, setA] = useState(0);
@@ -79,7 +81,7 @@ Fix: Derive b during the render phase (remove effect) or wrap in useMemo.
79
81
  ---
80
82
 
81
83
  ### 5. Control & Scope
82
- * **Ghost Mode:** Disable the Matrix UI while keeping console-based forensics active by setting `showHUD={false}` on the provider.
84
+ * **Ghost Mode:** Disable the visual overlay while keeping console-based forensics active by setting `showHUD={false}` on the provider.
83
85
  * **Selective Auditing:** Add `// @basis-ignore` at the top of any file to disable instrumentation. Recommended for:
84
86
  * High-frequency animation logic (>60fps)
85
87
  * Third-party library wrappers
@@ -87,30 +89,30 @@ Fix: Derive b during the render phase (remove effect) or wrap in useMemo.
87
89
 
88
90
  ---
89
91
 
90
- ## Visual Proof
92
+ ## HUD
91
93
 
92
- The optional HUD shows your **State Basis Matrix** in real-time. Purple pulses ($\Omega$) are Context anchors; Red pulses (!) are redundant shadows.
94
+ The optional overlay shows your component's state updates in real time. Purple pulses mark updates coming from Context; red pulses mark state that looks like a redundant copy of something else.
93
95
 
94
96
  <p align="center">
95
97
  <img src="./assets/050Basis.gif" width="800" alt="Basis Demo" />
96
98
  </p>
97
99
 
98
- > **Note:** While the HUD visualizes real-time updates, the **Architectural Health Report** (Console) provides the deep topological analysis.
100
+ > **Note:** The HUD shows updates as they happen. The **Architectural Health Report** (Console) looks at the whole update graph together, so it can catch patterns a single glance at the HUD would miss.
99
101
 
100
102
  ---
101
103
 
102
104
  ## What Basis Detects
103
105
 
104
- Basis uses **Graph Theory**, **Signal Processing**, and **Linear Algebra** to identify architectural violations that static linters miss:
106
+ Basis watches *when* your state updates and looks for timing patterns that usually mean architectural debt - two states always changing together, an effect immediately re-triggering a render, a click that fans out into updates across unrelated files. Every flag below is a signal to investigate, not a verified defect:
105
107
 
106
- - **⚡ Double Renders (Sync Leaks)** - Detects when a `useEffect` triggers a state update immediately after a render, forcing the browser to paint twice.
107
- - **⚡ Prime Movers (Root Causes)** - Ignores downstream symptoms and points you to the exact hook or event that started the chain reaction.
108
- - **⚡ Fragmented Updates** - Detects when a single click forces updates in multiple different files/contexts simultaneously (Tearing risk).
109
- - **Ω Context Mirroring** - Detects when you redundanty copy Global Context data into Local State (creating two sources of truth).
110
- - **♊ Duplicate State** - Identifies variables that always update at the exact same time and should be merged (e.g. `isLoading` + `isSuccess`).
108
+ - **⚡ Double Renders (Sync Leaks)** - A `useEffect` triggers a state update immediately after a render, forcing the browser to paint twice.
109
+ - **⚡ Prime Movers (Likely Root Causes)** - Skips downstream symptoms and points you to the hook or event most likely to have started the chain reaction. When multiple updates fire in the same tick, Basis ranks candidates by their position in the update graph rather than asserting a single definitive cause.
110
+ - **⚡ Fragmented Updates** - A single click forces updates in multiple different files or contexts at once (tearing risk).
111
+ - **Context Mirroring** - You're redundantly copying Global Context data into local state, creating two sources of truth.
112
+ - **Duplicate State** - Two variables always update at the exact same time and should probably be merged (e.g. `isLoading` + `isSuccess`).
111
113
  - **🛑 Infinite Loops** - A safety circuit-breaker that kills the auditor before a recursive update freezes your browser.
112
114
 
113
- [**See examples & fixes →**](https://github.com/liovic/react-state-basis/wiki/The-Forensic-Catalog)
115
+ Under the hood this is timing correlation over an update graph - ideas borrowed loosely from graph theory and signal processing, not a formal proof. [**See examples & fixes →**](https://github.com/liovic/react-state-basis/wiki/The-Forensic-Catalog)
114
116
 
115
117
  ---
116
118
 
@@ -119,9 +121,9 @@ Basis uses **Graph Theory**, **Signal Processing**, and **Linear Algebra** to id
119
121
  ### Architectural Health Report
120
122
  Check your entire app's state architecture by running `window.printBasisReport()` in the console.
121
123
 
122
- * **Refactor Priorities:** Uses **Spectral Influence** (Eigenvector Centrality) to rank bugs by their systemic impact. It tells you *what* to fix first.
123
- * **Efficiency Score:** A calculated percentage of how "clean" your architecture is (Sources of Truth - Causal Leaks).
124
- * **Sync Issues:** Groups entangled variables into clusters (e.g., Boolean Explosions).
124
+ * **Refactor Priorities:** Ranks issues by blast radius on the update graph, so you can see which hook or event has the widest fan-out across the rest of your app.
125
+ * **Efficiency Score:** A rough ratio of independent update sources vs effect-driven follow-up updates. Diagnostic, not a grade.
126
+ * **Sync Issues:** Groups variables that tend to update together into clusters (e.g., boolean pairs that are really one piece of state).
125
127
 
126
128
  ### Hardware Telemetry
127
129
  Verify engine efficiency and heap stability in real-time via `window.getBasisMetrics()`.
@@ -130,10 +132,10 @@ Verify engine efficiency and heap stability in real-time via `window.getBasisMet
130
132
 
131
133
  ## Real-World Evidence
132
134
 
133
- Basis is verified against industry-standard codebases to ensure high-fidelity detection:
135
+ Basis has been tested against industry-standard codebases:
134
136
 
135
- * **Excalidraw (114k⭐)** - Caught a theme-sync leak forcing a double-render on every toggle. [**PR #10637**](https://github.com/excalidraw/excalidraw/pull/10637)
136
- * **shadcn-admin (10k⭐)** - Detected redundant state pattern in viewport detection hooks. [**PR #274**](https://github.com/satnaing/shadcn-admin/pull/274) (MERGED)
137
+ * **Excalidraw (114k⭐)** - Proposed a theme-sync fix [**PR #10637**](https://github.com/excalidraw/excalidraw/pull/10637) (not merged)
138
+ * **shadcn-admin (10k⭐)** - Detected redundant state pattern in viewport detection hooks. [**PR #274**](https://github.com/satnaing/shadcn-admin/pull/274) (merged)
137
139
 
138
140
  ---
139
141
 
@@ -142,7 +144,7 @@ Basis is verified against industry-standard codebases to ensure high-fidelity de
142
144
  ### Zustand
143
145
 
144
146
  Wrap your store with `basisLogger` to give Basis visibility into external
145
- store updates. Store signals appear as Σ in the HUD and health report.
147
+ store updates. Store signals appear in the HUD and health report alongside your React state.
146
148
 
147
149
  ```typescript
148
150
  import { create } from 'zustand';
@@ -165,7 +167,7 @@ This enables detection of **Store Mirroring**, **Store Sync Leaks**, and
165
167
 
166
168
  ### More integrations coming
167
169
 
168
- Planned: XState, React Qery, Redux Toolkit. Community PRs welcome.
170
+ Planned: XState, React Query, Redux Toolkit. Community PRs welcome.
169
171
 
170
172
  ---
171
173
 
@@ -181,19 +183,19 @@ Planned: XState, React Qery, Redux Toolkit. Community PRs welcome.
181
183
 
182
184
  ## Documentation & Theory
183
185
 
184
- Basis is built on heuristics inspired by **Signal Processing**, **Linear Algebra**, and **Graph Theory**. To understand the underlying math, visit the [**Full Wiki**](https://github.com/liovic/react-state-basis/wiki).
186
+ The engine uses graph and timing heuristics to infer likely architectural issues from *when* state changes, not *what* it changes to. [**The wiki**](https://github.com/liovic/react-state-basis/wiki) explains the full mental model, the math it borrows from, and the engine internals. It is a heuristic, not a proof.
185
187
 
186
188
  ---
187
189
 
188
190
  ## Roadmap
189
191
 
190
- Each era of Basis answers a different architectural question:
192
+ Each version answers a different architectural question:
191
193
 
192
- ✓ **v0.4.x** - The Correlation Era - *Are these states moving together?*
193
- ✓ **v0.5.x** - The Decomposition Era - *Is this local state just a copy of Context?*
194
- → **v0.6.x** - The Graph Era - *Which bug should I fix first for maximum impact?*
195
- **v0.7.x** - The Information Era - *Does this state carry real information, or is it derivative?*
196
- **v0.8.x** - The Manifold Era - *How many hooks does your component actually need?*
194
+ ✓ **v0.4.x** - Detect states that always move together *(The Correlation Era)*
195
+ ✓ **v0.5.x** - Detect local copies of Context *(The Decomposition Era)*
196
+ → **v0.6.x** - Rank which update fans out widest *(The Graph Era)*
197
+ **v0.7.x** - Detect derivative vs. independent state *(The Information Era)*
198
+ **v0.8.x** - Estimate how much local state a component actually needs *(The Manifold Era)*
197
199
 
198
200
 
199
201
  [**More info**](https://github.com/liovic/react-state-basis/wiki/Roadmap)
@@ -204,4 +206,4 @@ Each era of Basis answers a different architectural question:
204
206
 
205
207
  Built by [LP](https://github.com/liovic) • [MIT License](https://opensource.org/licenses/MIT)
206
208
 
207
- </div>
209
+ </div>
@@ -62,11 +62,26 @@ var calculateSpectralInfluence = (graph, maxIterations = 20, tolerance = 1e-3) =
62
62
  return scores;
63
63
  };
64
64
 
65
- // src/core/ranker.ts
65
+ // src/core/constants.ts
66
+ var WINDOW_SIZE = 50;
67
+ var SIMILARITY_THRESHOLD = 0.88;
68
+ var LOOP_THRESHOLD = 150;
69
+ var VOLATILITY_THRESHOLD = 25;
70
+ var INSTANCE_SEP = "##";
71
+
72
+ // src/core/label.ts
73
+ var stripInstance = (label) => {
74
+ const idx = label.indexOf(INSTANCE_SEP);
75
+ return idx === -1 ? label : label.slice(0, idx);
76
+ };
66
77
  var parseLabel = (label) => {
67
- const parts = label.split(" -> ");
68
- return { file: parts[0] || "Unknown", name: parts[1] || label };
78
+ const base = stripInstance(label);
79
+ const parts = base.split(" -> ");
80
+ return { file: parts[0] || "Unknown", name: parts[1] || base };
69
81
  };
82
+ var isSameField = (labelA, labelB) => stripInstance(labelA) === stripInstance(labelB);
83
+
84
+ // src/core/ranker.ts
70
85
  var identifyTopIssues = (graph, history2, redundantLabels2, violationMap) => {
71
86
  const results = [];
72
87
  const influence = calculateSpectralInfluence(graph);
@@ -196,10 +211,6 @@ var STYLES = {
196
211
  bold: "font-weight: bold;",
197
212
  label: "background: #dfe6e9; color: #2d3436; padding: 0 4px; border-radius: 3px; font-family: monospace; font-weight: bold; border: 1px solid #b2bec3;"
198
213
  };
199
- var parseLabel2 = (label) => {
200
- const parts = label.split(" -> ");
201
- return { file: parts[0] || "Unknown", name: parts[1] || label };
202
- };
203
214
  var shouldLog = (key) => {
204
215
  const now = Date.now();
205
216
  const last = LAST_LOG_TIMES.get(key) || 0;
@@ -222,7 +233,7 @@ var getSuggestedFix = (issue, info) => {
222
233
  return `Local state is 'shadowing' Global Context. This creates two sources of truth. Delete the local state and consume the %cContext%c value directly.`;
223
234
  }
224
235
  if (leaks.length > 0) {
225
- const targetName = parseLabel2(leaks[0].target).name;
236
+ const targetName = parseLabel(leaks[0].target).name;
226
237
  if (issue.label.includes("effect")) {
227
238
  return `This Effect triggers a synchronous re-render of ${targetName}. Calculate ${targetName} during the render phase (Derived State) or wrap in %cuseMemo%c if expensive.`;
228
239
  }
@@ -252,7 +263,7 @@ var displayHealthReport = (history2, threshold, violationMap) => {
252
263
  `font-weight: normal; color: ${THEME.muted}; font-style: italic;`
253
264
  );
254
265
  topIssues.forEach((issue, idx) => {
255
- const info = parseLabel2(issue.label);
266
+ const info = parseLabel(issue.label);
256
267
  const icon = issue.metric === "influence" ? "\u26A1" : "\u{1F4C8}";
257
268
  const pColor = idx === 0 ? THEME.problem : idx === 1 ? THEME.solution : THEME.identity;
258
269
  let displayName = info.name;
@@ -272,7 +283,7 @@ var displayHealthReport = (history2, threshold, violationMap) => {
272
283
  const byFile = /* @__PURE__ */ new Map();
273
284
  issue.violations.forEach((v) => {
274
285
  if (issue.label.includes("Global Event") && v.type === "context_mirror") return;
275
- const { file, name } = parseLabel2(v.target);
286
+ const { file, name } = parseLabel(v.target);
276
287
  if (!byFile.has(file)) byFile.set(file, []);
277
288
  byFile.get(file).push(name);
278
289
  });
@@ -347,7 +358,7 @@ var displayHealthReport = (history2, threshold, violationMap) => {
347
358
  const clusterMetas = cluster.map((l) => ({
348
359
  label: l,
349
360
  meta: history2.get(l),
350
- name: parseLabel2(l).name
361
+ name: parseLabel(l).name
351
362
  }));
352
363
  const hasCtx = clusterMetas.some(
353
364
  (c) => c.meta.role === "context" /* CONTEXT */ || c.meta.role === "store" /* STORE */
@@ -388,8 +399,8 @@ var displayHealthReport = (history2, threshold, violationMap) => {
388
399
  };
389
400
  var displayRedundancyAlert = (labelA, metaA, labelB, metaB, sim) => {
390
401
  if (!isWeb || !shouldLog(`redundant-${labelA}-${labelB}`)) return;
391
- const infoA = parseLabel2(labelA);
392
- const infoB = parseLabel2(labelB);
402
+ const infoA = parseLabel(labelA);
403
+ const infoB = parseLabel(labelB);
393
404
  const isContextMirror = metaA.role === "local" /* LOCAL */ && metaB.role === "context" /* CONTEXT */ || metaB.role === "local" /* LOCAL */ && metaA.role === "context" /* CONTEXT */;
394
405
  const isStoreMirror = metaA.role === "local" /* LOCAL */ && metaB.role === "store" /* STORE */ || metaB.role === "local" /* LOCAL */ && metaA.role === "store" /* STORE */;
395
406
  const alertType = isContextMirror ? "CONTEXT MIRRORING" : isStoreMirror ? "STORE MIRRORING" : "DUPLICATE STATE";
@@ -434,8 +445,8 @@ var displayRedundancyAlert = (labelA, metaA, labelB, metaB, sim) => {
434
445
  };
435
446
  var displayCausalHint = (targetLabel, targetMeta, sourceLabel, sourceMeta) => {
436
447
  if (!isWeb || !shouldLog(`causal-${sourceLabel}-${targetLabel}`)) return;
437
- const target = parseLabel2(targetLabel);
438
- const source = parseLabel2(sourceLabel);
448
+ const target = parseLabel(targetLabel);
449
+ const source = parseLabel(sourceLabel);
439
450
  const headerType = sourceMeta.role === "context" /* CONTEXT */ ? "CONTEXT SYNC LEAK" : sourceMeta.role === "store" /* STORE */ ? "STORE SYNC LEAK" : "DOUBLE RENDER";
440
451
  const isEffect = sourceLabel.includes("effect") || sourceLabel.includes("useLayoutEffect");
441
452
  console.groupCollapsed(`%c \u26A1 BASIS | ${headerType} `, STYLES.headerProblem);
@@ -466,10 +477,10 @@ var displayCausalHint = (targetLabel, targetMeta, sourceLabel, sourceMeta) => {
466
477
  };
467
478
  var displayViolentBreaker = (label, count, threshold) => {
468
479
  if (!isWeb) return;
469
- const parts = label.split(" -> ");
480
+ const { name } = parseLabel(label);
470
481
  console.group(`%c \u{1F6D1} BASIS CRITICAL | CIRCUIT BREAKER `, STYLES.headerProblem);
471
482
  console.error(`INFINITE LOOP DETECTED
472
- Variable: ${parts[1] || label}
483
+ Variable: ${name}
473
484
  Frequency: ${count} updates/sec`);
474
485
  console.log(`%cACTION: Update BLOCKED to prevent browser freeze.`, `color: ${THEME.problem}; font-weight: bold;`);
475
486
  console.groupEnd();
@@ -479,12 +490,6 @@ var displayBootLog = (windowSize) => {
479
490
  console.log(`%cBasis%cAuditor%c "Graph Era" (Window: ${windowSize})`, STYLES.basis, STYLES.version, `color: ${THEME.muted}; font-style: italic; margin-left: 8px;`);
480
491
  };
481
492
 
482
- // src/core/constants.ts
483
- var WINDOW_SIZE = 50;
484
- var SIMILARITY_THRESHOLD = 0.88;
485
- var LOOP_THRESHOLD = 150;
486
- var VOLATILITY_THRESHOLD = 25;
487
-
488
493
  // src/core/analysis.ts
489
494
  var CAUSAL_MARGIN = 0.05;
490
495
  var isEventDriven = (label, graph) => {
@@ -521,6 +526,7 @@ var calculateAllSimilarities = (entryA, entryB) => {
521
526
  };
522
527
  var shouldSkipComparison = (entryA, entryB, dirtyLabels2) => {
523
528
  if (entryA.label === entryB.label) return true;
529
+ if (isSameField(entryA.label, entryB.label)) return true;
524
530
  if (dirtyLabels2.has(entryB.label) && entryA.label > entryB.label) return true;
525
531
  return false;
526
532
  };
@@ -855,6 +861,8 @@ if (typeof window !== "undefined") {
855
861
 
856
862
  export {
857
863
  WINDOW_SIZE,
864
+ INSTANCE_SEP,
865
+ parseLabel,
858
866
  history,
859
867
  redundantLabels,
860
868
  recordUpdate,
@@ -866,4 +874,4 @@ export {
866
874
  printBasisHealthReport,
867
875
  getBasisMetrics
868
876
  };
869
- //# sourceMappingURL=chunk-O2ZOR3L2.mjs.map
877
+ //# sourceMappingURL=chunk-E3D6YEKB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/math.ts","../src/core/graph.ts","../src/core/constants.ts","../src/core/label.ts","../src/core/ranker.ts","../src/core/logger.ts","../src/core/analysis.ts","../src/engine.ts"],"sourcesContent":["// src/core/math.ts\n\n/**\n * CIRCULAR SIMILARITY (v0.5.x)\n * Calculates Cosine Similarity across circular buffers.\n * \n * Optimization: Pre-normalizes the circular offset using a single modulo operation \n * outside the hot loop. This ensures the inner loop stays linearized (no division) \n * while remaining robust against extreme lead/lag values.\n */\nexport const calculateSimilarityCircular = (\n bufferA: Uint8Array,\n headA: number,\n bufferB: Uint8Array,\n headB: number,\n offset: number\n): number => {\n const L = bufferA.length;\n let dot = 0, magA = 0, magB = 0;\n\n const baseOffset = ((headB - headA + offset) % L + L) % L;\n\n for (let i = 0; i < L; i++) {\n const valA = bufferA[i];\n\n let iB = i + baseOffset;\n if (iB >= L) {\n iB -= L;\n }\n\n const valB = bufferB[iB];\n\n dot += valA * valB;\n magA += valA * valA;\n magB += valB * valB;\n }\n\n // Prevent Divide-by-Zero (Orthogonal/Idle result)\n if (magA === 0 || magB === 0) return 0;\n\n // Cosine Similarity Formula: (A · B) / (||A|| * ||B||)\n return dot / (Math.sqrt(magA) * Math.sqrt(magB));\n};\n\nexport const calculateCosineSimilarity = (A: Uint8Array, B: Uint8Array): number => {\n let dot = 0, magA = 0, magB = 0;\n for (let i = 0; i < A.length; i++) {\n dot += A[i] * B[i];\n magA += A[i] * A[i];\n magB += B[i] * B[i];\n }\n return (magA === 0 || magB === 0) ? 0 : dot / (Math.sqrt(magA) * Math.sqrt(magB));\n};\n","// src/core/graph.ts\n\nexport const calculateSpectralInfluence = (\n graph: Map<string, Map<string, number>>,\n maxIterations = 20,\n tolerance = 0.001\n) => {\n const nodes = Array.from(new Set([...graph.keys(), ...Array.from(graph.values()).flatMap(m => [...m.keys()])]));\n if (nodes.length === 0) return new Map<string, number>();\n\n let scores = new Map<string, number>();\n // Initialize: Every node starts with equal weight\n nodes.forEach(n => scores.set(n, 1 / nodes.length));\n\n for (let i = 0; i < maxIterations; i++) {\n const nextScores = new Map<string, number>();\n let totalWeight = 0;\n\n nodes.forEach(source => {\n let influence = 0;\n const outgoing = graph.get(source);\n\n if (outgoing) {\n outgoing.forEach((weight, target) => {\n // Rule: Source is important if it triggers targets that are active/important\n // We skip self-loops (source === target) to prevent artificial inflation\n if (source !== target) {\n influence += (scores.get(target) || 0) * weight;\n }\n });\n }\n // Every node has a \"Base\" existence weight to prevent sinks from reaching 0\n nextScores.set(source, influence + 0.01);\n totalWeight += (influence + 0.01);\n });\n\n // Normalize\n let delta = 0;\n nextScores.forEach((val, key) => {\n const normalized = val / totalWeight;\n const diff = normalized - (scores.get(key) || 0);\n delta += diff * diff;\n nextScores.set(key, normalized);\n });\n\n scores = nextScores;\n if (Math.sqrt(delta) < tolerance) break;\n }\n\n return scores;\n};\n","// src/core/constants.ts\n\nexport const WINDOW_SIZE = 50;\nexport const SIMILARITY_THRESHOLD = 0.88;\nexport const LOOP_THRESHOLD = 150;\nexport const LOOP_WINDOW_MS = 1000;\nexport const ANALYSIS_INTERVAL = 5;\n\nexport const VOLATILITY_THRESHOLD = 25;\n\nexport const INSTANCE_SEP = '##';","// src/core/label.ts\n\nimport { INSTANCE_SEP } from './constants';\n\nexport const stripInstance = (label: string): string => {\n const idx = label.indexOf(INSTANCE_SEP);\n return idx === -1 ? label : label.slice(0, idx);\n};\n\nexport const parseLabel = (label: string) => {\n const base = stripInstance(label);\n const parts = base.split(' -> ');\n return { file: parts[0] || \"Unknown\", name: parts[1] || base };\n};\n\nexport const isSameField = (labelA: string, labelB: string): boolean =>\n stripInstance(labelA) === stripInstance(labelB);","// src/core/ranker.ts\n\nimport { calculateSpectralInfluence } from './graph';\nimport { RingBufferMetadata, SignalRole, RankedIssue, ViolationDetail } from './types';\nimport { parseLabel } from './label';\n\nexport const identifyTopIssues = (\n graph: Map<string, Map<string, number>>,\n history: Map<string, RingBufferMetadata>,\n redundantLabels: Set<string>,\n violationMap: Map<string, ViolationDetail[]>\n): RankedIssue[] => {\n const results: RankedIssue[] = [];\n\n const influence = calculateSpectralInfluence(graph);\n\n const isEffect = (label: string) =>\n label.includes('effect_L') ||\n label.includes('useLayoutEffect') ||\n label.includes('useInsertionEffect');\n\n const isEvent = (label: string) => label.startsWith('Event_Tick_');\n\n // --- EVENT AGGREGATION MAP ---\n const eventSignatures = new Map<string, { count: number, score: number, targets: string[] }>();\n\n // 1. FILTER & PROCESS DRIVERS\n const drivers = Array.from(graph.entries())\n .filter(([label, targets]) => {\n if (targets.size === 0) return false;\n\n // AGGREGATE EVENTS\n if (isEvent(label)) {\n const validTargets = Array.from(targets.keys()).filter(t => {\n const meta = history.get(t);\n return meta && meta.role !== SignalRole.CONTEXT;\n });\n\n if (validTargets.length > 1) {\n const signature = validTargets.sort().join('|');\n const existing = eventSignatures.get(signature);\n if (existing) {\n existing.count++;\n existing.score = Math.max(existing.score, influence.get(label) || 0);\n } else {\n eventSignatures.set(signature, {\n count: 1,\n score: influence.get(label) || 0,\n targets: validTargets\n });\n }\n }\n return false;\n }\n\n // STANDARD NODE FILTERING\n const meta = history.get(label);\n if (meta?.role === SignalRole.CONTEXT) return false;\n if (meta?.role === SignalRole.PROJECTION) return false;\n\n const score = influence.get(label) || 0;\n if (isEffect(label) && targets.size > 0) return true;\n if (targets.size < 2 && score < 0.05) return false;\n\n return true;\n })\n .sort((a, b) => {\n const scoreA = influence.get(a[0]) || 0;\n const scoreB = influence.get(b[0]) || 0;\n return scoreB - scoreA;\n });\n\n // 2. INJECT AGGREGATED EVENTS (Top Priority)\n const sortedEvents = Array.from(eventSignatures.entries())\n .sort((a, b) => b[1].targets.length - a[1].targets.length);\n\n sortedEvents.slice(0, 2).forEach(([sig, data]) => {\n // Borrow the filename from the first target\n const primaryVictim = parseLabel(data.targets[0]);\n\n // We construct a label that looks like \"File.tsx -> Interaction Name\"\n // This tricks the Logger into printing the correct file location.\n const smartLabel = `${primaryVictim.file} -> Global Event (${primaryVictim.name})`;\n\n results.push({\n label: smartLabel,\n metric: 'influence',\n score: 1.0,\n reason: `Global Sync Event: An external trigger is updating ${data.targets.length} roots simultaneously. Occurred ${data.count} times.`,\n violations: data.targets.map(t => ({\n type: 'causal_leak',\n target: t\n }))\n });\n });\n\n // 3. GENERATE STANDARD ISSUES\n drivers.slice(0, 3 - results.length).forEach(([label, targets]) => {\n const targetNames = Array.from(targets.keys());\n\n if (isEffect(label)) {\n results.push({\n label,\n metric: 'influence',\n score: influence.get(label) || 0,\n reason: `Side-Effect Driver: Hook writes to state during render.`,\n violations: targetNames.map(t => ({ type: 'causal_leak', target: t }))\n });\n return;\n }\n\n results.push({\n label,\n metric: 'influence',\n score: influence.get(label) || targets.size,\n reason: `Sync Driver: Acts as a \"Prime Mover\" for ${targets.size} downstream signals.`,\n violations: targetNames.map(t => ({ type: 'causal_leak', target: t }))\n });\n });\n\n // 4. DENSITY FALLBACK\n if (results.length === 0) {\n const sortedDensity = Array.from(history.entries())\n .filter(([label, meta]) =>\n meta.role === SignalRole.LOCAL &&\n !redundantLabels.has(label) &&\n meta.density > 25\n )\n .sort((a, b) => b[1].density - a[1].density);\n\n sortedDensity.slice(0, 3).forEach(([label, meta]) => {\n results.push({\n label,\n metric: 'density',\n score: meta.density,\n reason: `High Frequency: potential main-thread saturation.`,\n violations: []\n });\n });\n }\n\n return results;\n};","// src/core/logger.ts\n\nimport { calculateCosineSimilarity } from \"./math\";\nimport { identifyTopIssues } from \"./ranker\";\nimport { RingBufferMetadata, SignalRole, RankedIssue, ViolationDetail } from \"./types\";\nimport { instance } from \"../engine\";\nimport { parseLabel } from \"./label\";\n\nconst isWeb = typeof window !== 'undefined' && typeof window.document !== 'undefined';\nconst LAST_LOG_TIMES = new Map<string, number>();\nconst LOG_COOLDOWN = 3000;\n\nconst THEME = {\n identity: \"#6C5CE7\", // Purple (Brand)\n problem: \"#D63031\", // Red (Bugs)\n solution: \"#FBC531\", // Yellow (Fixes)\n context: \"#0984E3\", // Blue (Locations)\n muted: \"#9AA0A6\", // Gray (Metadata)\n border: \"#2E2E35\",\n success: \"#00b894\", // Green (Good Score)\n};\n\nconst STYLES = {\n // Structure\n basis: `background: ${THEME.identity}; color: white; font-weight: bold; padding: 2px 6px; border-radius: 3px;`,\n headerIdentity: `background: ${THEME.identity}; color: white; font-weight: bold; padding: 4px 8px; border-radius: 4px;`,\n headerProblem: `background: ${THEME.problem}; color: white; font-weight: bold; padding: 4px 8px; border-radius: 4px;`,\n version: `background: #a29bfe; color: #2d3436; padding: 2px 6px; border-radius: 3px; margin-left: -4px;`,\n\n // Actions\n actionLabel: `color: ${THEME.solution}; font-weight: bold;`,\n actionPill: `color: ${THEME.solution}; font-weight: bold; border: 1px solid ${THEME.solution}; padding: 0 4px; border-radius: 3px;`,\n\n // Context\n impactLabel: `color: ${THEME.context}; font-weight: bold;`,\n location: `color: ${THEME.context}; font-family: monospace; font-weight: bold;`,\n\n // Text\n subText: `color: ${THEME.muted}; font-size: 11px;`,\n bold: \"font-weight: bold;\",\n label: \"background: #dfe6e9; color: #2d3436; padding: 0 4px; border-radius: 3px; font-family: monospace; font-weight: bold; border: 1px solid #b2bec3;\",\n};\n\nconst shouldLog = (key: string) => {\n const now = Date.now();\n const last = LAST_LOG_TIMES.get(key) || 0;\n if (now - last > LOG_COOLDOWN) {\n LAST_LOG_TIMES.set(key, now);\n return true;\n }\n return false;\n};\n\n// Helper: Detects boolean flags vs data\nconst isBooleanLike = (name: string) =>\n /^(is|has|can|should|did|will|show|hide)(?=[A-Z_])/.test(name);\n\n// --- SUGGESTION LOGIC ---\nconst getSuggestedFix = (issue: RankedIssue, info: { name: string }): string => {\n\n // 1. GLOBAL EVENT (Split State)\n if (issue.label.includes('Global Event')) {\n return `These variables update together but live in different hooks/files. Consolidate them into a single %cuseReducer%c or atomic store update.`;\n }\n\n const violations = issue.violations || [];\n const leaks = violations.filter(v => v.type === 'causal_leak');\n const mirrors = violations.filter(v => v.type === 'context_mirror');\n const duplicates = violations.filter(v => v.type === 'duplicate_state');\n\n // 2. CONTEXT MIRRORING (Shadow State)\n if (mirrors.length > 0) {\n return `Local state is 'shadowing' Global Context. This creates two sources of truth. ` +\n `Delete the local state and consume the %cContext%c value directly.`;\n }\n\n // 3. EFFECT CHAINS (Double Render)\n if (leaks.length > 0) {\n const targetName = parseLabel(leaks[0].target).name;\n\n // If driven by an Effect\n if (issue.label.includes('effect')) {\n return `This Effect triggers a synchronous re-render of ${targetName}. ` +\n `Calculate ${targetName} during the render phase (Derived State) or wrap in %cuseMemo%c if expensive.`;\n }\n // If driven by State (A -> B)\n return `State cascading detected. ${info.name} triggers ${targetName} in a separate frame. ` +\n `Merge them into one object to update simultaneously.`;\n }\n\n // 4. DUPLICATE STATE (Restored Logic)\n if (duplicates.length > 0) {\n // Boolean Explosion Logic\n if (isBooleanLike(info.name)) {\n return `Boolean Explosion detected. Multiple flags are toggling in sync. ` +\n `Replace impossible states with a single %cstatus%c string ('idle' | 'loading' | 'success').`;\n }\n return `Redundant State detected. This variable carries no unique information. ` +\n `Derive it from the source variable during render, or use %cuseMemo%c to cache the result.`;\n }\n\n // 5. HIGH FREQUENCY\n if (issue.metric === 'density') {\n return `High-Frequency Update. This variable updates faster than the frame rate. ` +\n `Apply %cdebounce%c or move to a Ref to unblock the main thread.`;\n }\n\n return `Check the dependency chain of ${info.name}.`;\n};\n\n\nexport const displayHealthReport = (history: Map<string, RingBufferMetadata>, threshold: number, violationMap: Map<string, ViolationDetail[]>) => {\n if (!isWeb) return;\n const entries = Array.from(history.entries());\n if (entries.length === 0) return;\n\n const topIssues = identifyTopIssues(instance.graph, history, instance.redundantLabels, violationMap);\n\n console.group(`%c 📊 BASIS | ARCHITECTURAL HEALTH REPORT `, STYLES.headerIdentity);\n\n // 1. REFACTOR PRIORITIES\n if (topIssues.length > 0) {\n console.log(`%c🎯 REFACTOR PRIORITIES %c(PRIME MOVERS)`,\n `font-weight: bold; color: ${THEME.identity}; margin-top: 10px;`,\n `font-weight: normal; color: ${THEME.muted}; font-style: italic;`\n );\n\n topIssues.forEach((issue, idx) => {\n const info = parseLabel(issue.label);\n const icon = issue.metric === 'influence' ? '⚡' : '📈';\n\n const pColor = idx === 0 ? THEME.problem : idx === 1 ? THEME.solution : THEME.identity;\n\n let displayName = info.name;\n let displayFile = info.file;\n\n if (issue.label.includes('Global Event')) {\n displayName = info.name;\n displayFile = info.file;\n }\n\n console.group(\n ` %c${idx + 1}%c ${icon} ${displayName} %c(${displayFile})`,\n `background: ${pColor}; color: ${idx === 1 ? 'black' : 'white'}; border-radius: 50%; padding: 0 5px;`,\n \"font-family: monospace; font-weight: 700;\",\n `color: ${THEME.muted}; font-size: 10px; font-weight: normal; font-style: italic;`\n );\n\n console.log(`%c${issue.reason}`, `color: ${THEME.muted}; font-style: italic;`);\n\n // IMPACTS: Grouped by File\n if (issue.violations.length > 0) {\n const byFile = new Map<string, string[]>();\n\n issue.violations.forEach(v => {\n if (issue.label.includes('Global Event') && v.type === 'context_mirror') return;\n const { file, name } = parseLabel(v.target);\n if (!byFile.has(file)) byFile.set(file, []);\n byFile.get(file)!.push(name);\n });\n\n const impactParts: string[] = [];\n byFile.forEach((vars, file) => {\n const varList = vars.join(', ');\n impactParts.push(`${file} (${varList})`);\n });\n\n if (impactParts.length > 0) {\n console.log(`%cImpacts: %c${impactParts.join(' + ')}`, STYLES.impactLabel, \"\");\n }\n }\n\n // SOLUTION\n const fix = getSuggestedFix(issue, info);\n const fixParts = fix.split('%c');\n\n if (fixParts.length === 3) {\n console.log(\n `%cSolution: %c${fixParts[0]}%c${fixParts[1]}%c${fixParts[2]}`,\n STYLES.actionLabel,\n \"\",\n STYLES.actionPill,\n \"\"\n );\n } else {\n console.log(\n `%cSolution: %c${fix}`,\n STYLES.actionLabel,\n \"\"\n );\n }\n\n console.groupEnd();\n });\n console.log(\"\\n\");\n }\n\n // 2. EFFICIENCY SCORE\n const clusters: string[][] = [];\n const processed = new Set<string>();\n let independentCount = 0;\n\n // A. Redundancy Check\n entries.forEach(([labelA, metaA]) => {\n if (processed.has(labelA)) return;\n const currentCluster = [labelA];\n processed.add(labelA);\n entries.forEach(([labelB, metaB]) => {\n if (labelA === labelB || processed.has(labelB)) return;\n if (calculateCosineSimilarity(metaA.buffer, metaB.buffer) > threshold) {\n if (metaA.role === SignalRole.CONTEXT && metaB.role === SignalRole.CONTEXT) return;\n currentCluster.push(labelB);\n processed.add(labelB);\n }\n });\n if (currentCluster.length > 1) clusters.push(currentCluster); else independentCount++;\n });\n\n // B. Causality Check (Graph Penalty)\n const totalVars = entries.length;\n const redundancyScore = ((independentCount + clusters.length) / totalVars) * 100;\n\n let internalEdges = 0;\n instance.graph.forEach((targets, source) => {\n if (source.startsWith('Event_Tick_')) return;\n internalEdges += targets.size;\n });\n\n const causalPenalty = (internalEdges / totalVars) * 100;\n\n let healthScore = redundancyScore - causalPenalty;\n if (healthScore < 0) healthScore = 0;\n\n const scoreColor = healthScore > 85 ? THEME.success : THEME.problem;\n\n console.log(`%cSystem Efficiency: %c${healthScore.toFixed(1)}%`,\n STYLES.bold, `color: ${scoreColor}; font-weight: bold;`\n );\n console.log(`%cSources of Truth: ${independentCount + clusters.length}/${totalVars} | Causal Leaks: ${internalEdges}`, STYLES.subText);\n\n // 3. SYNC ISSUES\n if (clusters.length > 0) {\n console.log(`%cDetected ${clusters.length} Sync Issues:`, `font-weight: bold; color: ${THEME.problem}; margin-top: 10px;`);\n\n clusters.forEach((cluster, idx) => {\n const clusterMetas = cluster.map(l => ({\n label: l,\n meta: history.get(l)!,\n name: parseLabel(l).name\n }));\n const hasCtx = clusterMetas.some(c =>\n c.meta.role === SignalRole.CONTEXT || c.meta.role === SignalRole.STORE\n );\n\n const names = clusterMetas.map(c => {\n const prefix = c.meta.role === SignalRole.STORE ? 'Σ ' : c.meta.role === SignalRole.CONTEXT ? 'Ω ' : '';\n return `${prefix}${c.name}`;\n }).join(' ⟷ ');\n\n console.group(` %c${idx + 1}%c ${names}`, `background: ${THEME.problem}; color: white; border-radius: 50%; padding: 0 5px;`, \"font-family: monospace; font-weight: bold;\");\n\n if (hasCtx) {\n const hasStore = clusterMetas.some(c => c.meta.role === SignalRole.STORE);\n const sourceType = hasStore ? 'External Store' : 'global context';\n console.log(`%cDiagnosis: ${hasStore ? 'Store' : 'Context'} Mirroring. Local state is shadowing ${sourceType}.`, `color: ${THEME.problem};`);\n console.log(`%cSolution: Use ${sourceType} directly to avoid state drift.`, STYLES.actionLabel);\n } else {\n const boolKeywords = ['is', 'has', 'can', 'should', 'loading', 'success', 'error', 'active', 'enabled', 'open', 'visible'];\n const boolCount = clusterMetas.filter(c =>\n boolKeywords.some(kw => c.name.toLowerCase().startsWith(kw))\n ).length;\n\n const isBoolExplosion = cluster.length > 2 && (boolCount / cluster.length) > 0.5;\n if (isBoolExplosion) {\n console.log(`%cDiagnosis:%c Boolean Explosion. Multiple booleans updating in sync.`, STYLES.bold, \"\");\n console.log(`%cSolution:%c Combine into a single %cstatus%c string or a %creducer%c.`, STYLES.actionLabel, \"\", STYLES.actionPill, \"\", STYLES.actionPill, \"\");\n } else if (cluster.length > 2) {\n console.log(`%cDiagnosis:%c Sibling Updates. These states respond to the same event.`, STYLES.bold, \"\");\n console.log(`%cSolution:%c This may be intentional. If not, consolidate into a %creducer%c.`, STYLES.actionLabel, \"\", STYLES.actionPill, \"\");\n } else {\n console.log(`%cDiagnosis:%c Redundant State. Variables always change together.`, STYLES.bold, \"\");\n console.log(`%cSolution:%c Derive one from the other via %cuseMemo%c.`, STYLES.actionLabel, \"\", STYLES.actionPill, \"\");\n }\n }\n console.groupEnd();\n });\n } else {\n console.log(\"%c✨ Your architecture is clean. No redundant state detected.\", `color: ${THEME.success}; font-weight: bold;`);\n }\n console.groupEnd();\n};\n\n// --- LIVE STREAM LOGGERS ---\n\nexport const displayRedundancyAlert = (labelA: string, metaA: RingBufferMetadata, labelB: string, metaB: RingBufferMetadata, sim: number) => {\n if (!isWeb || !shouldLog(`redundant-${labelA}-${labelB}`)) return;\n const infoA = parseLabel(labelA);\n const infoB = parseLabel(labelB);\n const isContextMirror = (metaA.role === SignalRole.LOCAL && metaB.role === SignalRole.CONTEXT) ||\n (metaB.role === SignalRole.LOCAL && metaA.role === SignalRole.CONTEXT);\n\n const isStoreMirror = (metaA.role === SignalRole.LOCAL && metaB.role === SignalRole.STORE) ||\n (metaB.role === SignalRole.LOCAL && metaA.role === SignalRole.STORE);\n\n const alertType = isContextMirror ? 'CONTEXT MIRRORING' : isStoreMirror ? 'STORE MIRRORING' : 'DUPLICATE STATE';\n console.group(`%c ♊ BASIS | ${alertType} `, STYLES.headerProblem);\n console.log(`%c📍 Location: %c${infoA.file}`, STYLES.bold, STYLES.location);\n console.log(`%cIssue:%c ${infoA.name} and ${infoB.name} are synchronized (${(sim * 100).toFixed(0)}%).`, STYLES.bold, \"\");\n\n if (isContextMirror || isStoreMirror) {\n const sourceType = isStoreMirror ? 'External Store' : 'Global Context';\n console.log(`%cFix:%c Local state is 'shadowing' ${sourceType}. Delete the local state and consume the %c${sourceType}%c value directly.`,\n STYLES.bold, \"\",\n STYLES.actionPill, \"\"\n );\n } else {\n if (isBooleanLike(infoA.name) || isBooleanLike(infoB.name)) {\n console.log(`%cFix:%c Boolean Explosion detected. Merge flags into a single %cstatus%c string or %cuseReducer%c.`,\n STYLES.bold, \"\",\n STYLES.actionPill, \"\",\n STYLES.actionPill, \"\"\n );\n } else {\n console.log(`%cFix:%c Redundant State detected. Derive %c${infoB.name}%c from %c${infoA.name}%c during render, or use %cuseMemo%c.`,\n STYLES.bold, \"\",\n STYLES.label, \"\",\n STYLES.label, \"\",\n STYLES.actionPill, \"\"\n );\n }\n }\n console.groupEnd();\n};\n\nexport const displayCausalHint = (targetLabel: string, targetMeta: RingBufferMetadata, sourceLabel: string, sourceMeta: RingBufferMetadata) => {\n if (!isWeb || !shouldLog(`causal-${sourceLabel}-${targetLabel}`)) return;\n const target = parseLabel(targetLabel);\n const source = parseLabel(sourceLabel);\n const headerType = sourceMeta.role === SignalRole.CONTEXT\n ? 'CONTEXT SYNC LEAK'\n : sourceMeta.role === SignalRole.STORE\n ? 'STORE SYNC LEAK'\n : 'DOUBLE RENDER';\n\n const isEffect = sourceLabel.includes('effect') || sourceLabel.includes('useLayoutEffect');\n\n console.groupCollapsed(`%c ⚡ BASIS | ${headerType} `, STYLES.headerProblem);\n console.log(`%c📍 Location: %c${target.file}`, STYLES.bold, STYLES.location);\n console.log(`%cIssue:%c ${source.name} triggers ${target.name} in separate frames.`, STYLES.bold, \"\");\n\n if (isEffect) {\n console.log(`%cFix:%c Derive %c${target.name}%c during the render phase (remove effect) or wrap in %cuseMemo%c.`,\n STYLES.bold, \"\",\n STYLES.label, \"\",\n STYLES.actionPill, \"\"\n );\n } else {\n console.log(`%cFix:%c Merge %c${target.name}%c with %c${source.name}%c into a single state update.`,\n STYLES.bold, \"\",\n STYLES.label, \"\",\n STYLES.label, \"\"\n );\n }\n console.groupEnd();\n};\n\nexport const displayViolentBreaker = (label: string, count: number, threshold: number) => {\n if (!isWeb) return;\n const { name } = parseLabel(label);\n console.group(`%c 🛑 BASIS CRITICAL | CIRCUIT BREAKER `, STYLES.headerProblem);\n console.error(`INFINITE LOOP DETECTED\\nVariable: ${name}\\nFrequency: ${count} updates/sec`);\n console.log(`%cACTION: Update BLOCKED to prevent browser freeze.`, `color: ${THEME.problem}; font-weight: bold;`);\n console.groupEnd();\n};\n\nexport const displayBootLog = (windowSize: number) => {\n if (!isWeb) return;\n console.log(`%cBasis%cAuditor%c \"Graph Era\" (Window: ${windowSize})`, STYLES.basis, STYLES.version, `color: ${THEME.muted}; font-style: italic; margin-left: 8px;`);\n};","// src/core/analysis.ts\n\nimport * as UI from './logger';\nimport { calculateSimilarityCircular } from './math';\nimport { SIMILARITY_THRESHOLD } from './constants';\nimport { SignalRole, Entry, ViolationDetail } from './types';\nimport { isSameField } from './label';\n\ninterface Similarities {\n sync: number;\n bA: number;\n aB: number;\n max: number;\n}\n\nconst CAUSAL_MARGIN = 0.05;\n\n// --- NOISE REDUCTION ---\n// Check if a node is directly driven by a Virtual Event.\nconst isEventDriven = (label: string, graph: Map<string, Map<string, number>>): boolean => {\n for (const [parent, targets] of graph.entries()) {\n if (parent.startsWith('Event_Tick_') && targets.has(label)) {\n return true;\n }\n }\n return false;\n};\n\nconst calculateAllSimilarities = (entryA: Entry, entryB: Entry): Similarities => {\n const sync = calculateSimilarityCircular(\n entryA.meta.buffer,\n entryA.meta.head,\n entryB.meta.buffer,\n entryB.meta.head,\n 0\n );\n\n const bA = calculateSimilarityCircular(\n entryA.meta.buffer,\n entryA.meta.head,\n entryB.meta.buffer,\n entryB.meta.head,\n 1\n );\n\n const aB = calculateSimilarityCircular(\n entryA.meta.buffer,\n entryA.meta.head,\n entryB.meta.buffer,\n entryB.meta.head,\n -1\n );\n\n return { sync, bA, aB, max: Math.max(sync, bA, aB) };\n};\n\nconst shouldSkipComparison = (\n entryA: Entry,\n entryB: Entry,\n dirtyLabels: Set<string>\n): boolean => {\n if (entryA.label === entryB.label) return true;\n\n if (isSameField(entryA.label, entryB.label)) return true;\n\n if (dirtyLabels.has(entryB.label) && entryA.label > entryB.label) return true;\n return false;\n};\n\nconst pushViolation = (\n map: Map<string, ViolationDetail[]>,\n source: string,\n detail: ViolationDetail\n) => {\n if (!map.has(source)) {\n map.set(source, []);\n }\n const list = map.get(source)!;\n const exists = list.some(\n v => v.type === detail.type && v.target === detail.target\n );\n if (!exists) {\n list.push(detail);\n }\n};\n\nconst isGlobalSource = (role: SignalRole): boolean =>\n role === SignalRole.CONTEXT || role === SignalRole.STORE;\n\nconst detectRedundancy = (\n entryA: Entry,\n entryB: Entry,\n similarities: Similarities,\n redundantSet: Set<string>,\n violationMap: Map<string, ViolationDetail[]>\n): void => {\n const roleA = entryA.meta.role;\n const roleB = entryB.meta.role;\n\n if (isGlobalSource(roleA) && isGlobalSource(roleB)) return;\n if (entryA.meta.density < 2 || entryB.meta.density < 2) return;\n\n if (roleA === SignalRole.LOCAL && isGlobalSource(roleB)) {\n redundantSet.add(entryA.label);\n pushViolation(violationMap, entryB.label, { type: 'context_mirror', target: entryA.label, similarity: similarities.max });\n UI.displayRedundancyAlert(entryA.label, entryA.meta, entryB.label, entryB.meta, similarities.max);\n }\n else if (isGlobalSource(roleA) && roleB === SignalRole.LOCAL) {\n redundantSet.add(entryB.label);\n pushViolation(violationMap, entryA.label, { type: 'context_mirror', target: entryB.label, similarity: similarities.max });\n UI.displayRedundancyAlert(entryB.label, entryB.meta, entryA.label, entryA.meta, similarities.max);\n }\n else if (roleA === SignalRole.LOCAL && roleB === SignalRole.LOCAL) {\n redundantSet.add(entryA.label);\n redundantSet.add(entryB.label);\n pushViolation(violationMap, entryA.label, { type: 'duplicate_state', target: entryB.label, similarity: similarities.max });\n pushViolation(violationMap, entryB.label, { type: 'duplicate_state', target: entryA.label, similarity: similarities.max });\n UI.displayRedundancyAlert(entryA.label, entryA.meta, entryB.label, entryB.meta, similarities.max);\n }\n};\n\nconst detectCausalLeak = (\n entryA: Entry,\n entryB: Entry,\n similarities: Similarities,\n violationMap: Map<string, ViolationDetail[]>,\n graph: Map<string, Map<string, number>>\n): void => {\n if (entryA.isVolatile || entryB.isVolatile) return;\n\n if (similarities.max - similarities.sync < CAUSAL_MARGIN) return;\n\n const addLeak = (source: string, target: string) => {\n if (isEventDriven(target, graph)) return;\n\n if (!violationMap.has(source)) {\n violationMap.set(source, []);\n }\n violationMap.get(source)!.push({ type: 'causal_leak', target });\n \n const sourceEntry = source === entryA.label ? entryA : entryB;\n const targetEntry = source === entryA.label ? entryB : entryA;\n UI.displayCausalHint(target, targetEntry.meta, source, sourceEntry.meta);\n };\n\n // bA High = A[t] matches B[t+1]. A happens before B.\n // Source: A, Target: B\n if (similarities.bA === similarities.max) {\n addLeak(entryA.label, entryB.label);\n }\n // aB High = A[t+1] matches B[t]. B happens before A.\n // Source: B, Target: A\n else if (similarities.aB === similarities.max) {\n addLeak(entryB.label, entryA.label);\n }\n};\n\nexport const detectSubspaceOverlap = (\n dirtyEntries: Entry[],\n allEntries: Entry[],\n redundantSet: Set<string>,\n dirtyLabels: Set<string>,\n graph: Map<string, Map<string, number>>\n): { compCount: number; violationMap: Map<string, ViolationDetail[]> } => {\n let compCount = 0;\n const violationMap = new Map<string, ViolationDetail[]>();\n\n for (const entryA of dirtyEntries) {\n for (const entryB of allEntries) {\n if (shouldSkipComparison(entryA, entryB, dirtyLabels)) continue;\n\n compCount++;\n const similarities = calculateAllSimilarities(entryA, entryB);\n\n if (similarities.max > SIMILARITY_THRESHOLD) {\n detectRedundancy(entryA, entryB, similarities, redundantSet, violationMap);\n detectCausalLeak(entryA, entryB, similarities, violationMap, graph);\n }\n }\n }\n\n return { compCount, violationMap };\n};","// src/engine.ts\n\nimport * as UI from './core/logger';\nimport { detectSubspaceOverlap } from './core/analysis';\nimport {\n SignalRole,\n StateOptions,\n RingBufferMetadata,\n BasisEngineState,\n Entry,\n ViolationDetail\n} from './core/types';\nimport {\n WINDOW_SIZE,\n LOOP_THRESHOLD,\n VOLATILITY_THRESHOLD\n} from './core/constants';\n\n// --- Static Internal State ---\n\nconst BASIS_INSTANCE_KEY = Symbol.for('__basis_engine_instance__');\n\nconst GRAPH_CLEANUP_INTERVAL = 5000; // Run every 5 seconds\nconst EVENT_TTL = 10000; // Keep events for 10 seconds\n\nconst NULL_SIGNAL: RingBufferMetadata = {\n role: SignalRole.PROJECTION,\n buffer: new Uint8Array(0),\n head: 0,\n density: 0,\n options: {}\n};\n\n// --- v0.6.0 EVENT TOPOLOGY ---\nlet activeEventId: string | null = null;\nlet activeEventTimer: any = null;\n\n// Garbage Collect old Event Nodes\nconst pruneGraph = () => {\n const now = Date.now();\n\n // Only checking the keys (Source Nodes)\n for (const source of instance.graph.keys()) {\n if (source.startsWith('Event_Tick_')) {\n // Extract timestamp from \"Event_Tick_1738492...\"\n const parts = source.split('_');\n const timestamp = parseInt(parts[2], 10);\n \n if (now - timestamp > EVENT_TTL) {\n instance.graph.delete(source);\n }\n }\n }\n};\n\nconst getEventId = () => {\n if (!activeEventId) {\n activeEventId = `Event_Tick_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`;\n\n requestAnimationFrame(() => {\n activeEventId = null;\n });\n }\n return activeEventId;\n};\n\n// GLOBAL SINGLETON HMR BRIDGE\nconst getGlobalInstance = (): BasisEngineState => {\n const root = globalThis as any;\n if (!root[BASIS_INSTANCE_KEY]) {\n root[BASIS_INSTANCE_KEY] = {\n config: { debug: false },\n history: new Map<string, RingBufferMetadata>(),\n currentTickBatch: new Set<string>(),\n redundantLabels: new Set<string>(),\n booted: false,\n tick: 0,\n isBatching: false,\n currentEffectSource: null,\n lastStateUpdate: null,\n pausedVariables: new Set<string>(),\n graph: new Map<string, Map<string, number>>(),\n violationMap: new Map<string, ViolationDetail[]>(),\n metrics: {\n lastAnalysisTimeMs: 0,\n comparisonCount: 0,\n lastAnalysisTimestamp: 0,\n systemEntropy: 0\n },\n alertCount: 0,\n loopCounters: new Map<string, number>(),\n lastCleanup: Date.now()\n };\n }\n return root[BASIS_INSTANCE_KEY];\n};\n\nexport const instance = getGlobalInstance();\n\nexport const config = instance.config;\nexport const history = instance.history;\nexport const redundantLabels = instance.redundantLabels;\nexport const currentTickBatch = instance.currentTickBatch;\n\nlet currentTickRegistry: Record<string, boolean> = {};\nconst dirtyLabels = new Set<string>();\n\n// TEMPORAL ENTROPY\nconst calculateTickEntropy = (tickIdx: number) => {\n let activeCount = 0;\n const total = instance.history.size;\n if (total === 0) return 1;\n\n instance.history.forEach((meta: RingBufferMetadata) => {\n if (meta.buffer[tickIdx] === 1) activeCount++;\n });\n return 1 - (activeCount / total);\n};\n\nexport const recordEdge = (source: string, target: string) => {\n if (!source || !target || source === target) return;\n if (!instance.graph.has(source)) {\n instance.graph.set(source, new Map());\n }\n const targets = instance.graph.get(source)!;\n targets.set(target, (targets.get(target) || 0) + 1);\n};\n\nexport const analyzeBasis = () => {\n if (!instance.config.debug || dirtyLabels.size === 0) {\n return;\n }\n\n const scheduler = (globalThis as any).requestIdleCallback || ((cb: any) => setTimeout(cb, 1));\n const snapshot = new Set(dirtyLabels);\n dirtyLabels.clear();\n\n scheduler(() => {\n const analysisStart = performance.now();\n const allEntries: Entry[] = [];\n const dirtyEntries: Entry[] = [];\n\n instance.history.forEach((meta: RingBufferMetadata, label: string) => {\n if (meta.options.suppressAll || meta.density === 0) return;\n\n const entry: Entry = {\n label, meta,\n isVolatile: meta.density > VOLATILITY_THRESHOLD\n };\n\n allEntries.push(entry);\n if (snapshot.has(label)) {\n dirtyEntries.push(entry);\n }\n });\n\n if (dirtyEntries.length === 0 || allEntries.length < 2) return;\n\n const nextRedundant = new Set<string>();\n instance.redundantLabels.forEach((l: string) => {\n if (!snapshot.has(l)) {\n nextRedundant.add(l);\n }\n });\n\n const { compCount, violationMap } = detectSubspaceOverlap(\n dirtyEntries,\n allEntries,\n nextRedundant,\n snapshot,\n instance.graph\n );\n\n instance.redundantLabels.clear();\n nextRedundant.forEach((l: string) => {\n instance.redundantLabels.add(l);\n });\n\n violationMap.forEach((newList, label) => {\n const existing = instance.violationMap.get(label) || [];\n newList.forEach(detail => {\n const alreadyExists = existing.some(\n v => v.type === detail.type && v.target === detail.target\n );\n if (!alreadyExists) {\n existing.push(detail);\n }\n });\n instance.violationMap.set(label, existing);\n });\n\n if (instance.violationMap.size > 500) {\n const keys = Array.from(instance.violationMap.keys()).slice(0, 200);\n keys.forEach(k => instance.violationMap.delete(k));\n }\n\n instance.metrics.lastAnalysisTimeMs = performance.now() - analysisStart;\n instance.metrics.comparisonCount = compCount;\n instance.metrics.lastAnalysisTimestamp = Date.now();\n });\n};\n\nconst processHeartbeat = () => {\n instance.tick++;\n\n instance.history.forEach((meta: RingBufferMetadata, label: string) => {\n const oldValue = meta.buffer[meta.head];\n const newValue = instance.currentTickBatch.has(label) ? 1 : 0;\n\n meta.buffer[meta.head] = newValue;\n if (oldValue !== newValue) {\n meta.density += (newValue - oldValue);\n }\n\n meta.head = (meta.head + 1) % WINDOW_SIZE;\n });\n\n const lastHead = (instance.history.size > 0) ? (instance.tick % WINDOW_SIZE) : 0;\n instance.metrics.systemEntropy = calculateTickEntropy(lastHead);\n\n instance.currentTickBatch.clear();\n currentTickRegistry = {};\n instance.isBatching = false;\n instance.lastStateUpdate = null;\n\n if (dirtyLabels.size > 0) {\n analyzeBasis();\n }\n};\n\n// INTERCEPTION LAYER\nexport const recordUpdate = (label: string): boolean => {\n if (!instance.config.debug) return true;\n if (instance.pausedVariables.has(label)) return false;\n\n const now = Date.now();\n if (now - instance.lastCleanup > 1000) {\n instance.loopCounters.clear();\n instance.lastCleanup = now;\n\n pruneGraph();\n }\n\n const count = (instance.loopCounters.get(label) || 0) + 1;\n instance.loopCounters.set(label, count);\n\n if (count > LOOP_THRESHOLD) {\n UI.displayViolentBreaker(label, count, LOOP_THRESHOLD);\n instance.pausedVariables.add(label);\n return false;\n }\n\n const meta = instance.history.get(label);\n\n // --- CAUSAL RESOLUTION ---\n let edgeSource: string | null = null;\n\n // PRIORITY 1: Explicit Effect Driver\n // If we are inside an effect, it IS the cause.\n if (instance.currentEffectSource) {\n edgeSource = instance.currentEffectSource;\n }\n // PRIORITY 2: The Event Horizon (Siblings)\n // We removed the synchronous state-to-state link here.\n // If A and B update in the same event handler, they are siblings (Event -> A, Event -> B).\n // They are NOT a dependency chain (A -> B).\n else {\n edgeSource = getEventId();\n }\n\n // Record graph edge\n if (edgeSource && edgeSource !== label) {\n recordEdge(edgeSource, label);\n\n // Hinting Logic (only for non-events)\n if (instance.currentEffectSource && instance.currentEffectSource !== label) {\n\n const sourceMeta = instance.history.get(instance.currentEffectSource) || NULL_SIGNAL;\n\n // Volatility Guard\n if (meta && sourceMeta && meta.density < VOLATILITY_THRESHOLD && sourceMeta.density < VOLATILITY_THRESHOLD) {\n UI.displayCausalHint(label, meta, instance.currentEffectSource, sourceMeta);\n }\n }\n }\n\n // Source Tracking\n // We still track this for future features, but we don't use it for \n // immediate causal attribution anymore to prevent sibling-glomming.\n if (meta && meta.role === SignalRole.LOCAL && !instance.currentEffectSource) {\n instance.lastStateUpdate = label;\n }\n\n if (currentTickRegistry[label]) return true;\n\n currentTickRegistry[label] = true;\n instance.currentTickBatch.add(label);\n dirtyLabels.add(label);\n\n if (!instance.isBatching) {\n instance.isBatching = true;\n requestAnimationFrame(processHeartbeat);\n }\n\n return true;\n};\n\n// --- LIFECYCLE API ---\n\nexport const configureBasis = (c: any) => {\n Object.assign(instance.config, c);\n if (instance.config.debug && !instance.booted) {\n UI.displayBootLog(WINDOW_SIZE);\n instance.booted = true;\n }\n};\n\nexport const registerVariable = (l: string, o: StateOptions = {}) => {\n if (o.suppressAll) return;\n\n if (!instance.history.has(l)) {\n instance.history.set(l, {\n buffer: new Uint8Array(WINDOW_SIZE),\n head: 0,\n density: 0,\n options: o,\n role: o.role || SignalRole.LOCAL\n });\n }\n};\n\nexport const unregisterVariable = (l: string) => {\n instance.history.delete(l);\n instance.loopCounters.delete(l);\n instance.pausedVariables.delete(l);\n instance.redundantLabels.delete(l);\n};\n\nexport const beginEffectTracking = (l: string) => {\n if (instance.config.debug) instance.currentEffectSource = l;\n};\n\nexport const endEffectTracking = () => {\n instance.currentEffectSource = null;\n};\n\nexport const printBasisHealthReport = (threshold = 0.5) => {\n if (!instance.config.debug) return;\n UI.displayHealthReport(instance.history, threshold, instance.violationMap);\n};\n\nexport const getBasisMetrics = () => ({\n engine: 'v0.6.x',\n hooks: instance.history.size,\n analysis_ms: instance.metrics.lastAnalysisTimeMs.toFixed(3),\n entropy: instance.metrics.systemEntropy.toFixed(3)\n});\n\nif (typeof window !== 'undefined') {\n (window as any).printBasisReport = printBasisHealthReport;\n (window as any).getBasisMetrics = getBasisMetrics;\n}\n\nexport const __testEngine__ = {\n instance,\n history,\n configureBasis,\n registerVariable,\n unregisterVariable,\n recordUpdate,\n printBasisHealthReport,\n analyzeBasis,\n beginEffectTracking,\n endEffectTracking\n};\n"],"mappings":";AAUO,IAAM,8BAA8B,CACzC,SACA,OACA,SACA,OACA,WACW;AACX,QAAM,IAAI,QAAQ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