Skip to content

Commit d58b133

Browse files
aksOpsclaude
andcommitted
Fix LayerClassifier to update networkx data in-place via classify_store
The original classify() mutated temporary GraphNode copies that weren't persisted back to the graph. New classify_store() method updates the networkx node data dict directly. Moved to run after linkers so all nodes (including linker-created MODULE nodes) get classified. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 287f185 commit d58b133

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

src/code_intelligence/analyzer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,18 +378,18 @@ def _report(msg: str) -> None:
378378
exc_info=True,
379379
)
380380

381-
# ----------------------------------------------------------
382-
# 5b. Classify layers
383-
# ----------------------------------------------------------
384-
from code_intelligence.classifiers.layer_classifier import LayerClassifier
385-
LayerClassifier().classify(list(builder._store.all_nodes()))
386-
387381
# ----------------------------------------------------------
388382
# 6. Run cross-file linkers
389383
# ----------------------------------------------------------
390384
_report("🔗 Linking cross-file relationships…")
391385
builder.run_linkers()
392386

387+
# ----------------------------------------------------------
388+
# 6b. Classify layers (after linkers so all nodes are covered)
389+
# ----------------------------------------------------------
390+
from code_intelligence.classifiers.layer_classifier import LayerClassifier
391+
LayerClassifier().classify_store(builder._store)
392+
393393
# ----------------------------------------------------------
394394
# 7. Record run and return result
395395
# ----------------------------------------------------------

src/code_intelligence/classifiers/layer_classifier.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from __future__ import annotations
44

55
import re
6-
from typing import Sequence
6+
from typing import Any, Sequence
77

8-
from code_intelligence.models.graph import GraphNode, NodeKind
8+
from code_intelligence.models.graph import GraphNode, NodeKind, SourceLocation
99

1010
_FRONTEND_NODE_KINDS = {NodeKind.COMPONENT, NodeKind.HOOK}
1111
_BACKEND_NODE_KINDS = {NodeKind.GUARD, NodeKind.MIDDLEWARE, NodeKind.ENDPOINT, NodeKind.REPOSITORY, NodeKind.DATABASE_CONNECTION, NodeKind.QUERY}
@@ -34,6 +34,27 @@ def classify(self, nodes: Sequence[GraphNode]) -> None:
3434
for node in nodes:
3535
node.properties["layer"] = self._classify_one(node)
3636

37+
def classify_store(self, store: Any) -> None:
38+
"""Classify nodes directly in a GraphStore, updating networkx data in-place."""
39+
for node_id, data in store.graph.nodes(data=True):
40+
if "kind" not in data:
41+
continue
42+
# Build a lightweight GraphNode for classification
43+
loc = data.get("location")
44+
if isinstance(loc, dict):
45+
loc = SourceLocation(**loc)
46+
node = GraphNode(
47+
id=data.get("id", node_id),
48+
kind=NodeKind(data["kind"]),
49+
label=data.get("label", ""),
50+
location=loc,
51+
properties=data.get("properties", {}),
52+
)
53+
layer = self._classify_one(node)
54+
# Update the networkx data dict directly
55+
props = data.setdefault("properties", {})
56+
props["layer"] = layer
57+
3758
def _classify_one(self, node: GraphNode) -> str:
3859
if node.kind in _FRONTEND_NODE_KINDS:
3960
return "frontend"

0 commit comments

Comments
 (0)