react-state-basis 0.6.3 → 0.6.5
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 +253 -74
- package/dist/{chunk-E3D6YEKB.mjs → chunk-EJXGN76H.mjs} +170 -2
- package/dist/chunk-EJXGN76H.mjs.map +1 -0
- package/dist/client.d.mts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js.map +1 -1
- package/dist/client.mjs.map +1 -1
- package/dist/index.d.mts +36 -1
- package/dist/index.d.ts +36 -1
- package/dist/index.js +184 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -2
- package/dist/index.mjs.map +1 -1
- package/dist/integrations/zustand.js +159 -0
- package/dist/integrations/zustand.js.map +1 -1
- package/dist/integrations/zustand.mjs +1 -1
- package/dist/plugin.js +2 -1
- package/dist/production.d.mts +3 -3
- package/dist/production.d.ts +3 -3
- package/dist/production.js +8 -7
- package/dist/production.js.map +1 -1
- package/dist/production.mjs +8 -7
- package/dist/production.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-E3D6YEKB.mjs.map +0 -1
|
@@ -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\nimport { BasisGraphNode, BasisGraphEdge, BasisEventGroup } from './types';\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\nexport const groupEventSources = (\n nodes: BasisGraphNode[],\n edges: BasisGraphEdge[]\n): BasisEventGroup[] => {\n const outgoing = new Map<string, BasisGraphEdge[]>();\n edges.forEach(e => {\n if (!outgoing.has(e.source)) outgoing.set(e.source, []);\n outgoing.get(e.source)!.push(e);\n });\n\n const eventSourceIds = nodes.filter(n => n.role === 'event').map(n => n.id);\n\n const signatureOf = (sourceEdges: BasisGraphEdge[]) =>\n sourceEdges\n .map(e => `${e.target}@${e.weight}`)\n .sort()\n .join('|');\n\n const buckets = new Map<string, string[]>();\n eventSourceIds.forEach(id => {\n const sig = signatureOf(outgoing.get(id) || []);\n if (!buckets.has(sig)) buckets.set(sig, []);\n buckets.get(sig)!.push(id);\n });\n\n const groups: BasisEventGroup[] = Array.from(buckets.values()).map(sourceIds => ({\n sourceIds,\n occurrences: sourceIds.length,\n edges: (outgoing.get(sourceIds[0]) || []).slice()\n }));\n\n return groups.sort((a, b) => (b.edges.length - a.edges.length) || (b.occurrences - a.occurrences));\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);\n\nexport const isEffectLabel = (name: string): boolean =>\n /^effect_L\\d+(:\\d+)?$/.test(name) ||\n name === 'anonymous_effect' ||\n name === 'anonymous_layout_effect';","// 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, BasisGraphJSON, BasisGraphNode, BasisGraphEdge } from \"./types\";\nimport { instance } from \"../engine\";\nimport { parseLabel, isEffectLabel } 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\nconst splitHookLine = (raw: string): { hook: string; line?: number } => {\n const m = raw.match(/^(.*):(\\d+)$/);\n if (!m) return { hook: raw };\n return { hook: m[1], line: Number(m[2]) };\n};\n\nconst formatHook = (raw: string): string => {\n const { hook } = splitHookLine(raw);\n if (!isEffectLabel(hook)) return hook;\n const lineMatch = hook.match(/L(\\d+)$/);\n return lineMatch ? `effect @ L${lineMatch[1]}` : 'effect (anonymous)';\n};\n\nconst formatNode = (node?: BasisGraphNode, fallbackId = '?'): string => {\n if (!node) return fallbackId;\n if (node.role === 'event') return 'Event';\n const hook = formatHook(node.name || node.id);\n if (node.file && hook) return `${node.file} → ${hook}`;\n return hook || node.id;\n};\n\nexport const displayGraphReport = (graph: BasisGraphJSON) => {\n if (!isWeb) return;\n if (graph.nodes.length === 0) {\n console.log(\n `%c 📊 BASIS | CAUSAL GRAPH %c(no data yet)`,\n STYLES.headerIdentity,\n `color: ${THEME.muted}; font-style: italic;`\n );\n return;\n }\n\n const nodeById = new Map(graph.nodes.map(n => [n.id, n]));\n const outgoing = new Map<string, BasisGraphEdge[]>();\n graph.edges.forEach(e => {\n if (!outgoing.has(e.source)) outgoing.set(e.source, []);\n outgoing.get(e.source)!.push(e);\n });\n\n type Group = {\n sourceIds: string[];\n sourceNode: BasisGraphNode | undefined;\n edges: BasisGraphEdge[];\n occurrences: number;\n };\n\n const eventGroups: Group[] = graph.eventGroups.map(g => ({\n sourceIds: g.sourceIds,\n sourceNode: nodeById.get(g.sourceIds[0]),\n edges: g.edges,\n occurrences: g.occurrences\n }));\n\n const groupedSourceIds = new Set(graph.eventGroups.flatMap(g => g.sourceIds));\n const nonEventGroups: Group[] = Array.from(outgoing.keys())\n .filter(id => !groupedSourceIds.has(id))\n .map(id => ({ sourceIds: [id], sourceNode: nodeById.get(id), edges: outgoing.get(id)!, occurrences: 1 }));\n\n const groups: Group[] = [...eventGroups, ...nonEventGroups].sort(\n (a, b) => (b.edges.length - a.edges.length) || (b.occurrences - a.occurrences)\n );\n\n console.group(\n `%c 📊 BASIS | CAUSAL GRAPH %c${graph.nodes.length} nodes · ${graph.edges.length} edges · ${groups.length} sources · buffer window ${graph.bufferWindowSize}`,\n STYLES.headerIdentity,\n `color: ${THEME.muted}; font-weight: normal; font-style: italic;`\n );\n console.log(\n `%cparent → child = observed cause → update. (×N) = times in this window. Event groups with the same fan-out are collapsed.`,\n STYLES.subText\n );\n\n groups.forEach(group => {\n const isEvent = group.sourceNode?.role === 'event';\n const isCtx = group.sourceNode?.role === SignalRole.CONTEXT;\n const isFx = group.sourceNode?.role === 'effect';\n const isUnknown = group.sourceNode?.role === 'unknown';\n const icon = isEvent ? '⚡' : isCtx ? 'Ω' : isFx ? '↯' : isUnknown ? '?' : '●';\n const color = isEvent ? THEME.solution : isCtx ? THEME.context : THEME.identity;\n\n const fanout = group.edges.length;\n const hits = group.occurrences;\n const hitLabel = hits > 1 ? ` · ×${hits}` : '';\n\n const title = isEvent\n ? `Event · ${fanout} target${fanout === 1 ? '' : 's'}${hitLabel}`\n : formatNode(group.sourceNode, group.sourceIds[0]);\n\n console.groupCollapsed(\n `%c${icon} %c${title}`,\n `color: ${color};`,\n 'font-family: monospace; font-weight: 600;'\n );\n\n group.edges\n .slice()\n .sort((a, b) => b.weight - a.weight)\n .forEach(edge => {\n const target = nodeById.get(edge.target);\n const label = formatNode(target, edge.target);\n const weight = edge.weight > 1 ? ` (×${edge.weight})` : '';\n if (target?.redundant) {\n console.log(\n `%c ${label}%c${weight} %credundant`,\n `color: ${THEME.muted}; font-family: monospace;`,\n `color: ${THEME.muted}; font-style: italic;`,\n `color: ${THEME.problem}; font-weight: bold;`\n );\n } else {\n console.log(\n `%c ${label}%c${weight}`,\n `color: ${THEME.muted}; font-family: monospace;`,\n `color: ${THEME.muted}; font-style: italic;`\n );\n }\n });\n\n console.groupEnd();\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 BasisGraphJSON,\n BasisGraphNode,\n BasisGraphEdge\n} from './core/types';\nimport {\n WINDOW_SIZE,\n LOOP_THRESHOLD,\n VOLATILITY_THRESHOLD\n} from './core/constants';\nimport { parseLabel, isEffectLabel } from './core/label';\nimport { groupEventSources } from './core/graph';\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 instance.graph.delete(l);\n instance.graph.forEach((targets) => targets.delete(l));\n\n instance.violationMap.delete(l);\n instance.violationMap.forEach((list) => {\n const idx = list.findIndex((v) => v.target === l);\n if (idx !== -1) list.splice(idx, 1);\n });\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\nexport const getBasisGraph = (): BasisGraphJSON => {\n const nodeIds = new Set<string>();\n const edges: BasisGraphEdge[] = [];\n\n instance.graph.forEach((targets, source) => {\n nodeIds.add(source);\n targets.forEach((weight, target) => {\n nodeIds.add(target);\n edges.push({ source, target, weight });\n });\n });\n\n const nodes: BasisGraphNode[] = Array.from(nodeIds).map((id) => {\n if (id.startsWith('Event_Tick_')) {\n return { id, name: 'Event', file: '(shared trigger)', role: 'event', density: null, redundant: false };\n }\n const meta = instance.history.get(id);\n const { file, name } = parseLabel(id);\n if (!meta) {\n const role = isEffectLabel(name) ? 'effect' : 'unknown';\n return { id, name, file, role, density: null, redundant: false };\n }\n return {\n id,\n name,\n file,\n role: meta.role,\n density: meta.density,\n redundant: instance.redundantLabels.has(id)\n };\n });\n\n return {\n generatedAt: Date.now(),\n bufferWindowSize: WINDOW_SIZE,\n eventTtlMs: EVENT_TTL,\n nodes,\n edges,\n eventGroups: groupEventSources(nodes, edges)\n };\n};\n\nexport const printBasisGraph = () => {\n if (!instance.config.debug) return;\n UI.displayGraphReport(getBasisGraph());\n};\n\nif (typeof window !== 'undefined') {\n (window as any).printBasisReport = printBasisHealthReport;\n (window as any).getBasisMetrics = getBasisMetrics;\n (window as any).getBasisGraph = getBasisGraph;\n (window as any).printBasisGraph = printBasisGraph;\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 getBasisGraph,\n printBasisGraph\n};"],"mappings":";AAUO,IAAM,8BAA8B,CACzC,SACA,OACA,SACA,OACA,WACW;AACX,QAAM,IAAI,QAAQ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oB,MAAM,SAAS,SAAS,MAAM,WAAW,MAAM;AAAA,IACvG;AACA,UAAM,OAAO,SAAS,QAAQ,IAAI,EAAE;AACpC,UAAM,EAAE,MAAM,KAAK,IAAI,WAAW,EAAE;AACpC,QAAI,CAAC,MAAM;AACT,YAAM,OAAO,cAAc,IAAI,IAAI,WAAW;AAC9C,aAAO,EAAE,IAAI,MAAM,MAAM,MAAM,SAAS,MAAM,WAAW,MAAM;AAAA,IACjE;AACA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,WAAW,SAAS,gBAAgB,IAAI,EAAE;AAAA,IAC5C;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,aAAa,KAAK,IAAI;AAAA,IACtB,kBAAkB;AAAA,IAClB,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,aAAa,kBAAkB,OAAO,KAAK;AAAA,EAC7C;AACF;AAEO,IAAM,kBAAkB,MAAM;AACnC,MAAI,CAAC,SAAS,OAAO,MAAO;AAC5B,EAAG,mBAAmB,cAAc,CAAC;AACvC;AAEA,IAAI,OAAO,WAAW,aAAa;AACjC,EAAC,OAAe,mBAAmB;AACnC,EAAC,OAAe,kBAAkB;AAClC,EAAC,OAAe,gBAAgB;AAChC,EAAC,OAAe,kBAAkB;AACpC;","names":["history","redundantLabels","meta","history","dirtyLabels"]}
|
package/dist/client.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ReactDOMClient from 'react-dom/client';
|
|
2
2
|
export { ReactDOMClient as default };
|
|
3
3
|
|
|
4
|
-
declare const createRoot:
|
|
5
|
-
declare const hydrateRoot:
|
|
4
|
+
declare const createRoot: typeof ReactDOMClient.createRoot;
|
|
5
|
+
declare const hydrateRoot: typeof ReactDOMClient.hydrateRoot;
|
|
6
6
|
|
|
7
7
|
export { createRoot, hydrateRoot };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ReactDOMClient from 'react-dom/client';
|
|
2
2
|
export { ReactDOMClient as default };
|
|
3
3
|
|
|
4
|
-
declare const createRoot:
|
|
5
|
-
declare const hydrateRoot:
|
|
4
|
+
declare const createRoot: typeof ReactDOMClient.createRoot;
|
|
5
|
+
declare const hydrateRoot: typeof ReactDOMClient.hydrateRoot;
|
|
6
6
|
|
|
7
7
|
export { createRoot, hydrateRoot };
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["// src/client.ts\n\nimport * as ReactDOMClient from 'react-dom/client';\n\nexport const createRoot =
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["// src/client.ts\n\nimport * as ReactDOMClient from 'react-dom/client';\n\nexport const createRoot = ReactDOMClient.createRoot;\nexport const hydrateRoot = ReactDOMClient.hydrateRoot;\n\nexport default ReactDOMClient;"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,oBAAAA;AAAA,EAAA;AAAA,qBAAAC;AAAA;AAAA;AAEA,qBAAgC;AAEzB,IAAMD,cAA4B;AAClC,IAAMC,eAA6B;AAE1C,IAAO,iBAAQ;","names":["createRoot","hydrateRoot"]}
|
package/dist/client.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["// src/client.ts\n\nimport * as ReactDOMClient from 'react-dom/client';\n\nexport const createRoot =
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["// src/client.ts\n\nimport * as ReactDOMClient from 'react-dom/client';\n\nexport const createRoot = ReactDOMClient.createRoot;\nexport const hydrateRoot = ReactDOMClient.hydrateRoot;\n\nexport default ReactDOMClient;"],"mappings":";AAEA,YAAY,oBAAoB;AAEzB,IAAMA,cAA4B;AAClC,IAAMC,eAA6B;AAE1C,IAAO,iBAAQ;","names":["createRoot","hydrateRoot"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,39 @@ import React__default, { ReactNode } from 'react';
|
|
|
3
3
|
export { basis } from './vite-plugin.mjs';
|
|
4
4
|
import 'vite';
|
|
5
5
|
|
|
6
|
+
declare enum SignalRole {
|
|
7
|
+
LOCAL = "local",
|
|
8
|
+
CONTEXT = "context",
|
|
9
|
+
PROJECTION = "proj",
|
|
10
|
+
STORE = "store"
|
|
11
|
+
}
|
|
12
|
+
interface BasisGraphNode {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
file: string;
|
|
16
|
+
role: SignalRole | 'event' | 'effect' | 'unknown';
|
|
17
|
+
density: number | null;
|
|
18
|
+
redundant: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface BasisGraphEdge {
|
|
21
|
+
source: string;
|
|
22
|
+
target: string;
|
|
23
|
+
weight: number;
|
|
24
|
+
}
|
|
25
|
+
interface BasisEventGroup {
|
|
26
|
+
sourceIds: string[];
|
|
27
|
+
occurrences: number;
|
|
28
|
+
edges: BasisGraphEdge[];
|
|
29
|
+
}
|
|
30
|
+
interface BasisGraphJSON {
|
|
31
|
+
generatedAt: number;
|
|
32
|
+
bufferWindowSize: number;
|
|
33
|
+
eventTtlMs: number;
|
|
34
|
+
nodes: BasisGraphNode[];
|
|
35
|
+
edges: BasisGraphEdge[];
|
|
36
|
+
eventGroups: BasisEventGroup[];
|
|
37
|
+
}
|
|
38
|
+
|
|
6
39
|
/**
|
|
7
40
|
* Standard React Reducer type inference helpers.
|
|
8
41
|
*/
|
|
@@ -53,5 +86,7 @@ declare const getBasisMetrics: () => {
|
|
|
53
86
|
analysis_ms: string;
|
|
54
87
|
entropy: string;
|
|
55
88
|
};
|
|
89
|
+
declare const getBasisGraph: () => BasisGraphJSON;
|
|
90
|
+
declare const printBasisGraph: () => void;
|
|
56
91
|
|
|
57
|
-
export { BasisProvider, configureBasis, createContext, getBasisMetrics, printBasisHealthReport, use, useActionState, useBasisConfig, useCallback, useContext, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useOptimistic, useReducer, useRef, useState, useSyncExternalStore, useTransition };
|
|
92
|
+
export { type BasisEventGroup, type BasisGraphEdge, type BasisGraphJSON, type BasisGraphNode, BasisProvider, configureBasis, createContext, getBasisGraph, getBasisMetrics, printBasisGraph, printBasisHealthReport, use, useActionState, useBasisConfig, useCallback, useContext, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useOptimistic, useReducer, useRef, useState, useSyncExternalStore, useTransition };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,39 @@ import React__default, { ReactNode } from 'react';
|
|
|
3
3
|
export { basis } from './vite-plugin.js';
|
|
4
4
|
import 'vite';
|
|
5
5
|
|
|
6
|
+
declare enum SignalRole {
|
|
7
|
+
LOCAL = "local",
|
|
8
|
+
CONTEXT = "context",
|
|
9
|
+
PROJECTION = "proj",
|
|
10
|
+
STORE = "store"
|
|
11
|
+
}
|
|
12
|
+
interface BasisGraphNode {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
file: string;
|
|
16
|
+
role: SignalRole | 'event' | 'effect' | 'unknown';
|
|
17
|
+
density: number | null;
|
|
18
|
+
redundant: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface BasisGraphEdge {
|
|
21
|
+
source: string;
|
|
22
|
+
target: string;
|
|
23
|
+
weight: number;
|
|
24
|
+
}
|
|
25
|
+
interface BasisEventGroup {
|
|
26
|
+
sourceIds: string[];
|
|
27
|
+
occurrences: number;
|
|
28
|
+
edges: BasisGraphEdge[];
|
|
29
|
+
}
|
|
30
|
+
interface BasisGraphJSON {
|
|
31
|
+
generatedAt: number;
|
|
32
|
+
bufferWindowSize: number;
|
|
33
|
+
eventTtlMs: number;
|
|
34
|
+
nodes: BasisGraphNode[];
|
|
35
|
+
edges: BasisGraphEdge[];
|
|
36
|
+
eventGroups: BasisEventGroup[];
|
|
37
|
+
}
|
|
38
|
+
|
|
6
39
|
/**
|
|
7
40
|
* Standard React Reducer type inference helpers.
|
|
8
41
|
*/
|
|
@@ -53,5 +86,7 @@ declare const getBasisMetrics: () => {
|
|
|
53
86
|
analysis_ms: string;
|
|
54
87
|
entropy: string;
|
|
55
88
|
};
|
|
89
|
+
declare const getBasisGraph: () => BasisGraphJSON;
|
|
90
|
+
declare const printBasisGraph: () => void;
|
|
56
91
|
|
|
57
|
-
export { BasisProvider, configureBasis, createContext, getBasisMetrics, printBasisHealthReport, use, useActionState, useBasisConfig, useCallback, useContext, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useOptimistic, useReducer, useRef, useState, useSyncExternalStore, useTransition };
|
|
92
|
+
export { type BasisEventGroup, type BasisGraphEdge, type BasisGraphJSON, type BasisGraphNode, BasisProvider, configureBasis, createContext, getBasisGraph, getBasisMetrics, printBasisGraph, printBasisHealthReport, use, useActionState, useBasisConfig, useCallback, useContext, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useOptimistic, useReducer, useRef, useState, useSyncExternalStore, useTransition };
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,9 @@ __export(index_exports, {
|
|
|
34
34
|
basis: () => basis,
|
|
35
35
|
configureBasis: () => configureBasis,
|
|
36
36
|
createContext: () => createContext,
|
|
37
|
+
getBasisGraph: () => getBasisGraph,
|
|
37
38
|
getBasisMetrics: () => getBasisMetrics,
|
|
39
|
+
printBasisGraph: () => printBasisGraph,
|
|
38
40
|
printBasisHealthReport: () => printBasisHealthReport,
|
|
39
41
|
use: () => use,
|
|
40
42
|
useActionState: () => useActionState,
|
|
@@ -125,6 +127,27 @@ var calculateSpectralInfluence = (graph, maxIterations = 20, tolerance = 1e-3) =
|
|
|
125
127
|
}
|
|
126
128
|
return scores;
|
|
127
129
|
};
|
|
130
|
+
var groupEventSources = (nodes, edges) => {
|
|
131
|
+
const outgoing = /* @__PURE__ */ new Map();
|
|
132
|
+
edges.forEach((e) => {
|
|
133
|
+
if (!outgoing.has(e.source)) outgoing.set(e.source, []);
|
|
134
|
+
outgoing.get(e.source).push(e);
|
|
135
|
+
});
|
|
136
|
+
const eventSourceIds = nodes.filter((n) => n.role === "event").map((n) => n.id);
|
|
137
|
+
const signatureOf = (sourceEdges) => sourceEdges.map((e) => `${e.target}@${e.weight}`).sort().join("|");
|
|
138
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
139
|
+
eventSourceIds.forEach((id) => {
|
|
140
|
+
const sig = signatureOf(outgoing.get(id) || []);
|
|
141
|
+
if (!buckets.has(sig)) buckets.set(sig, []);
|
|
142
|
+
buckets.get(sig).push(id);
|
|
143
|
+
});
|
|
144
|
+
const groups = Array.from(buckets.values()).map((sourceIds) => ({
|
|
145
|
+
sourceIds,
|
|
146
|
+
occurrences: sourceIds.length,
|
|
147
|
+
edges: (outgoing.get(sourceIds[0]) || []).slice()
|
|
148
|
+
}));
|
|
149
|
+
return groups.sort((a, b) => b.edges.length - a.edges.length || b.occurrences - a.occurrences);
|
|
150
|
+
};
|
|
128
151
|
|
|
129
152
|
// src/core/constants.ts
|
|
130
153
|
var WINDOW_SIZE = 50;
|
|
@@ -144,6 +167,7 @@ var parseLabel = (label) => {
|
|
|
144
167
|
return { file: parts[0] || "Unknown", name: parts[1] || base };
|
|
145
168
|
};
|
|
146
169
|
var isSameField = (labelA, labelB) => stripInstance(labelA) === stripInstance(labelB);
|
|
170
|
+
var isEffectLabel = (name) => /^effect_L\d+(:\d+)?$/.test(name) || name === "anonymous_effect" || name === "anonymous_layout_effect";
|
|
147
171
|
|
|
148
172
|
// src/core/ranker.ts
|
|
149
173
|
var identifyTopIssues = (graph, history2, redundantLabels2, violationMap) => {
|
|
@@ -539,6 +563,99 @@ var displayCausalHint = (targetLabel, targetMeta, sourceLabel, sourceMeta) => {
|
|
|
539
563
|
}
|
|
540
564
|
console.groupEnd();
|
|
541
565
|
};
|
|
566
|
+
var splitHookLine = (raw) => {
|
|
567
|
+
const m = raw.match(/^(.*):(\d+)$/);
|
|
568
|
+
if (!m) return { hook: raw };
|
|
569
|
+
return { hook: m[1], line: Number(m[2]) };
|
|
570
|
+
};
|
|
571
|
+
var formatHook = (raw) => {
|
|
572
|
+
const { hook } = splitHookLine(raw);
|
|
573
|
+
if (!isEffectLabel(hook)) return hook;
|
|
574
|
+
const lineMatch = hook.match(/L(\d+)$/);
|
|
575
|
+
return lineMatch ? `effect @ L${lineMatch[1]}` : "effect (anonymous)";
|
|
576
|
+
};
|
|
577
|
+
var formatNode = (node, fallbackId = "?") => {
|
|
578
|
+
if (!node) return fallbackId;
|
|
579
|
+
if (node.role === "event") return "Event";
|
|
580
|
+
const hook = formatHook(node.name || node.id);
|
|
581
|
+
if (node.file && hook) return `${node.file} \u2192 ${hook}`;
|
|
582
|
+
return hook || node.id;
|
|
583
|
+
};
|
|
584
|
+
var displayGraphReport = (graph) => {
|
|
585
|
+
if (!isWeb) return;
|
|
586
|
+
if (graph.nodes.length === 0) {
|
|
587
|
+
console.log(
|
|
588
|
+
`%c \u{1F4CA} BASIS | CAUSAL GRAPH %c(no data yet)`,
|
|
589
|
+
STYLES.headerIdentity,
|
|
590
|
+
`color: ${THEME.muted}; font-style: italic;`
|
|
591
|
+
);
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
const nodeById = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
595
|
+
const outgoing = /* @__PURE__ */ new Map();
|
|
596
|
+
graph.edges.forEach((e) => {
|
|
597
|
+
if (!outgoing.has(e.source)) outgoing.set(e.source, []);
|
|
598
|
+
outgoing.get(e.source).push(e);
|
|
599
|
+
});
|
|
600
|
+
const eventGroups = graph.eventGroups.map((g) => ({
|
|
601
|
+
sourceIds: g.sourceIds,
|
|
602
|
+
sourceNode: nodeById.get(g.sourceIds[0]),
|
|
603
|
+
edges: g.edges,
|
|
604
|
+
occurrences: g.occurrences
|
|
605
|
+
}));
|
|
606
|
+
const groupedSourceIds = new Set(graph.eventGroups.flatMap((g) => g.sourceIds));
|
|
607
|
+
const nonEventGroups = Array.from(outgoing.keys()).filter((id) => !groupedSourceIds.has(id)).map((id) => ({ sourceIds: [id], sourceNode: nodeById.get(id), edges: outgoing.get(id), occurrences: 1 }));
|
|
608
|
+
const groups = [...eventGroups, ...nonEventGroups].sort(
|
|
609
|
+
(a, b) => b.edges.length - a.edges.length || b.occurrences - a.occurrences
|
|
610
|
+
);
|
|
611
|
+
console.group(
|
|
612
|
+
`%c \u{1F4CA} BASIS | CAUSAL GRAPH %c${graph.nodes.length} nodes \xB7 ${graph.edges.length} edges \xB7 ${groups.length} sources \xB7 buffer window ${graph.bufferWindowSize}`,
|
|
613
|
+
STYLES.headerIdentity,
|
|
614
|
+
`color: ${THEME.muted}; font-weight: normal; font-style: italic;`
|
|
615
|
+
);
|
|
616
|
+
console.log(
|
|
617
|
+
`%cparent \u2192 child = observed cause \u2192 update. (\xD7N) = times in this window. Event groups with the same fan-out are collapsed.`,
|
|
618
|
+
STYLES.subText
|
|
619
|
+
);
|
|
620
|
+
groups.forEach((group) => {
|
|
621
|
+
const isEvent = group.sourceNode?.role === "event";
|
|
622
|
+
const isCtx = group.sourceNode?.role === "context" /* CONTEXT */;
|
|
623
|
+
const isFx = group.sourceNode?.role === "effect";
|
|
624
|
+
const isUnknown = group.sourceNode?.role === "unknown";
|
|
625
|
+
const icon = isEvent ? "\u26A1" : isCtx ? "\u03A9" : isFx ? "\u21AF" : isUnknown ? "?" : "\u25CF";
|
|
626
|
+
const color = isEvent ? THEME.solution : isCtx ? THEME.context : THEME.identity;
|
|
627
|
+
const fanout = group.edges.length;
|
|
628
|
+
const hits = group.occurrences;
|
|
629
|
+
const hitLabel = hits > 1 ? ` \xB7 \xD7${hits}` : "";
|
|
630
|
+
const title = isEvent ? `Event \xB7 ${fanout} target${fanout === 1 ? "" : "s"}${hitLabel}` : formatNode(group.sourceNode, group.sourceIds[0]);
|
|
631
|
+
console.groupCollapsed(
|
|
632
|
+
`%c${icon} %c${title}`,
|
|
633
|
+
`color: ${color};`,
|
|
634
|
+
"font-family: monospace; font-weight: 600;"
|
|
635
|
+
);
|
|
636
|
+
group.edges.slice().sort((a, b) => b.weight - a.weight).forEach((edge) => {
|
|
637
|
+
const target = nodeById.get(edge.target);
|
|
638
|
+
const label = formatNode(target, edge.target);
|
|
639
|
+
const weight = edge.weight > 1 ? ` (\xD7${edge.weight})` : "";
|
|
640
|
+
if (target?.redundant) {
|
|
641
|
+
console.log(
|
|
642
|
+
`%c ${label}%c${weight} %credundant`,
|
|
643
|
+
`color: ${THEME.muted}; font-family: monospace;`,
|
|
644
|
+
`color: ${THEME.muted}; font-style: italic;`,
|
|
645
|
+
`color: ${THEME.problem}; font-weight: bold;`
|
|
646
|
+
);
|
|
647
|
+
} else {
|
|
648
|
+
console.log(
|
|
649
|
+
`%c ${label}%c${weight}`,
|
|
650
|
+
`color: ${THEME.muted}; font-family: monospace;`,
|
|
651
|
+
`color: ${THEME.muted}; font-style: italic;`
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
console.groupEnd();
|
|
656
|
+
});
|
|
657
|
+
console.groupEnd();
|
|
658
|
+
};
|
|
542
659
|
var displayViolentBreaker = (label, count, threshold) => {
|
|
543
660
|
if (!isWeb) return;
|
|
544
661
|
const { name } = parseLabel(label);
|
|
@@ -901,6 +1018,13 @@ var unregisterVariable = (l) => {
|
|
|
901
1018
|
instance.loopCounters.delete(l);
|
|
902
1019
|
instance.pausedVariables.delete(l);
|
|
903
1020
|
instance.redundantLabels.delete(l);
|
|
1021
|
+
instance.graph.delete(l);
|
|
1022
|
+
instance.graph.forEach((targets) => targets.delete(l));
|
|
1023
|
+
instance.violationMap.delete(l);
|
|
1024
|
+
instance.violationMap.forEach((list) => {
|
|
1025
|
+
const idx = list.findIndex((v) => v.target === l);
|
|
1026
|
+
if (idx !== -1) list.splice(idx, 1);
|
|
1027
|
+
});
|
|
904
1028
|
};
|
|
905
1029
|
var beginEffectTracking = (l) => {
|
|
906
1030
|
if (instance.config.debug) instance.currentEffectSource = l;
|
|
@@ -918,9 +1042,53 @@ var getBasisMetrics = () => ({
|
|
|
918
1042
|
analysis_ms: instance.metrics.lastAnalysisTimeMs.toFixed(3),
|
|
919
1043
|
entropy: instance.metrics.systemEntropy.toFixed(3)
|
|
920
1044
|
});
|
|
1045
|
+
var getBasisGraph = () => {
|
|
1046
|
+
const nodeIds = /* @__PURE__ */ new Set();
|
|
1047
|
+
const edges = [];
|
|
1048
|
+
instance.graph.forEach((targets, source) => {
|
|
1049
|
+
nodeIds.add(source);
|
|
1050
|
+
targets.forEach((weight, target) => {
|
|
1051
|
+
nodeIds.add(target);
|
|
1052
|
+
edges.push({ source, target, weight });
|
|
1053
|
+
});
|
|
1054
|
+
});
|
|
1055
|
+
const nodes = Array.from(nodeIds).map((id) => {
|
|
1056
|
+
if (id.startsWith("Event_Tick_")) {
|
|
1057
|
+
return { id, name: "Event", file: "(shared trigger)", role: "event", density: null, redundant: false };
|
|
1058
|
+
}
|
|
1059
|
+
const meta = instance.history.get(id);
|
|
1060
|
+
const { file, name } = parseLabel(id);
|
|
1061
|
+
if (!meta) {
|
|
1062
|
+
const role = isEffectLabel(name) ? "effect" : "unknown";
|
|
1063
|
+
return { id, name, file, role, density: null, redundant: false };
|
|
1064
|
+
}
|
|
1065
|
+
return {
|
|
1066
|
+
id,
|
|
1067
|
+
name,
|
|
1068
|
+
file,
|
|
1069
|
+
role: meta.role,
|
|
1070
|
+
density: meta.density,
|
|
1071
|
+
redundant: instance.redundantLabels.has(id)
|
|
1072
|
+
};
|
|
1073
|
+
});
|
|
1074
|
+
return {
|
|
1075
|
+
generatedAt: Date.now(),
|
|
1076
|
+
bufferWindowSize: WINDOW_SIZE,
|
|
1077
|
+
eventTtlMs: EVENT_TTL,
|
|
1078
|
+
nodes,
|
|
1079
|
+
edges,
|
|
1080
|
+
eventGroups: groupEventSources(nodes, edges)
|
|
1081
|
+
};
|
|
1082
|
+
};
|
|
1083
|
+
var printBasisGraph = () => {
|
|
1084
|
+
if (!instance.config.debug) return;
|
|
1085
|
+
displayGraphReport(getBasisGraph());
|
|
1086
|
+
};
|
|
921
1087
|
if (typeof window !== "undefined") {
|
|
922
1088
|
window.printBasisReport = printBasisHealthReport;
|
|
923
1089
|
window.getBasisMetrics = getBasisMetrics;
|
|
1090
|
+
window.getBasisGraph = getBasisGraph;
|
|
1091
|
+
window.printBasisGraph = printBasisGraph;
|
|
924
1092
|
}
|
|
925
1093
|
|
|
926
1094
|
// src/hooks.ts
|
|
@@ -1029,6 +1197,11 @@ function useEffect(effect, deps, label) {
|
|
|
1029
1197
|
endEffectTracking();
|
|
1030
1198
|
return typeof destructor === "function" ? destructor : void 0;
|
|
1031
1199
|
}, deps);
|
|
1200
|
+
(0, import_react.useEffect)(() => {
|
|
1201
|
+
return () => {
|
|
1202
|
+
unregisterVariable(storageKey);
|
|
1203
|
+
};
|
|
1204
|
+
}, [storageKey]);
|
|
1032
1205
|
}
|
|
1033
1206
|
function useLayoutEffect(effect, deps, label) {
|
|
1034
1207
|
const effectiveLabel = label || "anonymous_layout_effect";
|
|
@@ -1040,6 +1213,11 @@ function useLayoutEffect(effect, deps, label) {
|
|
|
1040
1213
|
endEffectTracking();
|
|
1041
1214
|
return typeof destructor === "function" ? destructor : void 0;
|
|
1042
1215
|
}, deps);
|
|
1216
|
+
(0, import_react.useEffect)(() => {
|
|
1217
|
+
return () => {
|
|
1218
|
+
unregisterVariable(storageKey);
|
|
1219
|
+
};
|
|
1220
|
+
}, [storageKey]);
|
|
1043
1221
|
}
|
|
1044
1222
|
function useOptimistic(passthrough, reducer, label) {
|
|
1045
1223
|
const effectiveLabel = (0, import_react.useRef)(label || getFallbackLabel("optimistic")).current;
|
|
@@ -1051,7 +1229,10 @@ function useOptimistic(passthrough, reducer, label) {
|
|
|
1051
1229
|
unregisterVariable(storageKey);
|
|
1052
1230
|
};
|
|
1053
1231
|
}, [storageKey]);
|
|
1054
|
-
const [state, reactAddOptimistic] = React19.useOptimistic(
|
|
1232
|
+
const [state, reactAddOptimistic] = React19.useOptimistic(
|
|
1233
|
+
passthrough,
|
|
1234
|
+
reducer
|
|
1235
|
+
);
|
|
1055
1236
|
const addOptimistic = (0, import_react.useCallback)((payload) => {
|
|
1056
1237
|
if (recordUpdate(storageKey)) {
|
|
1057
1238
|
reactAddOptimistic(payload);
|
|
@@ -1310,7 +1491,9 @@ function basis() {
|
|
|
1310
1491
|
basis,
|
|
1311
1492
|
configureBasis,
|
|
1312
1493
|
createContext,
|
|
1494
|
+
getBasisGraph,
|
|
1313
1495
|
getBasisMetrics,
|
|
1496
|
+
printBasisGraph,
|
|
1314
1497
|
printBasisHealthReport,
|
|
1315
1498
|
use,
|
|
1316
1499
|
useActionState,
|