tldrgraph 0.1.0__py3-none-any.whl

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.
tldrgraph/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ """
2
+ TLDRGraph: Token-Efficient Hybrid Code Flow & Semantic Navigation Engine (Dynamic Multi-Layer)
3
+ """
4
+
5
+ __version__ = "0.1.0"
@@ -0,0 +1,75 @@
1
+ """
2
+ Layer Classification Engine for TLDRGraph.
3
+
4
+ Layer identity and rule sets live in :mod:`.layers`.
5
+ This module evaluates rules over the active registry in rank order: first match
6
+ wins. If no rule matches across any layer, the registry's designated utility
7
+ bucket is assigned with default provenance.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from enum import Enum
13
+ from typing import Any, Dict, Mapping, Optional, Tuple
14
+
15
+ from .layers import (
16
+ DEFAULT_LAYERS,
17
+ LAYER_API,
18
+ LAYER_ASYNC,
19
+ LAYER_DATA,
20
+ LAYER_DEVOPS,
21
+ LAYER_SERVICE,
22
+ LAYER_UI,
23
+ LAYER_UTILITY,
24
+ Layer,
25
+ get_registry,
26
+ )
27
+
28
+ #: Display names of the built-in default set, by id. Used only to seed the
29
+ #: legacy ``LayerType`` enum below -- logic must not read this.
30
+ _DEFAULT_NAMES = {layer.id: layer.name for layer in DEFAULT_LAYERS}
31
+
32
+
33
+ class LayerType(str, Enum):
34
+ """
35
+ Deprecated compatibility shim over the *default* layer set.
36
+
37
+ Frozen at import time, so it cannot follow a swapped registry. Kept only so
38
+ existing callers and tests that hold ``LayerType.X.value`` keep working; new
39
+ code must use :mod:`tldrgraph.layers` ids instead.
40
+ """
41
+
42
+ LAYER_1_UI = _DEFAULT_NAMES[LAYER_UI]
43
+ LAYER_2_API = _DEFAULT_NAMES[LAYER_API]
44
+ LAYER_3_SERVICE = _DEFAULT_NAMES[LAYER_SERVICE]
45
+ LAYER_4_DATA = _DEFAULT_NAMES[LAYER_DATA]
46
+ LAYER_5_ASYNC = _DEFAULT_NAMES[LAYER_ASYNC]
47
+ LAYER_6_DEVOPS = _DEFAULT_NAMES[LAYER_DEVOPS]
48
+ UNKNOWN = _DEFAULT_NAMES[LAYER_UTILITY]
49
+
50
+
51
+ def classify_node_with_source(node_id: str, node_data: Mapping[str, Any]) -> Tuple[Layer, str]:
52
+ """
53
+ Classifies a node and returns (layer, layer_source).
54
+
55
+ layer_source is "rule" when matched by a rule in the active registry, or
56
+ "default" when fallen back to the utility bucket.
57
+ """
58
+ registry = get_registry()
59
+ for layer in registry.ordered():
60
+ for rule in layer.rules:
61
+ if rule.matches(node_id, node_data):
62
+ return layer, "rule"
63
+
64
+ return registry.utility, "default"
65
+
66
+
67
+ def classify_node(node_id: str, node_data: Dict[str, Any]) -> Layer:
68
+ """
69
+ Classifies an AST / graph node into one of the architectural layers.
70
+
71
+ Evaluates rules across the active registry in rank order: first match wins.
72
+ Returns the :class:`~tldrgraph.layers.Layer` from the active registry.
73
+ """
74
+ layer, _ = classify_node_with_source(node_id, node_data)
75
+ return layer