Skip to content

feat(layer-101): cannibalize safishamsi/graphify → Graph Insights#24

Draft
slavazeph-coder wants to merge 1 commit into
mainfrom
claude/integrate-graphify-JM6rl
Draft

feat(layer-101): cannibalize safishamsi/graphify → Graph Insights#24
slavazeph-coder wants to merge 1 commit into
mainfrom
claude/integrate-graphify-JM6rl

Conversation

@slavazeph-coder

Copy link
Copy Markdown
Owner

Summary

Cannibalized safishamsi/graphify's analytical layer on top of the existing Layer 20 code graph. Five additions, no new deps.

The-brain already had the retrieval side (Layers 20/24/28/33/34) — embeddings, BM25, RRF fusion, Louvain. What graphify uniquely offered was the analytical layer: provenance honesty, cross-community insight extraction, and graph-derived questions. That's what shipped.

What's new

  1. Edge provenancecodeParser.js tags every edge as
    EXTRACTED (1.0) / INFERRED (0.8) / AMBIGUOUS (0.5). Unresolved imports now surface as external:<module> nodes with AMBIGUOUS edges instead of being dropped.
  2. Leiden-litecommunities.js adds detectCommunitiesLeiden. Runs Louvain, then splits any community whose induced subgraph is disconnected. Captures Leiden's main guarantee (Traag et al. 2019) at <100 LOC.
  3. Graph analytics — new utils/graphAnalytics.js:
    • God-node detection — high-degree cross-community hubs, with synthetic-artifact filtering (degree-1 stubs and pure-container files excluded).
    • Surprising connections — composite score: confidence + cross-community + cross-filetype + peripheral→hub asymmetry + optional semantic similarity.
    • Suggested questions — 7 archetypes derived purely from graph structure: ambiguous edges, high-betweenness bridges (Brandes), isolated nodes, low-cohesion communities, tight-coupling pairs, external-load files, singletons.
  4. Wiki bundlewikiGenerator.js adds generateGraphWikiBundle / downloadGraphWikiBundle: index.md + community-N.md per community.
  5. Graph Insights panel (Layer 101)components/GraphInsightsPanel.jsx. Paste code → choose Leiden/Louvain → see provenance breakdown, god-nodes, surprising connections, suggested questions, export wiki. "Apply to brain" maps insight density onto cognitive regions (PFC=questions, HPC=hubs, AMY=ambiguity).

Files

File Status Purpose
src/utils/codeParser.js modified provenance tags + external nodes
src/utils/communities.js modified detectCommunitiesLeiden
src/utils/graphAnalytics.js new god-nodes, surprising, questions, Brandes betweenness
src/utils/wikiGenerator.js modified generateGraphWikiBundle
src/components/GraphInsightsPanel.jsx new Layer 101 UI
src/utils/layerCatalog.js modified Layer 101 registered
src/styles/global.css modified question-list + archetype chip
src/App.jsx modified panel mount + immunity hook

Test plan

  • npm run build — vite v5.4.21, 912 modules, clean
  • Manual: paste seeded multi-file example, verify god-nodes / surprising / questions populate
  • Manual: toggle Leiden ↔ Louvain, confirm Leiden splits metric appears
  • Manual: "Apply to brain" updates regions; "Export wiki" downloads markdown bundle
  • Manual: paste single file (no === path === delimiters) and confirm graceful single-file path

Trade-offs / notes

  • Kept Leiden as a pure-JS lite implementation (one BFS-split pass post-Louvain) instead of pulling graphology-communities-leiden — captures the connectedness guarantee without a new dep.
  • Tree-sitter WASM was considered for a richer call-graph but rejected: 3-5MB bundle hit for marginal gain over the existing regex parser.
  • Surprising-connections takes optional embeddings + cosineFn — wiring it to Layer 24 MiniLM is a follow-up (the panel ships without it for now).
  • The new external: nodes can inflate node count on import-heavy code; god-node detection excludes them by default.

🤖 Generated with Claude Code


Generated by Claude Code

Adds graphify's analytical layer on top of the existing Layer 20 code
graph. Five additions, no new deps:

1. Edge provenance — codeParser.js tags every edge as EXTRACTED (1.0),
   INFERRED (0.8), or AMBIGUOUS (0.5). Unresolved imports now surface
   as `external:<module>` nodes with AMBIGUOUS edges instead of being
   silently dropped.

2. Leiden-lite — communities.js adds detectCommunitiesLeiden which
   runs Louvain then splits any community whose induced subgraph is
   disconnected. Captures Leiden's main guarantee at <100 LOC.

