sourcecode 2.3.0__py3-none-any.whl → 2.5.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.
- sourcecode/__init__.py +1 -1
- sourcecode/archetype.py +46 -0
- sourcecode/cli.py +491 -4
- sourcecode/context_cache.py +637 -0
- sourcecode/context_graph.py +32 -24
- sourcecode/explain.py +24 -0
- sourcecode/repository_ir.py +1 -1
- sourcecode/retrieval/__init__.py +192 -0
- sourcecode/retrieval/context.py +241 -0
- sourcecode/retrieval/errors.py +41 -0
- sourcecode/retrieval/executor.py +51 -0
- sourcecode/retrieval/planner.py +297 -0
- sourcecode/retrieval/query.py +484 -0
- sourcecode/retrieval/request.py +94 -0
- sourcecode/retrieval/resolution.py +135 -0
- sourcecode/retrieval/result.py +144 -0
- sourcecode/retrieval/retriever.py +62 -0
- sourcecode/retrieval/runtime.py +259 -0
- sourcecode/retrieval/steps.py +242 -0
- sourcecode/retrieval/steps_endpoint.py +311 -0
- sourcecode/retrieval/steps_graph.py +248 -0
- sourcecode/retrieval/steps_impact.py +293 -0
- sourcecode/retrieval/steps_intf.py +247 -0
- sourcecode/retrieval/steps_struct.py +338 -0
- sourcecode/retrieval/steps_txsec.py +351 -0
- sourcecode/security_config.py +4 -4
- {sourcecode-2.3.0.dist-info → sourcecode-2.5.0.dist-info}/METADATA +4 -4
- {sourcecode-2.3.0.dist-info → sourcecode-2.5.0.dist-info}/RECORD +31 -12
- {sourcecode-2.3.0.dist-info → sourcecode-2.5.0.dist-info}/WHEEL +0 -0
- {sourcecode-2.3.0.dist-info → sourcecode-2.5.0.dist-info}/entry_points.txt +0 -0
- {sourcecode-2.3.0.dist-info → sourcecode-2.5.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
"""KnowledgeQuery — the declarative, serializable plan and its step algebra
|
|
2
|
+
(design §4.4, §5.4).
|
|
3
|
+
|
|
4
|
+
A `KnowledgeQuery` is a side-effect-free VALUE describing *what* to retrieve, never *how
|
|
5
|
+
the result is computed*. Steps are the closed vocabulary of retrieval operations; each is
|
|
6
|
+
pure data (a `kind` + parameters) carrying **no execution logic** — all execution logic
|
|
7
|
+
lives in the Query Plan Runtime's step handlers. Because a step is data, a plan is:
|
|
8
|
+
|
|
9
|
+
* **serializable** — `to_dict()` / `from_dict()` round-trip (register/log/replay);
|
|
10
|
+
* **inspectable** — `describe()` lists the step names without running anything;
|
|
11
|
+
* **CLI-independent** — the same plan value is submitted from CLI, MCP, IDE, API.
|
|
12
|
+
|
|
13
|
+
Adding an intent is declaring a new plan over these steps; the Runtime is untouched.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from dataclasses import dataclass
|
|
18
|
+
from typing import Any, ClassVar
|
|
19
|
+
|
|
20
|
+
from sourcecode.retrieval.request import RetrievalIntent
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Step:
|
|
24
|
+
"""Marker base for a declarative retrieval operation. Frozen data, no behaviour.
|
|
25
|
+
|
|
26
|
+
`kind` is the stable, serializable discriminator the Runtime dispatches on; it is
|
|
27
|
+
decoupled from the Python class name so the wire form survives refactors."""
|
|
28
|
+
|
|
29
|
+
__slots__ = ()
|
|
30
|
+
kind: ClassVar[str] = "step"
|
|
31
|
+
|
|
32
|
+
def params(self) -> dict[str, Any]:
|
|
33
|
+
"""The step's parameters as a plain, serializable dict."""
|
|
34
|
+
return {}
|
|
35
|
+
|
|
36
|
+
def to_dict(self) -> dict[str, Any]:
|
|
37
|
+
return {"kind": self.kind, "params": self.params()}
|
|
38
|
+
|
|
39
|
+
@classmethod
|
|
40
|
+
def from_params(cls, params: dict[str, Any]) -> "Step":
|
|
41
|
+
"""Rebuild a step from its serialized params. Overridden by parameterized steps."""
|
|
42
|
+
return cls()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass(frozen=True)
|
|
46
|
+
class Characterize(Step):
|
|
47
|
+
"""Reuse `ArchetypeClassifier`; select one archetype `dimension`
|
|
48
|
+
(``software_archetype`` | ``architectural_style`` | …). Single responsibility:
|
|
49
|
+
obtain the dimension's scored candidates + evidence + graph metrics."""
|
|
50
|
+
|
|
51
|
+
kind: ClassVar[str] = "characterize"
|
|
52
|
+
dimension: str
|
|
53
|
+
|
|
54
|
+
def params(self) -> dict[str, Any]:
|
|
55
|
+
return {"dimension": self.dimension}
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def from_params(cls, params: dict[str, Any]) -> "Characterize":
|
|
59
|
+
return cls(dimension=params["dimension"])
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass(frozen=True)
|
|
63
|
+
class RankByScore(Step):
|
|
64
|
+
"""Order the selected candidates by their EXISTING engine score (no new scoring).
|
|
65
|
+
Single responsibility: ranking."""
|
|
66
|
+
|
|
67
|
+
kind: ClassVar[str] = "rank_by_score"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclass(frozen=True)
|
|
71
|
+
class CollectEvidence(Step):
|
|
72
|
+
"""Gather the winning candidate's evidence + graph-topology observations into typed
|
|
73
|
+
structures. Single responsibility: evidence/observation assembly."""
|
|
74
|
+
|
|
75
|
+
kind: ClassVar[str] = "collect_evidence"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@dataclass(frozen=True)
|
|
79
|
+
class BuildResult(Step):
|
|
80
|
+
"""Assemble the final typed `KnowledgeResult` from the shared context. A plan MUST
|
|
81
|
+
terminate in this step. Single responsibility: result construction. GENERIC — reused
|
|
82
|
+
by every pack; it reads only generic result slots, never a pack's internals."""
|
|
83
|
+
|
|
84
|
+
kind: ClassVar[str] = "build_result"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# ── IMPACT pack steps (Fase 5) ───────────────────────────────────────────────────
|
|
88
|
+
# All reuse existing engines; none extracts or re-derives knowledge.
|
|
89
|
+
@dataclass(frozen=True)
|
|
90
|
+
class ResolveTarget(Step):
|
|
91
|
+
"""Bind the request's symbol/file anchor to the impact target token. Single
|
|
92
|
+
responsibility: pick the target from the resolved anchors."""
|
|
93
|
+
|
|
94
|
+
kind: ClassVar[str] = "resolve_target"
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@dataclass(frozen=True)
|
|
98
|
+
class ComputeBlastRadius(Step):
|
|
99
|
+
"""Reuse `repository_ir.compute_blast_radius` over the acquired repo IR. Produces the
|
|
100
|
+
single blast-radius dict every projection step reads. Single responsibility: run the
|
|
101
|
+
impact engine once."""
|
|
102
|
+
|
|
103
|
+
kind: ClassVar[str] = "compute_blast_radius"
|
|
104
|
+
max_depth: int = 4
|
|
105
|
+
|
|
106
|
+
def params(self) -> dict[str, Any]:
|
|
107
|
+
return {"max_depth": self.max_depth}
|
|
108
|
+
|
|
109
|
+
@classmethod
|
|
110
|
+
def from_params(cls, params: dict[str, Any]) -> "ComputeBlastRadius":
|
|
111
|
+
return cls(max_depth=int(params.get("max_depth", 4)))
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@dataclass(frozen=True)
|
|
115
|
+
class ResolveDependents(Step):
|
|
116
|
+
"""Project direct + indirect callers from the blast dict into entities."""
|
|
117
|
+
|
|
118
|
+
kind: ClassVar[str] = "resolve_dependents"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@dataclass(frozen=True)
|
|
122
|
+
class ResolveEndpoints(Step):
|
|
123
|
+
"""Project affected endpoints from the blast dict into entities."""
|
|
124
|
+
|
|
125
|
+
kind: ClassVar[str] = "resolve_endpoints"
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@dataclass(frozen=True)
|
|
129
|
+
class ResolveIntegrations(Step):
|
|
130
|
+
"""Reuse `SemanticIntegrationEngine`; keep integrations whose owner is in the blast
|
|
131
|
+
cone. Single responsibility: scope integrations to the impact."""
|
|
132
|
+
|
|
133
|
+
kind: ClassVar[str] = "resolve_integrations"
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
@dataclass(frozen=True)
|
|
137
|
+
class ResolveTransactions(Step):
|
|
138
|
+
"""Project transactional boundaries touched from the blast dict into entities."""
|
|
139
|
+
|
|
140
|
+
kind: ClassVar[str] = "resolve_transactions"
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
@dataclass(frozen=True)
|
|
144
|
+
class ResolveModules(Step):
|
|
145
|
+
"""Project cross-module impact from the blast dict into entities."""
|
|
146
|
+
|
|
147
|
+
kind: ClassVar[str] = "resolve_modules"
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@dataclass(frozen=True)
|
|
151
|
+
class RankByRisk(Step):
|
|
152
|
+
"""Order the impacted entities using the engine's OWN direct/indirect classification
|
|
153
|
+
(no new score). Single responsibility: deterministic risk ordering."""
|
|
154
|
+
|
|
155
|
+
kind: ClassVar[str] = "rank_by_risk"
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@dataclass(frozen=True)
|
|
159
|
+
class CollectImpactEvidence(Step):
|
|
160
|
+
"""Assemble confidence, explanation (engine text passthrough), provenance, and
|
|
161
|
+
risk observations from the blast dict. GENERIC across all impact intents."""
|
|
162
|
+
|
|
163
|
+
kind: ClassVar[str] = "collect_impact_evidence"
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
# ── TRANSACTIONS & SECURITY pack steps (Fase 6) ──────────────────────────────────
|
|
167
|
+
# All project outputs of existing engines (Spring tx/security/validation, endpoint
|
|
168
|
+
# model); none analyzes source or re-derives knowledge.
|
|
169
|
+
@dataclass(frozen=True)
|
|
170
|
+
class ResolveTransactionFlow(Step):
|
|
171
|
+
"""Project the @Transactional boundary index (`SpringSemanticModel.tx_index`) into
|
|
172
|
+
entities. Single responsibility: the transactional boundary map."""
|
|
173
|
+
|
|
174
|
+
kind: ClassVar[str] = "resolve_transaction_flow"
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
@dataclass(frozen=True)
|
|
178
|
+
class ResolveTransactionEntrypoints(Step):
|
|
179
|
+
"""Project the transactional boundaries that sit at the API surface (enclosing class
|
|
180
|
+
is a controller). Reuses tx_index × endpoint model."""
|
|
181
|
+
|
|
182
|
+
kind: ClassVar[str] = "resolve_transaction_entrypoints"
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@dataclass(frozen=True)
|
|
186
|
+
class ResolvePropagation(Step):
|
|
187
|
+
"""Project boundaries by propagation + the propagation-risk tx audit findings
|
|
188
|
+
(TX-002/003/004). Reuses tx_index + `run_tx_audit`."""
|
|
189
|
+
|
|
190
|
+
kind: ClassVar[str] = "resolve_propagation"
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
@dataclass(frozen=True)
|
|
194
|
+
class ResolveSecuritySurface(Step):
|
|
195
|
+
"""Project the security audit findings (`run_security_audit`) into entities."""
|
|
196
|
+
|
|
197
|
+
kind: ClassVar[str] = "resolve_security_surface"
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
@dataclass(frozen=True)
|
|
201
|
+
class ResolveSecurityChain(Step):
|
|
202
|
+
"""Project the security findings scoped to a target (its symbol / related symbols /
|
|
203
|
+
enclosing class). Reuses `run_security_audit`."""
|
|
204
|
+
|
|
205
|
+
kind: ClassVar[str] = "resolve_security_chain"
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
@dataclass(frozen=True)
|
|
209
|
+
class ResolveValidationPoints(Step):
|
|
210
|
+
"""Project the request-body validation surface (`build_validation_surface`)."""
|
|
211
|
+
|
|
212
|
+
kind: ClassVar[str] = "resolve_validation_points"
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
@dataclass(frozen=True)
|
|
216
|
+
class RankByCriticality(Step):
|
|
217
|
+
"""Order entities by the engines' OWN severity + confidence (no new score). Single
|
|
218
|
+
responsibility: deterministic criticality ordering. GENERIC across tx/security."""
|
|
219
|
+
|
|
220
|
+
kind: ClassVar[str] = "rank_by_criticality"
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
@dataclass(frozen=True)
|
|
224
|
+
class CollectSecurityEvidence(Step):
|
|
225
|
+
"""Assemble confidence, provenance, and observations from the domain result (evidence
|
|
226
|
+
rows are attached by the resolve steps). GENERIC across all tx/security intents."""
|
|
227
|
+
|
|
228
|
+
kind: ClassVar[str] = "collect_security_evidence"
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
# ── INTERFACES & INTEGRATIONS pack steps (Fase 7) ────────────────────────────────
|
|
232
|
+
# All project already-indexed knowledge (endpoint model, integration engine, event
|
|
233
|
+
# graph); none analyzes source or re-derives knowledge. Whole-repo inventories.
|
|
234
|
+
@dataclass(frozen=True)
|
|
235
|
+
class ResolveEndpointInventory(Step):
|
|
236
|
+
"""Project the whole endpoint model (`SpringSemanticModel.endpoint_index`) into
|
|
237
|
+
entities. Single responsibility: the repository's HTTP surface."""
|
|
238
|
+
|
|
239
|
+
kind: ClassVar[str] = "resolve_endpoint_inventory"
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
@dataclass(frozen=True)
|
|
243
|
+
class ResolveIntegrationInventory(Step):
|
|
244
|
+
"""Reuse `SemanticIntegrationEngine`; project EVERY detected integration (no cone
|
|
245
|
+
filter — the whole-repo counterpart of the impact pack's ResolveIntegrations)."""
|
|
246
|
+
|
|
247
|
+
kind: ClassVar[str] = "resolve_integration_inventory"
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
@dataclass(frozen=True)
|
|
251
|
+
class ResolveEventTopology(Step):
|
|
252
|
+
"""Project the Spring event graph (`SpringSemanticModel.event_graph`): one entity per
|
|
253
|
+
event type with its publishers and listeners. Single responsibility: event topology."""
|
|
254
|
+
|
|
255
|
+
kind: ClassVar[str] = "resolve_event_topology"
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
@dataclass(frozen=True)
|
|
259
|
+
class CollectInterfaceEvidence(Step):
|
|
260
|
+
"""Assemble confidence, provenance, and observations from the resolve step's output
|
|
261
|
+
(evidence rows are attached by the resolve steps). GENERIC across the interfaces/
|
|
262
|
+
integrations pack."""
|
|
263
|
+
|
|
264
|
+
kind: ClassVar[str] = "collect_interface_evidence"
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
# ── SUBSYSTEMS & DEPENDENCIES pack steps (Fase 8) ────────────────────────────────
|
|
268
|
+
# All project already-built knowledge (the repo_ir subsystem partition, the module
|
|
269
|
+
# graph); none analyzes source or re-derives knowledge.
|
|
270
|
+
@dataclass(frozen=True)
|
|
271
|
+
class ResolveScope(Step):
|
|
272
|
+
"""Bind the request's subsystem/module/package anchor to a scope token. Single
|
|
273
|
+
responsibility: pick the scope. Shared by the anchored structure intents."""
|
|
274
|
+
|
|
275
|
+
kind: ClassVar[str] = "resolve_scope"
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
@dataclass(frozen=True)
|
|
279
|
+
class ResolveSubsystemInventory(Step):
|
|
280
|
+
"""Project the repo_ir subsystem partition into entities. Single responsibility: the
|
|
281
|
+
repository's subsystem map."""
|
|
282
|
+
|
|
283
|
+
kind: ClassVar[str] = "resolve_subsystem_inventory"
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
@dataclass(frozen=True)
|
|
287
|
+
class ResolveSubsystemMembers(Step):
|
|
288
|
+
"""Project the member symbols of the scoped subsystem. Reuses the repo_ir partition."""
|
|
289
|
+
|
|
290
|
+
kind: ClassVar[str] = "resolve_subsystem_members"
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
@dataclass(frozen=True)
|
|
294
|
+
class ResolveModuleDependents(Step):
|
|
295
|
+
"""Project modules that depend ON the scope (reverse module-graph edges)."""
|
|
296
|
+
|
|
297
|
+
kind: ClassVar[str] = "resolve_module_dependents"
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
@dataclass(frozen=True)
|
|
301
|
+
class ResolveModuleDependencies(Step):
|
|
302
|
+
"""Project modules the scope DEPENDS ON (forward module-graph edges)."""
|
|
303
|
+
|
|
304
|
+
kind: ClassVar[str] = "resolve_module_dependencies"
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
@dataclass(frozen=True)
|
|
308
|
+
class ResolveTypeDependents(Step):
|
|
309
|
+
"""Project the type-level dependents of a target symbol from the repo_ir reverse graph
|
|
310
|
+
(imports / implements / injects / contained_in edges). Reuses the impact pack's
|
|
311
|
+
ResolveTarget to bind the symbol."""
|
|
312
|
+
|
|
313
|
+
kind: ClassVar[str] = "resolve_type_dependents"
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
@dataclass(frozen=True)
|
|
317
|
+
class CollectStructureEvidence(Step):
|
|
318
|
+
"""Assemble confidence, provenance, and explanation from the resolve step's output.
|
|
319
|
+
GENERIC across the subsystems/dependencies pack."""
|
|
320
|
+
|
|
321
|
+
kind: ClassVar[str] = "collect_structure_evidence"
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
# ── ENDPOINT & CALL deep-dive pack steps (Fase 10) ───────────────────────────────
|
|
325
|
+
# All project already-built knowledge (validation surface, endpoint model, security
|
|
326
|
+
# audit, call adjacency), scoped to an anchor; none analyzes source or re-derives.
|
|
327
|
+
@dataclass(frozen=True)
|
|
328
|
+
class ResolveEndpointRef(Step):
|
|
329
|
+
"""Bind the request's endpoint/path/symbol anchor to a reference token. Shared head of
|
|
330
|
+
the endpoint-scoped intents."""
|
|
331
|
+
|
|
332
|
+
kind: ClassVar[str] = "resolve_endpoint_ref"
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
@dataclass(frozen=True)
|
|
336
|
+
class ResolveEndpointContract(Step):
|
|
337
|
+
"""Project the request/validation contract of the referenced endpoint(s) from
|
|
338
|
+
`build_validation_surface`. Single responsibility: one endpoint's contract."""
|
|
339
|
+
|
|
340
|
+
kind: ClassVar[str] = "resolve_endpoint_contract"
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
@dataclass(frozen=True)
|
|
344
|
+
class ResolveEndpointSecurity(Step):
|
|
345
|
+
"""Project the effective security of the referenced endpoint(s): the endpoint model's
|
|
346
|
+
CanonicalSecurity + the security-audit findings on the handler."""
|
|
347
|
+
|
|
348
|
+
kind: ClassVar[str] = "resolve_endpoint_security"
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
@dataclass(frozen=True)
|
|
352
|
+
class ResolveCallNeighborhood(Step):
|
|
353
|
+
"""Project the forward callees + reverse callers of the target symbol from the call
|
|
354
|
+
adjacency. Reuses the impact pack's ResolveTarget to bind the symbol."""
|
|
355
|
+
|
|
356
|
+
kind: ClassVar[str] = "resolve_call_neighborhood"
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
@dataclass(frozen=True)
|
|
360
|
+
class CollectEndpointEvidence(Step):
|
|
361
|
+
"""Assemble confidence, provenance, and explanation from the resolve step's output.
|
|
362
|
+
GENERIC across the endpoint/call deep-dive pack."""
|
|
363
|
+
|
|
364
|
+
kind: ClassVar[str] = "collect_endpoint_evidence"
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
# ── GRAPH-analysis pack steps (Fase 11) ──────────────────────────────────────────
|
|
368
|
+
# All project already-built knowledge (the Spring call-chain engine, the tx index, the
|
|
369
|
+
# module graph summary); none analyzes source or re-derives knowledge.
|
|
370
|
+
@dataclass(frozen=True)
|
|
371
|
+
class ResolveExecutionPaths(Step):
|
|
372
|
+
"""Project the multi-hop caller reachability through the target symbol from
|
|
373
|
+
`run_impact_chain`. Reuses the impact pack's ResolveTarget to bind the symbol."""
|
|
374
|
+
|
|
375
|
+
kind: ClassVar[str] = "resolve_execution_paths"
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
@dataclass(frozen=True)
|
|
379
|
+
class ResolveTransactionsReaching(Step):
|
|
380
|
+
"""Project the @Transactional boundaries whose class can reach the target through the
|
|
381
|
+
call chain (run_impact_chain callers ∩ tx_index)."""
|
|
382
|
+
|
|
383
|
+
kind: ClassVar[str] = "resolve_transactions_reaching"
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
@dataclass(frozen=True)
|
|
387
|
+
class ResolveSubsystemCoupling(Step):
|
|
388
|
+
"""Project the repository's coupling structure: module-graph hubs / cycles / orphans +
|
|
389
|
+
the subsystem partition."""
|
|
390
|
+
|
|
391
|
+
kind: ClassVar[str] = "resolve_subsystem_coupling"
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
@dataclass(frozen=True)
|
|
395
|
+
class CollectGraphEvidence(Step):
|
|
396
|
+
"""Assemble confidence, provenance, and explanation from the resolve step's output.
|
|
397
|
+
GENERIC across the graph-analysis pack."""
|
|
398
|
+
|
|
399
|
+
kind: ClassVar[str] = "collect_graph_evidence"
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
# ── step (de)serialization registry ─────────────────────────────────────────────
|
|
403
|
+
# Maps the wire `kind` back to its Step class. New steps register here; the Runtime
|
|
404
|
+
# dispatches by `kind`, this table only reconstructs a plan from its serialized form.
|
|
405
|
+
_STEP_TYPES: dict[str, type[Step]] = {
|
|
406
|
+
Characterize.kind: Characterize,
|
|
407
|
+
RankByScore.kind: RankByScore,
|
|
408
|
+
CollectEvidence.kind: CollectEvidence,
|
|
409
|
+
BuildResult.kind: BuildResult,
|
|
410
|
+
# IMPACT pack
|
|
411
|
+
ResolveTarget.kind: ResolveTarget,
|
|
412
|
+
ComputeBlastRadius.kind: ComputeBlastRadius,
|
|
413
|
+
ResolveDependents.kind: ResolveDependents,
|
|
414
|
+
ResolveEndpoints.kind: ResolveEndpoints,
|
|
415
|
+
ResolveIntegrations.kind: ResolveIntegrations,
|
|
416
|
+
ResolveTransactions.kind: ResolveTransactions,
|
|
417
|
+
ResolveModules.kind: ResolveModules,
|
|
418
|
+
RankByRisk.kind: RankByRisk,
|
|
419
|
+
CollectImpactEvidence.kind: CollectImpactEvidence,
|
|
420
|
+
# TRANSACTIONS & SECURITY pack
|
|
421
|
+
ResolveTransactionFlow.kind: ResolveTransactionFlow,
|
|
422
|
+
ResolveTransactionEntrypoints.kind: ResolveTransactionEntrypoints,
|
|
423
|
+
ResolvePropagation.kind: ResolvePropagation,
|
|
424
|
+
ResolveSecuritySurface.kind: ResolveSecuritySurface,
|
|
425
|
+
ResolveSecurityChain.kind: ResolveSecurityChain,
|
|
426
|
+
ResolveValidationPoints.kind: ResolveValidationPoints,
|
|
427
|
+
RankByCriticality.kind: RankByCriticality,
|
|
428
|
+
CollectSecurityEvidence.kind: CollectSecurityEvidence,
|
|
429
|
+
# INTERFACES & INTEGRATIONS pack
|
|
430
|
+
ResolveEndpointInventory.kind: ResolveEndpointInventory,
|
|
431
|
+
ResolveIntegrationInventory.kind: ResolveIntegrationInventory,
|
|
432
|
+
ResolveEventTopology.kind: ResolveEventTopology,
|
|
433
|
+
CollectInterfaceEvidence.kind: CollectInterfaceEvidence,
|
|
434
|
+
# SUBSYSTEMS & DEPENDENCIES pack
|
|
435
|
+
ResolveScope.kind: ResolveScope,
|
|
436
|
+
ResolveSubsystemInventory.kind: ResolveSubsystemInventory,
|
|
437
|
+
ResolveSubsystemMembers.kind: ResolveSubsystemMembers,
|
|
438
|
+
ResolveModuleDependents.kind: ResolveModuleDependents,
|
|
439
|
+
ResolveModuleDependencies.kind: ResolveModuleDependencies,
|
|
440
|
+
ResolveTypeDependents.kind: ResolveTypeDependents,
|
|
441
|
+
CollectStructureEvidence.kind: CollectStructureEvidence,
|
|
442
|
+
# ENDPOINT & CALL deep-dive pack
|
|
443
|
+
ResolveEndpointRef.kind: ResolveEndpointRef,
|
|
444
|
+
ResolveEndpointContract.kind: ResolveEndpointContract,
|
|
445
|
+
ResolveEndpointSecurity.kind: ResolveEndpointSecurity,
|
|
446
|
+
ResolveCallNeighborhood.kind: ResolveCallNeighborhood,
|
|
447
|
+
CollectEndpointEvidence.kind: CollectEndpointEvidence,
|
|
448
|
+
# GRAPH-analysis pack
|
|
449
|
+
ResolveExecutionPaths.kind: ResolveExecutionPaths,
|
|
450
|
+
ResolveTransactionsReaching.kind: ResolveTransactionsReaching,
|
|
451
|
+
ResolveSubsystemCoupling.kind: ResolveSubsystemCoupling,
|
|
452
|
+
CollectGraphEvidence.kind: CollectGraphEvidence,
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
def step_from_dict(data: dict[str, Any]) -> Step:
|
|
457
|
+
kind = data.get("kind")
|
|
458
|
+
step_cls = _STEP_TYPES.get(kind)
|
|
459
|
+
if step_cls is None:
|
|
460
|
+
raise KeyError(f"unknown step kind {kind!r}")
|
|
461
|
+
return step_cls.from_params(data.get("params") or {})
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
@dataclass(frozen=True)
|
|
465
|
+
class KnowledgeQuery:
|
|
466
|
+
"""An ordered, declarative plan bound to the intent it serves. Holds no graph
|
|
467
|
+
handle and runs nothing."""
|
|
468
|
+
|
|
469
|
+
intent: RetrievalIntent
|
|
470
|
+
steps: tuple[Step, ...]
|
|
471
|
+
|
|
472
|
+
def describe(self) -> tuple[str, ...]:
|
|
473
|
+
"""The plan as an ordered tuple of step class names — printable/explainable
|
|
474
|
+
without executing anything."""
|
|
475
|
+
return tuple(type(s).__name__ for s in self.steps)
|
|
476
|
+
|
|
477
|
+
def to_dict(self) -> dict[str, Any]:
|
|
478
|
+
return {"intent": self.intent.value, "steps": [s.to_dict() for s in self.steps]}
|
|
479
|
+
|
|
480
|
+
@classmethod
|
|
481
|
+
def from_dict(cls, data: dict[str, Any]) -> "KnowledgeQuery":
|
|
482
|
+
intent = RetrievalIntent(data["intent"])
|
|
483
|
+
steps = tuple(step_from_dict(s) for s in data.get("steps", ()))
|
|
484
|
+
return cls(intent=intent, steps=steps)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Retrieval input model — the engine's typed contract (design §5.1, §9).
|
|
2
|
+
|
|
3
|
+
The engine's public input is a **typed** `RetrievalRequest`, never a natural-language
|
|
4
|
+
string. Natural language → typed intent is the consumer's job, strictly upstream and
|
|
5
|
+
outside this boundary. This is what keeps the engine deterministic, offline, and free of
|
|
6
|
+
every prohibition (no LLM, no embeddings, no text search).
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
from enum import Enum
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class RetrievalIntent(Enum):
|
|
15
|
+
"""The catalogue of typed questions the engine can answer.
|
|
16
|
+
|
|
17
|
+
An OPEN set. Phase 2 ships exactly one member; each future capability is a new
|
|
18
|
+
member here + a plan in `QueryPlanner` + (usually) a trivial resolver strategy —
|
|
19
|
+
the `KnowledgeExecutor` is unchanged when the plan composes existing steps.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
ARCHITECTURAL_CORE = "architectural-core"
|
|
23
|
+
ARCHITECTURAL_STYLE = "architectural-style"
|
|
24
|
+
DEPLOYMENT_SHAPE = "deployment-shape"
|
|
25
|
+
PRIMARY_INTERFACE = "primary-interface"
|
|
26
|
+
# IMPACT pack (Fase 5)
|
|
27
|
+
BLAST_RADIUS = "blast-radius"
|
|
28
|
+
AFFECTED_ENDPOINTS = "affected-endpoints"
|
|
29
|
+
AFFECTED_INTEGRATIONS = "affected-integrations"
|
|
30
|
+
TRANSACTION_BOUNDARIES = "transaction-boundaries"
|
|
31
|
+
CROSS_MODULE_IMPACT = "cross-module-impact"
|
|
32
|
+
# TRANSACTIONS & SECURITY pack (Fase 6)
|
|
33
|
+
TRANSACTION_FLOW = "transaction-flow"
|
|
34
|
+
TRANSACTION_ENTRYPOINTS = "transaction-entrypoints"
|
|
35
|
+
TRANSACTION_PROPAGATION = "transaction-propagation"
|
|
36
|
+
SECURITY_SURFACE = "security-surface"
|
|
37
|
+
SECURITY_CHAIN = "security-chain"
|
|
38
|
+
VALIDATION_POINTS = "validation-points"
|
|
39
|
+
# INTERFACES & INTEGRATIONS pack (Fase 7)
|
|
40
|
+
ENDPOINT_INVENTORY = "endpoint-inventory"
|
|
41
|
+
INTEGRATION_INVENTORY = "integration-inventory"
|
|
42
|
+
EVENT_TOPOLOGY = "event-topology"
|
|
43
|
+
# SUBSYSTEMS & DEPENDENCIES pack (Fase 8)
|
|
44
|
+
SUBSYSTEM_INVENTORY = "subsystem-inventory"
|
|
45
|
+
SUBSYSTEM_MEMBERS = "subsystem-members"
|
|
46
|
+
MODULE_DEPENDENTS = "module-dependents"
|
|
47
|
+
MODULE_DEPENDENCIES = "module-dependencies"
|
|
48
|
+
TYPE_DEPENDENTS = "type-dependents"
|
|
49
|
+
# ENDPOINT & CALL deep-dive pack (Fase 10)
|
|
50
|
+
ENDPOINT_CONTRACT = "endpoint-contract"
|
|
51
|
+
ENDPOINT_SECURITY = "endpoint-security"
|
|
52
|
+
CALL_NEIGHBORHOOD = "call-neighborhood"
|
|
53
|
+
# GRAPH-analysis pack (Fase 11)
|
|
54
|
+
EXECUTION_PATHS_THROUGH = "execution-paths-through"
|
|
55
|
+
TRANSACTIONS_REACHING = "transactions-reaching"
|
|
56
|
+
SUBSYSTEM_COUPLING = "subsystem-coupling"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass(frozen=True)
|
|
60
|
+
class RetrievalAnchor:
|
|
61
|
+
"""A typed pointer into the knowledge graph — NEVER free text to be searched.
|
|
62
|
+
|
|
63
|
+
`kind` selects the *structured* index used to bind `raw` to graph identities
|
|
64
|
+
(a simple type name → FQN via `types_by_simple`, a tech token → integration
|
|
65
|
+
scheme enum, …). It is not a substring query.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
kind: str # "symbol" | "package" | "module" | "tech" | "file" | "subsystem"
|
|
69
|
+
raw: str
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass(frozen=True)
|
|
73
|
+
class RetrievalOptions:
|
|
74
|
+
"""Presentation/shape knobs. They tune *what is returned*, never *how it is
|
|
75
|
+
computed* — the plan owns computation.
|
|
76
|
+
|
|
77
|
+
`limit` caps the number of entities in the result (applied by the terminal BuildResult
|
|
78
|
+
step, which records an `entities_truncated` observation when it bites). ``0`` means
|
|
79
|
+
unbounded — the default, so an unset option never silently drops engine-faithful
|
|
80
|
+
results. `min_confidence` and `include_evidence_text` are RESERVED (documented in
|
|
81
|
+
ADR-retrieval-v1): declared for the stable option surface, not yet enforced."""
|
|
82
|
+
|
|
83
|
+
limit: int = 0 # 0 = unbounded (engine-faithful); >0 caps the entity count
|
|
84
|
+
min_confidence: str | None = None # RESERVED — "low" | "medium" | "high"
|
|
85
|
+
include_evidence_text: bool = False # RESERVED — opt-in lazy B-3 text grounding
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@dataclass(frozen=True)
|
|
89
|
+
class RetrievalRequest:
|
|
90
|
+
"""A complete, typed knowledge query submitted by any consumer."""
|
|
91
|
+
|
|
92
|
+
intent: RetrievalIntent
|
|
93
|
+
anchors: tuple[RetrievalAnchor, ...] = ()
|
|
94
|
+
options: RetrievalOptions = field(default_factory=RetrievalOptions)
|