java-codebase-rag 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.
java_ontology.py ADDED
@@ -0,0 +1,446 @@
1
+ """Shared valid role and capability label sets for Java indexers and MCP.
2
+
3
+ Used by `ast_java` inference, brownfield config validation in `graph_enrich`,
4
+ and resolver steps for `@CodebaseRole` / `@CodebaseCapability`."""
5
+ from __future__ import annotations
6
+
7
+ from dataclasses import dataclass
8
+ from typing import Literal
9
+
10
+ from ast_java import (
11
+ ROLE_ANNOTATIONS,
12
+ _INJECTED_TYPES_TO_CAPABILITY,
13
+ _METHOD_ANN_TO_CAPABILITY,
14
+ _SUPERTYPE_TO_CAPABILITY,
15
+ _TYPE_ANN_TO_CAPABILITY,
16
+ )
17
+
18
+ # Roles: Spring stereotype values plus DTO from `infer_role_for_type`.
19
+ VALID_ROLES: frozenset[str] = frozenset((*ROLE_ANNOTATIONS.values(), "DTO"))
20
+
21
+ VALID_CAPABILITIES: frozenset[str] = frozenset(
22
+ {
23
+ *_METHOD_ANN_TO_CAPABILITY.values(),
24
+ *_TYPE_ANN_TO_CAPABILITY.values(),
25
+ *_INJECTED_TYPES_TO_CAPABILITY.values(),
26
+ *_SUPERTYPE_TO_CAPABILITY.values(),
27
+ }
28
+ )
29
+
30
+ VALID_ROUTE_FRAMEWORKS: frozenset[str] = frozenset((
31
+ "spring_mvc",
32
+ "webflux",
33
+ ))
34
+
35
+ VALID_ROUTE_KINDS: frozenset[str] = frozenset((
36
+ "http_endpoint",
37
+ "http_consumer",
38
+ "kafka_topic",
39
+ "rabbit_queue",
40
+ "jms_destination",
41
+ "stream_binding",
42
+ ))
43
+
44
+ VALID_CLIENT_KINDS: frozenset[str] = frozenset((
45
+ "feign_method",
46
+ "rest_template",
47
+ "web_client",
48
+ ))
49
+
50
+ VALID_PRODUCER_KINDS: frozenset[str] = frozenset((
51
+ "kafka_send",
52
+ "stream_bridge_send",
53
+ ))
54
+
55
+ VALID_HTTP_CALL_STRATEGIES: frozenset[str] = frozenset((
56
+ "feign_method",
57
+ "rest_template",
58
+ "web_client",
59
+ "unresolved",
60
+ ))
61
+
62
+ VALID_ASYNC_CALL_STRATEGIES: frozenset[str] = frozenset((
63
+ "kafka_template",
64
+ "stream_bridge",
65
+ "rabbit_template",
66
+ "jms_template",
67
+ "unresolved",
68
+ ))
69
+
70
+ VALID_HTTP_CALL_MATCHES: frozenset[str] = frozenset((
71
+ "cross_service",
72
+ "intra_service",
73
+ "ambiguous",
74
+ "phantom",
75
+ "unresolved",
76
+ ))
77
+
78
+ VALID_RESOLVE_REASONS: frozenset[str] = frozenset((
79
+ "exact_id",
80
+ "exact_fqn",
81
+ "fqn_suffix",
82
+ "short_name",
83
+ "route_template",
84
+ "route_method_path",
85
+ "client_target",
86
+ "client_target_path",
87
+ "producer_topic",
88
+ "producer_topic_prefix",
89
+ ))
90
+
91
+ # Brownfield / fallback edge resolution strategies (hints v2 neighbors fuzzy signal).
92
+ # ``phantom`` / ``chained_receiver`` are not CALLS edge strategies after PR-3 (receiver
93
+ # failures live on ``UnresolvedCallSite``); they remain on HTTP/ASYNC match literals only.
94
+ FUZZY_STRATEGY_SET: frozenset[str] = frozenset({
95
+ "layer_c_source",
96
+ "layer_b_fqn",
97
+ "overload_ambiguous",
98
+ "implicit_super",
99
+ })
100
+
101
+ VALID_UNRESOLVED_CALL_REASONS: frozenset[str] = frozenset({
102
+ "phantom_unresolved_receiver",
103
+ "chained_receiver",
104
+ })
105
+
106
+ # Union of fuzzy + non-fuzzy resolver strategies that may appear on graph edges
107
+ # carrying a `strategy` column (brownfield layers, codebase stubs, call-graph tiers,
108
+ # HTTP/async dispatch literals). Used by `EdgeSpec.brownfield_resolver_sourced`.
109
+ BROWNFIELD_RESOLVER_STRATEGY_SET: frozenset[str] = frozenset({
110
+ *FUZZY_STRATEGY_SET,
111
+ # Receiver-tier / HTTP match literals — not CALLS edge strategies after PR-3 UCS facet.
112
+ "phantom",
113
+ "chained_receiver",
114
+ "layer_b_ann",
115
+ "layer_a_meta",
116
+ "codebase_route",
117
+ "codebase_client",
118
+ "codebase_producer",
119
+ "annotation",
120
+ "spel",
121
+ "constant_ref",
122
+ *VALID_HTTP_CALL_STRATEGIES,
123
+ *VALID_ASYNC_CALL_STRATEGIES,
124
+ *VALID_CLIENT_KINDS,
125
+ *VALID_PRODUCER_KINDS,
126
+ "import_map",
127
+ "static_import",
128
+ "static_import_wildcard",
129
+ "constructor",
130
+ "method_reference",
131
+ "this_super",
132
+ "unique_type_name",
133
+ "suffix",
134
+ "same_module",
135
+ })
136
+
137
+ NodeKind = Literal["Symbol", "Route", "Client", "Producer"]
138
+ Cardinality = Literal["many_to_many", "many_to_one", "one_to_many", "one_to_one"]
139
+
140
+
141
+ @dataclass(frozen=True)
142
+ class EdgeAttr:
143
+ name: str
144
+ kuzu_type: str
145
+ purpose: str
146
+
147
+
148
+ @dataclass(frozen=True)
149
+ class EdgeSpec:
150
+ name: str
151
+ src: NodeKind
152
+ dst: NodeKind
153
+ cardinality: Cardinality
154
+ brownfield_resolver_sourced: bool
155
+ attrs: tuple[EdgeAttr, ...]
156
+ purpose: str
157
+ typical_traversals: dict[str, str]
158
+ member_only: bool = False
159
+
160
+
161
+ _SYMBOL_TYPE_TRAVERSAL = (
162
+ "neighbors(['{id}'],'out',['DECLARES']) "
163
+ "then neighbors(member_ids,'{direction}',['{edge}'])"
164
+ )
165
+
166
+ _COMPOSED_MEMBER_TYPE_TRAVERSAL = (
167
+ "neighbors(['{id}'],'out',['DECLARES.{edge}']) — or "
168
+ "neighbors(['{id}'],'out',['DECLARES']) then neighbors(member_ids,'{direction}',['{edge}'])"
169
+ )
170
+
171
+ EDGE_SCHEMA: dict[str, EdgeSpec] = {
172
+ "EXTENDS": EdgeSpec(
173
+ name="EXTENDS",
174
+ src="Symbol",
175
+ dst="Symbol",
176
+ cardinality="many_to_one",
177
+ brownfield_resolver_sourced=False,
178
+ attrs=(
179
+ EdgeAttr("dst_name", "STRING", "raw supertype name as written in source"),
180
+ EdgeAttr("dst_fqn", "STRING", "best-effort resolved FQN of the supertype"),
181
+ EdgeAttr("resolved", "BOOLEAN", "True iff dst_fqn was resolved to an in-graph Symbol"),
182
+ ),
183
+ purpose="class or interface direct supertype relation",
184
+ typical_traversals={
185
+ "type_subject": _SYMBOL_TYPE_TRAVERSAL.format(id="{id}", direction="{direction}", edge="EXTENDS"),
186
+ "member_subject": "neighbors(['{id}'],'out',['EXTENDS'])",
187
+ "alien_subject": "EXTENDS connects Symbol → Symbol; use a type or member Symbol id",
188
+ },
189
+ ),
190
+ "IMPLEMENTS": EdgeSpec(
191
+ name="IMPLEMENTS",
192
+ src="Symbol",
193
+ dst="Symbol",
194
+ cardinality="many_to_many",
195
+ brownfield_resolver_sourced=False,
196
+ attrs=(
197
+ EdgeAttr("dst_name", "STRING", "raw interface name as written in source"),
198
+ EdgeAttr("dst_fqn", "STRING", "best-effort resolved FQN of the interface"),
199
+ EdgeAttr("resolved", "BOOLEAN", "True iff dst_fqn was resolved to an in-graph Symbol"),
200
+ ),
201
+ purpose="class implements interface relation",
202
+ typical_traversals={
203
+ "type_subject": _SYMBOL_TYPE_TRAVERSAL.format(id="{id}", direction="{direction}", edge="IMPLEMENTS"),
204
+ "member_subject": "neighbors(['{id}'],'out',['IMPLEMENTS'])",
205
+ "alien_subject": "IMPLEMENTS connects Symbol → Symbol; use a type or member Symbol id",
206
+ },
207
+ ),
208
+ "INJECTS": EdgeSpec(
209
+ name="INJECTS",
210
+ src="Symbol",
211
+ dst="Symbol",
212
+ cardinality="many_to_many",
213
+ brownfield_resolver_sourced=False,
214
+ attrs=(
215
+ EdgeAttr("dst_name", "STRING", "raw injected type name as written in source"),
216
+ EdgeAttr("dst_fqn", "STRING", "best-effort resolved FQN of the injected type"),
217
+ EdgeAttr("resolved", "BOOLEAN", "True iff dst_fqn was resolved to an in-graph Symbol"),
218
+ EdgeAttr("mechanism", "STRING", "injection mechanism literal (constructor, field, setter, …)"),
219
+ EdgeAttr("annotation", "STRING", "injection annotation simple name when present"),
220
+ EdgeAttr("field_or_param", "STRING", "field or parameter name for the injection site"),
221
+ ),
222
+ purpose="dependency injection edge from declaring type to injected type",
223
+ typical_traversals={
224
+ "type_subject": _SYMBOL_TYPE_TRAVERSAL.format(id="{id}", direction="{direction}", edge="INJECTS"),
225
+ "member_subject": "neighbors(['{id}'],'in',['INJECTS'])",
226
+ "alien_subject": "INJECTS connects Symbol → Symbol; use a type Symbol id",
227
+ },
228
+ ),
229
+ "DECLARES": EdgeSpec(
230
+ name="DECLARES",
231
+ src="Symbol",
232
+ dst="Symbol",
233
+ cardinality="one_to_many",
234
+ brownfield_resolver_sourced=False,
235
+ attrs=(),
236
+ purpose="type declares member Symbol (method, constructor, nested type)",
237
+ typical_traversals={
238
+ "type_subject": "neighbors(['{id}'],'out',['DECLARES'])",
239
+ "member_subject": "neighbors(['{id}'],'in',['DECLARES'])",
240
+ "alien_subject": "DECLARES connects Symbol → Symbol; use a type Symbol id for outbound members",
241
+ },
242
+ ),
243
+ "OVERRIDES": EdgeSpec(
244
+ name="OVERRIDES",
245
+ src="Symbol",
246
+ dst="Symbol",
247
+ cardinality="many_to_one",
248
+ brownfield_resolver_sourced=False,
249
+ attrs=(),
250
+ purpose="subtype method overrides supertype declared method with matching signature",
251
+ member_only=True,
252
+ typical_traversals={
253
+ "type_subject": _SYMBOL_TYPE_TRAVERSAL.format(id="{id}", direction="{direction}", edge="OVERRIDES"),
254
+ "member_subject": "neighbors(['{id}'],'out',['OVERRIDES'])",
255
+ "alien_subject": "OVERRIDES connects method Symbol → method Symbol",
256
+ },
257
+ ),
258
+ "CALLS": EdgeSpec(
259
+ name="CALLS",
260
+ src="Symbol",
261
+ dst="Symbol",
262
+ cardinality="many_to_many",
263
+ brownfield_resolver_sourced=True,
264
+ attrs=(
265
+ EdgeAttr("call_site_line", "INT64", "source line of the call site"),
266
+ EdgeAttr("call_site_byte", "INT64", "source byte offset of the call site"),
267
+ EdgeAttr("arg_count", "INT64", "argument count at the call site (-1 for method references)"),
268
+ EdgeAttr("confidence", "DOUBLE", "resolver confidence in [0.0, 1.0]"),
269
+ EdgeAttr("strategy", "STRING", "call-graph resolution strategy literal"),
270
+ EdgeAttr("source", "STRING", "call-graph source tag"),
271
+ EdgeAttr("resolved", "BOOLEAN", "True iff callee Symbol was resolved in-graph"),
272
+ EdgeAttr(
273
+ "callee_declaring_role",
274
+ "STRING",
275
+ "role of the Symbol that declares the callee method",
276
+ ),
277
+ ),
278
+ purpose="intra-codebase method call from caller method to callee method",
279
+ member_only=True,
280
+ typical_traversals={
281
+ "type_subject": _SYMBOL_TYPE_TRAVERSAL.format(id="{id}", direction="{direction}", edge="CALLS"),
282
+ "member_subject": "neighbors(['{id}'],'out',['CALLS'])",
283
+ "alien_subject": "CALLS connects method Symbol → method Symbol",
284
+ },
285
+ ),
286
+ "EXPOSES": EdgeSpec(
287
+ name="EXPOSES",
288
+ src="Symbol",
289
+ dst="Route",
290
+ cardinality="one_to_one",
291
+ brownfield_resolver_sourced=True,
292
+ attrs=(
293
+ EdgeAttr("confidence", "DOUBLE", "route extraction confidence in [0.0, 1.0]"),
294
+ EdgeAttr("strategy", "STRING", "route resolution strategy literal"),
295
+ ),
296
+ purpose="declaring method exposes an inbound HTTP or messaging Route",
297
+ member_only=True,
298
+ typical_traversals={
299
+ "type_subject": _SYMBOL_TYPE_TRAVERSAL.format(id="{id}", direction="{direction}", edge="EXPOSES"),
300
+ "member_subject": "neighbors(['{id}'],'out',['EXPOSES'])",
301
+ "alien_subject": "EXPOSES connects method Symbol → Route; use a method Symbol id",
302
+ },
303
+ ),
304
+ "DECLARES_CLIENT": EdgeSpec(
305
+ name="DECLARES_CLIENT",
306
+ src="Symbol",
307
+ dst="Client",
308
+ cardinality="one_to_many",
309
+ brownfield_resolver_sourced=True,
310
+ attrs=(
311
+ EdgeAttr("confidence", "DOUBLE", "client declaration confidence in [0.0, 1.0]"),
312
+ EdgeAttr("strategy", "STRING", "client resolution strategy literal"),
313
+ ),
314
+ purpose="method declares an outbound HTTP client call site",
315
+ member_only=True,
316
+ typical_traversals={
317
+ "type_subject": _SYMBOL_TYPE_TRAVERSAL.format(
318
+ id="{id}", direction="{direction}", edge="DECLARES_CLIENT",
319
+ ),
320
+ "member_subject": "neighbors(['{id}'],'out',['DECLARES_CLIENT'])",
321
+ "alien_subject": "DECLARES_CLIENT connects method Symbol → Client",
322
+ },
323
+ ),
324
+ "DECLARES_PRODUCER": EdgeSpec(
325
+ name="DECLARES_PRODUCER",
326
+ src="Symbol",
327
+ dst="Producer",
328
+ cardinality="one_to_many",
329
+ brownfield_resolver_sourced=True,
330
+ attrs=(
331
+ EdgeAttr("confidence", "DOUBLE", "producer declaration confidence in [0.0, 1.0]"),
332
+ EdgeAttr("strategy", "STRING", "producer resolution strategy literal"),
333
+ ),
334
+ purpose="method declares an outbound async producer call site",
335
+ member_only=True,
336
+ typical_traversals={
337
+ "type_subject": _SYMBOL_TYPE_TRAVERSAL.format(
338
+ id="{id}", direction="{direction}", edge="DECLARES_PRODUCER",
339
+ ),
340
+ "member_subject": "neighbors(['{id}'],'out',['DECLARES_PRODUCER'])",
341
+ "alien_subject": "DECLARES_PRODUCER connects method Symbol → Producer",
342
+ },
343
+ ),
344
+ "HTTP_CALLS": EdgeSpec(
345
+ name="HTTP_CALLS",
346
+ src="Client",
347
+ dst="Route",
348
+ cardinality="many_to_many",
349
+ brownfield_resolver_sourced=True,
350
+ attrs=(
351
+ EdgeAttr("confidence", "DOUBLE", "pass6 match confidence in [0.0, 1.0]"),
352
+ EdgeAttr("strategy", "STRING", "HTTP call resolution strategy literal"),
353
+ EdgeAttr("method_call", "STRING", "HTTP method of the call site"),
354
+ EdgeAttr("raw_uri", "STRING", "uninterpolated URI template from the call site"),
355
+ EdgeAttr("match", "STRING", "cross_service|intra_service|ambiguous|phantom|unresolved"),
356
+ ),
357
+ purpose="resolved HTTP call from a declared Client to a target route",
358
+ typical_traversals={
359
+ "type_subject": (
360
+ "neighbors(['{id}'],'out',['DECLARES']) "
361
+ "then neighbors(member_ids,'out',['DECLARES_CLIENT']) "
362
+ "then neighbors(client_ids,'out',['HTTP_CALLS'])"
363
+ ),
364
+ "member_subject": (
365
+ "neighbors(['{id}'],'out',['DECLARES_CLIENT']) "
366
+ "then neighbors(client_ids,'out',['HTTP_CALLS'])"
367
+ ),
368
+ "route_subject": (
369
+ "neighbors(['{id}'],'in',['HTTP_CALLS']) "
370
+ "then neighbors(client_ids,'in',['DECLARES_CLIENT']) for declaring method"
371
+ ),
372
+ "alien_subject": (
373
+ "HTTP_CALLS connects Client→Route; use DECLARES_CLIENT from a method Symbol, "
374
+ "or neighbors(client_id,'out',['HTTP_CALLS']) from a Client id"
375
+ ),
376
+ },
377
+ ),
378
+ "ASYNC_CALLS": EdgeSpec(
379
+ name="ASYNC_CALLS",
380
+ src="Producer",
381
+ dst="Route",
382
+ cardinality="many_to_many",
383
+ brownfield_resolver_sourced=True,
384
+ attrs=(
385
+ EdgeAttr("confidence", "DOUBLE", "pass6 match confidence in [0.0, 1.0]"),
386
+ EdgeAttr("strategy", "STRING", "async call resolution strategy literal"),
387
+ EdgeAttr("direction", "STRING", "produce|consume async direction literal"),
388
+ EdgeAttr("raw_topic", "STRING", "uninterpolated topic template from the call site"),
389
+ EdgeAttr("match", "STRING", "cross_service|intra_service|ambiguous|phantom|unresolved"),
390
+ ),
391
+ purpose="resolved async call from a declared Producer to a topic route",
392
+ typical_traversals={
393
+ "type_subject": (
394
+ "neighbors(['{id}'],'out',['DECLARES']) "
395
+ "then neighbors(member_ids,'out',['DECLARES_PRODUCER']) "
396
+ "then neighbors(producer_ids,'out',['ASYNC_CALLS'])"
397
+ ),
398
+ "member_subject": (
399
+ "neighbors(['{id}'],'out',['DECLARES_PRODUCER']) "
400
+ "then neighbors(producer_ids,'out',['ASYNC_CALLS'])"
401
+ ),
402
+ "route_subject": (
403
+ "neighbors(['{id}'],'in',['ASYNC_CALLS']) "
404
+ "then neighbors(producer_ids,'in',['DECLARES_PRODUCER']) for declaring method"
405
+ ),
406
+ "alien_subject": (
407
+ "ASYNC_CALLS connects Producer→Route; use DECLARES_PRODUCER from a method Symbol, "
408
+ "or neighbors(producer_id,'out',['ASYNC_CALLS']) from a Producer id"
409
+ ),
410
+ },
411
+ ),
412
+ }
413
+
414
+ ResolveReason = Literal[
415
+ "exact_id",
416
+ "exact_fqn",
417
+ "fqn_suffix",
418
+ "short_name",
419
+ "route_template",
420
+ "route_method_path",
421
+ "client_target",
422
+ "client_target_path",
423
+ "producer_topic",
424
+ "producer_topic_prefix",
425
+ ]
426
+
427
+ __all__ = [
428
+ "VALID_ROLES",
429
+ "VALID_CAPABILITIES",
430
+ "VALID_ROUTE_FRAMEWORKS",
431
+ "VALID_ROUTE_KINDS",
432
+ "VALID_CLIENT_KINDS",
433
+ "VALID_PRODUCER_KINDS",
434
+ "VALID_HTTP_CALL_STRATEGIES",
435
+ "VALID_ASYNC_CALL_STRATEGIES",
436
+ "VALID_HTTP_CALL_MATCHES",
437
+ "VALID_RESOLVE_REASONS",
438
+ "FUZZY_STRATEGY_SET",
439
+ "BROWNFIELD_RESOLVER_STRATEGY_SET",
440
+ "NodeKind",
441
+ "Cardinality",
442
+ "EdgeAttr",
443
+ "EdgeSpec",
444
+ "EDGE_SCHEMA",
445
+ "ResolveReason",
446
+ ]