{# R7 · GRAPH center view (live) — INTERACTIVE node-edge graph. The Cortex knowledge / code graph rendered as an actual interactive NODE-EDGE graph (cytoscape.js, vendored at /static/cytoscape.min.js — no CDN), not just lists. Entities are nodes (coloured by kind via the node-kind palette), relationships are edges. Pan/zoom; click a node to focus + highlight its neighbours and populate the inspector; double-click re-centres the search on that node. The graph is BOUNDED server-side (main._graph_elements): the search hits + their 1-hop neighbours, capped at _GRAPH_NODE_CAP (~140) nodes — the Kaidera OS graph is ~5,868 nodes / 44k edges, so we never ship the whole thing to the browser. A "showing N of M" note makes the bound explicit. Data: nodes/edges from /cortex-graph-search (entities + one-hop relationships), headline counts from /graph/stats. The search box drives it — a term re-centres the graph on the matching entities + neighbours. Default (no term) seeds a project-flavoured catch-all so the canvas isn't empty. The entity + relationship LISTS are kept (collapsible side panel, "Lists" toggle) — the visual graph is primary but the verbatim rows stay reachable. The graph data may be thin/stale (the graph_rebuild cron has been flaky), so a clear "graph data may be stale" note always shows. Context (built in main._graph_view): `selected`, `selected_key` : project record + key (header) `gr_term` : current entity-search term ("" = seed) `gr_own_nodes/_edges` : this project's code-graph repo stats `gr_total_nodes/_edges` : cross-repo totals (context) `gr_repo_count` : code-graph repo count `gr_elements_json` : cytoscape elements (nodes+edges) JSON `gr_graph_nodes/_edges` : RENDERED node/edge counts (bounded) `gr_graph_total_nodes` : M for the "showing N of M" note `gr_node_cap`, `gr_graph_capped` : the cap + whether it clipped `gr_entities` + `gr_entity_count` : side-panel entity list `gr_relationships` + `gr_rel_count`: side-panel relationship list `gr_kind_counts` : {code, mem, work} tallies (legend) `gr_admin_reachable` : was /admin/cortex/entities reachable? `gr_entity_source` : "admin-l4" | "graph-search" #} {% if selected %}
{# ---------- header ---------- #}
Knowledge graph
{{ selected.display_name or selected.project_key }} L3 code graph + L4 entities
{# in-view entity search — reloads the graph view for this project + term #}
{# ---------- stale-data note (graph_rebuild cron has been flaky) ---------- #}
Graph data may be stale — the graph_rebuild cron has been failing, so node/edge counts and entities can lag the live state.
{# ---------- stats strip ---------- #}
{{ "{:,}".format(gr_own_nodes) if gr_own_nodes is not none else "—" }}
Nodes · {{ selected_key }}
{{ "{:,}".format(gr_own_edges) if gr_own_edges is not none else "—" }}
Edges · {{ selected_key }}
{{ "{:,}".format(gr_total_nodes) if gr_total_nodes is not none else "—" }}
Nodes · all repos
{{ "{:,}".format(gr_total_edges) if gr_total_edges is not none else "—" }}
Edges · all repos
{{ gr_repo_count }}
Code-graph repos
{# ---------- node-kind legend (over the RENDERED nodes) ---------- #}
Code & files {{ gr_kind_counts.code }} L3 Memory entities {{ gr_kind_counts.mem }} L4 Work & handoffs {{ gr_kind_counts.work }} L1 relationship edge
{# ======================================================================== MAIN — the interactive node-edge graph canvas (cytoscape) + a collapsible Lists side panel (entities + relationships). ======================================================================== #}
{# ----- the graph canvas ----- #}
{# elements payload: cytoscape JSON island the canvas JS reads #} {# the cytoscape mount #}
{# canvas toolbar (top-left): fit · re-layout #}
{{ selected_key }}
{# "showing N of M" bound note (bottom-left) #}
Showing {{ gr_graph_nodes }}{% if gr_graph_total_nodes is not none %} of {{ "{:,}".format(gr_graph_total_nodes) }}{% endif %} nodes · {{ gr_graph_edges }} edges {% if gr_graph_capped %} — capped at {{ gr_node_cap }}; search to explore{% else %} — bounded neighbourhood; search to explore{% endif %}
{# zoom stack (bottom-right) #}
{# empty-state overlay (no nodes returned) #} {% if gr_graph_nodes == 0 %}

No graph for “{{ gr_term or 'this seed' }}”.

No entities or relationships came back from cortex-graph-search. Try a different term, a file path, an entity name, or a handoff id.

{% endif %} {# node inspector (right, inside the canvas) — populated on node click #}
{# ----- collapsible LISTS side panel (entities + relationships) ----- #}
{# ---------- edge legend + provenance ---------- #}
Visual graph is a bounded neighbourhood — the search hits + their 1-hop neighbours (capped at {{ gr_node_cap }} nodes), not the whole {{ "{:,}".format(gr_graph_total_nodes) if gr_graph_total_nodes is not none else "full" }}-node graph. Nodes + edges from Cortex /cortex-graph-search (L3 + L4); headline counts from /graph/stats. {% if not gr_admin_reachable %} The L4 admin entity API (/admin/cortex/entities) is token-gated and not reachable from this read-only console, so the graph-search entities stand in.{% endif %}
{% else %}

Select a project to explore its knowledge graph.

{% endif %}