diff --git a/brainsnn-r3f-app/src/App.jsx b/brainsnn-r3f-app/src/App.jsx index afb3b3f..6f65555 100644 --- a/brainsnn-r3f-app/src/App.jsx +++ b/brainsnn-r3f-app/src/App.jsx @@ -24,6 +24,7 @@ import HeatmapTimeline from './components/HeatmapTimeline'; import KnowledgeBrainPanel from './components/KnowledgeBrainPanel'; import MCPBridgePanel from './components/MCPBridgePanel'; import CodeBrainPanel from './components/CodeBrainPanel'; +import GraphInsightsPanel from './components/GraphInsightsPanel'; import BrainStewardPanel from './components/BrainStewardPanel'; import ConversationBrainPanel from './components/ConversationBrainPanel'; import ImmunityPanel from './components/ImmunityPanel'; @@ -553,6 +554,21 @@ export default function App() { /> + + { + setState((prev) => ({ + ...prev, + regions: { ...prev.regions, ...payload.regions }, + scenario: payload.scenario, + tick: prev.tick + 1 + })); + recordImmunity(IMMUNITY_EVENTS.CODE_ANALYZED, {}); + toastSuccess('Graph insights mapped onto brain'); + }} + /> + + diff --git a/brainsnn-r3f-app/src/components/GraphInsightsPanel.jsx b/brainsnn-r3f-app/src/components/GraphInsightsPanel.jsx new file mode 100644 index 0000000..074b50b --- /dev/null +++ b/brainsnn-r3f-app/src/components/GraphInsightsPanel.jsx @@ -0,0 +1,320 @@ +import React, { useMemo, useState } from 'react'; +import { parseFiles } from '../utils/codeParser'; +import { detectCommunities, detectCommunitiesLeiden } from '../utils/communities'; +import { analyzeGraph } from '../utils/graphAnalytics'; +import { downloadGraphWikiBundle } from '../utils/wikiGenerator'; + +/** + * Layer 101 — Graph Insights + * + * Cannibalized from safishamsi/graphify. Takes the same code paste as + * Layer 20 and runs three structural analytics on top: + * - Edge confidence (EXTRACTED / INFERRED / AMBIGUOUS) provenance + * - God-node detection (cross-community hubs, artifact-filtered) + * - Surprising connections (cross-community + cross-filetype + asym) + * - Suggested questions (7 archetypes derived from graph structure) + * + * Toggle Leiden refinement to split disconnected communities. Export + * everything as a markdown wiki bundle. + */ +export default function GraphInsightsPanel({ onApplyToNetwork }) { + const [input, setInput] = useState(EXAMPLE_INPUT); + const [graph, setGraph] = useState(null); + const [algorithm, setAlgorithm] = useState('leiden'); // 'louvain' | 'leiden' + const [error, setError] = useState(null); + + const result = useMemo(() => { + if (!graph) return null; + try { + const detect = algorithm === 'leiden' ? detectCommunitiesLeiden : detectCommunities; + const communities = detect({ nodes: graph.nodes, edges: graph.edges }); + const analytics = analyzeGraph(graph, communities); + return { graph, communities, analytics }; + } catch (err) { + setError(err.message); + return null; + } + }, [graph, algorithm]); + + function handleAnalyze() { + setError(null); + const files = parseInput(input); + if (!files.length) { + setGraph(null); + return; + } + const parsed = parseFiles(files); + setGraph(parsed); + } + + function handleExport() { + if (!result) return; + downloadGraphWikiBundle(result.graph, result.communities, result.analytics); + } + + function applyToBrain() { + if (!result?.analytics) return; + const { godNodes, surprising, questions } = result.analytics; + // Map insight density onto cognitive regions: + // PFC = analytical load (questions) + // HPC = recall surface (god-nodes) + // CTX = breadth (community count) + // THL = signal routing (surprising connections) + // AMY = ambiguity / unease (AMBIGUOUS edges) + const ambig = (graph?.stats?.provenance?.AMBIGUOUS) || 0; + const regions = { + PFC: clamp(0.35 + questions.length * 0.04, 0.2, 0.95), + HPC: clamp(0.3 + godNodes.length * 0.05, 0.2, 0.9), + CTX: clamp(0.25 + (result.communities.communities.length || 0) * 0.03, 0.2, 0.9), + THL: clamp(0.25 + surprising.length * 0.04, 0.2, 0.9), + AMY: clamp(0.2 + ambig * 0.02, 0.15, 0.9), + BG: 0.35, + CBL: 0.3 + }; + onApplyToNetwork?.({ + regions, + scenario: `Graph Insights · ${godNodes.length} god-nodes · ${surprising.length} surprising · ${questions.length} questions` + }); + } + + return ( +
+
Layer 101
+

Graph Insights

+

+ Cannibalized from safishamsi/graphify. Edge-confidence provenance, + god-node detection, surprising connections, and 7 graph-derived + question archetypes — turns Layer 20 from a viewer into an analyst. +

+ + +