3. Graph analytics — new utils/graphAnalytics.js with god-node
   detection (cross-community hubs, artifact-filtered), surprising-
   connections scoring (cross-community + cross-filetype +
   peripheral→hub + optional semantic), and 7 suggested-question
   archetypes derived purely from graph structure (ambiguous edges,
   high-betweenness bridges via Brandes, isolated nodes, low-cohesion
   communities, tight-coupling pairs, external-load files,
   singletons).

4. Wiki bundle — wikiGenerator.js adds generateGraphWikiBundle and
   downloadGraphWikiBundle: index.md + community-N.md per community,
   graphify-style article navigation.

5. Graph Insights panel — new components/GraphInsightsPanel.jsx
   (Layer 101). Paste code → choose Leiden/Louvain → see provenance
   breakdown, god-nodes, surprising connections, suggested questions.
   Apply to brain maps insight density onto cognitive regions
   (PFC=questions, HPC=hubs, AMY=ambiguity).

Wired into App.jsx, registered in layerCatalog.js as Layer 101 in the
'data' group. Build clean (vite v5.4.21, 912 modules transformed).
slavazeph-coder pushed a commit that referenced this pull request May 2, 2026
Roll the homepage repositioning across the in-product app, build the
Brand Risk Scorecard layer, and replace the homepage gallery
placeholders with real scan illustrations.

brainsnn-r3f-app
- index.html title + og + twitter meta now lead with "affective-
  intelligence engine" and the four-outcome positioning sentence.
- OnboardingWalkthrough STEPS rewritten — step 1 leads with the
  positioning sentence, the Cognitive Firewall is framed as "the
  engine," the new Brand Risk Scorecard gets its own step, and the
  ordering puts the engine before the visualization layer.
- MilestonePanel intro paragraph updated to the new framing.
- Layer 106 (Brand Risk Scorecard) added to layerCatalog and mounted
  in App.jsx behind an ErrorBoundary, after the Milestone panel.

L106 — Brand Risk Scorecard
- src/utils/brandRisk.js: splitItems / scoreItem / computeBrandRisk /
  brandBriefMarkdown. Pure functions, no side effects. Aggregates
  Cognitive Firewall (L4) + Propaganda Templates (L39) + Ad
  Transparency archetypes (L48) into a single 0–100 score with a
  4-tier classification (Clean / Watch / At risk / Critical).
- src/components/BrandRiskPanel.jsx: brand input + items textarea +
  load-sample helper, headline score card, dominant archetypes,
  most-fired templates, top 5 worst items, copy-brief-as-Markdown.
- Score formula: 60% mean pressure + 25% peak pressure + 15% high-
  risk archetype share. High-risk archetypes: abusive-domestic,
  phishing, conspiracy-hook, political-attack, cult-recruitment.
- Number 106 picked to avoid colliding with the open L101 PRs (#22,
  #24, #25 — see PR #27 description for the suggested resolution).

ui/brainsnn-site gallery
- public/scan-fear-cascade.svg, scan-certainty-theater.svg, and
  scan-affective-trajectory.svg — three hand-rolled SVG cards that
  match the new gallery copy. 4-dim score bars, brain proxy with the
  appropriate region glowing, evidence chips.
- GALLERY_ITEMS now carries an `image` field; App.jsx reads it with
  the demo-placeholder.svg as a fallback.

Builds
- npm run build --prefix ui/brainsnn-site — 624 modules, 8.03s, clean.
- npm run build --prefix brainsnn-r3f-app — 912 modules, 6.19s, clean.

https://claude.ai/code/session_brainsnn-ui-build-28ebr

Copy link
Copy Markdown
Owner Author

Heads up — there's a layer-number collision on main:

If #25 lands as the canonical L101–L105 thread, the cleanest resolution here is to renumber Graph Insights to L106 … wait, I just took L106 in #27 (Brand Risk Scorecard). So either:

  1. Renumber Graph Insights to L107 in src/utils/layerCatalog.js + the LAYER_ID constant in GraphInsightsPanel.jsx + the eyebrow string. Smallest delta.
  2. Coordinate with feat(quantum + L105): finish the alignment build, add eml universal primitive #25 to move Quantum to a different range so Graph Insights can keep L101.

Option 1 is the lower-conflict path. Happy to land the renumber on this branch if you want — just say the word.

For reference, the layer numbers I'm aware of as in-flight on top of main's 100 layers:

Layer PR Topic
101 #22, #24, #25 Quantum (#22, #25), Graph Insights (#24) — collision
102 #25 Quantum Bell Pair Lab
103 #25 Quantum Sweep
104 #25 Quantum Glossary
105 #25 Universal Primitive Lab (eml)
106 #27 Brand Risk Scorecard

Suggesting Graph Insights → L107 unless you'd rather have it land first as 101.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants