legacylenscli 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.
- legacylenscli/__init__.py +3 -0
- legacylenscli/analysis/__init__.py +135 -0
- legacylenscli/analysis/crud.py +196 -0
- legacylenscli/analysis/entrypoints.py +427 -0
- legacylenscli/analysis/graph.py +457 -0
- legacylenscli/analysis/health.py +392 -0
- legacylenscli/analysis/inventory.py +128 -0
- legacylenscli/analysis/metrics.py +200 -0
- legacylenscli/analysis/rules.py +1036 -0
- legacylenscli/analysis/side_effects.py +640 -0
- legacylenscli/analysis/sql_extract.py +623 -0
- legacylenscli/cli.py +224 -0
- legacylenscli/config.py +6 -0
- legacylenscli/evaluation/__init__.py +49 -0
- legacylenscli/evaluation/metrics.py +270 -0
- legacylenscli/evaluation/runner.py +556 -0
- legacylenscli/ingestion/__init__.py +53 -0
- legacylenscli/ingestion/hashing.py +134 -0
- legacylenscli/ingestion/scanner.py +406 -0
- legacylenscli/ir/__init__.py +76 -0
- legacylenscli/ir/models.py +784 -0
- legacylenscli/ir/schema.sql +230 -0
- legacylenscli/ir/store.py +1162 -0
- legacylenscli/llm/__init__.py +50 -0
- legacylenscli/llm/cache.py +128 -0
- legacylenscli/llm/claims.py +154 -0
- legacylenscli/llm/context_builder.py +674 -0
- legacylenscli/llm/prompts/explain_function.md +19 -0
- legacylenscli/llm/prompts/qa.md +17 -0
- legacylenscli/llm/prompts/summarize_module.md +17 -0
- legacylenscli/llm/prompts.py +65 -0
- legacylenscli/llm/providers/__init__.py +47 -0
- legacylenscli/llm/providers/base.py +119 -0
- legacylenscli/llm/providers/hosted.py +190 -0
- legacylenscli/llm/providers/local.py +166 -0
- legacylenscli/llm/service.py +123 -0
- legacylenscli/llm/settings.py +150 -0
- legacylenscli/parsers/__init__.py +62 -0
- legacylenscli/parsers/ast_metrics.py +154 -0
- legacylenscli/parsers/base.py +118 -0
- legacylenscli/parsers/edges.py +212 -0
- legacylenscli/parsers/java/__init__.py +7 -0
- legacylenscli/parsers/java/jsp.py +521 -0
- legacylenscli/parsers/java/parser.py +1292 -0
- legacylenscli/parsers/java/servlet_api.py +71 -0
- legacylenscli/parsers/java/xml_config.py +308 -0
- legacylenscli/parsers/php/__init__.py +5 -0
- legacylenscli/parsers/php/parser.py +1494 -0
- legacylenscli/parsers/web.py +79 -0
- legacylenscli/publisher/__init__.py +37 -0
- legacylenscli/publisher/diagrams.py +235 -0
- legacylenscli/publisher/markdown_gen.py +1184 -0
- legacylenscli/publisher/site.py +317 -0
- legacylenscli/publisher/templates/index.md.j2 +3 -0
- legacylenscli/publisher/templates/page.md.j2 +3 -0
- legacylenscli/py.typed +0 -0
- legacylenscli/qa/__init__.py +19 -0
- legacylenscli/qa/__main__.py +79 -0
- legacylenscli/qa/answers.py +445 -0
- legacylenscli/qa/retrieval.py +1302 -0
- legacylenscli/qa/server.py +222 -0
- legacylenscli/qa/static/app.css +1094 -0
- legacylenscli/qa/static/app.js +489 -0
- legacylenscli/qa/static/index.html +251 -0
- legacylenscli/verification/__init__.py +24 -0
- legacylenscli/verification/citations.py +174 -0
- legacylenscli/verification/verifier.py +524 -0
- legacylenscli-0.1.0.dist-info/METADATA +254 -0
- legacylenscli-0.1.0.dist-info/RECORD +72 -0
- legacylenscli-0.1.0.dist-info/WHEEL +4 -0
- legacylenscli-0.1.0.dist-info/entry_points.txt +2 -0
- legacylenscli-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Static analysis over IR facts."""
|
|
2
|
+
|
|
3
|
+
from .crud import (
|
|
4
|
+
CrudMatrix,
|
|
5
|
+
CrudOperation,
|
|
6
|
+
TableCrud,
|
|
7
|
+
build_crud,
|
|
8
|
+
build_crud_from_records,
|
|
9
|
+
)
|
|
10
|
+
from .entrypoints import (
|
|
11
|
+
EntryPointDetail,
|
|
12
|
+
EntryPointsReport,
|
|
13
|
+
build_entrypoints,
|
|
14
|
+
)
|
|
15
|
+
from .graph import (
|
|
16
|
+
GraphSummary,
|
|
17
|
+
NodeRank,
|
|
18
|
+
RelationshipGraphs,
|
|
19
|
+
UnresolvedEdge,
|
|
20
|
+
build_graphs,
|
|
21
|
+
)
|
|
22
|
+
from .health import (
|
|
23
|
+
FindingSeverity,
|
|
24
|
+
HealthFinding,
|
|
25
|
+
HealthReport,
|
|
26
|
+
HealthStatus,
|
|
27
|
+
build_health_report,
|
|
28
|
+
)
|
|
29
|
+
from .inventory import (
|
|
30
|
+
ClassKindCount,
|
|
31
|
+
Inventory,
|
|
32
|
+
LanguageInventory,
|
|
33
|
+
build_inventory,
|
|
34
|
+
)
|
|
35
|
+
from .metrics import (
|
|
36
|
+
Distribution,
|
|
37
|
+
FunctionMetric,
|
|
38
|
+
MetricsReport,
|
|
39
|
+
build_metrics,
|
|
40
|
+
collect_function_metrics,
|
|
41
|
+
)
|
|
42
|
+
from .rules import (
|
|
43
|
+
BusinessRuleReport,
|
|
44
|
+
DeadCodeCandidate,
|
|
45
|
+
DeadCodeReport,
|
|
46
|
+
RuleCandidate,
|
|
47
|
+
RuleKind,
|
|
48
|
+
RuleSource,
|
|
49
|
+
build_business_rules,
|
|
50
|
+
build_dead_code,
|
|
51
|
+
)
|
|
52
|
+
from .side_effects import (
|
|
53
|
+
SideEffectCandidate,
|
|
54
|
+
SideEffectGroup,
|
|
55
|
+
SideEffectReport,
|
|
56
|
+
SideEffectSite,
|
|
57
|
+
build_side_effect_report,
|
|
58
|
+
build_side_effect_report_from_records,
|
|
59
|
+
build_side_effects,
|
|
60
|
+
classify_java_constructor,
|
|
61
|
+
classify_java_method,
|
|
62
|
+
classify_jsp_process,
|
|
63
|
+
classify_jsp_session_write,
|
|
64
|
+
classify_php_function_call,
|
|
65
|
+
classify_php_session_write,
|
|
66
|
+
classify_php_shell_command,
|
|
67
|
+
resolve_java_type,
|
|
68
|
+
)
|
|
69
|
+
from .sql_extract import (
|
|
70
|
+
SqlStatement,
|
|
71
|
+
build_data_access,
|
|
72
|
+
detect_driver,
|
|
73
|
+
looks_like_sql,
|
|
74
|
+
parse_sql,
|
|
75
|
+
split_sql_statements,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
__all__ = [
|
|
79
|
+
"BusinessRuleReport",
|
|
80
|
+
"ClassKindCount",
|
|
81
|
+
"CrudMatrix",
|
|
82
|
+
"CrudOperation",
|
|
83
|
+
"DeadCodeCandidate",
|
|
84
|
+
"DeadCodeReport",
|
|
85
|
+
"Distribution",
|
|
86
|
+
"EntryPointDetail",
|
|
87
|
+
"EntryPointsReport",
|
|
88
|
+
"FindingSeverity",
|
|
89
|
+
"FunctionMetric",
|
|
90
|
+
"GraphSummary",
|
|
91
|
+
"HealthFinding",
|
|
92
|
+
"HealthReport",
|
|
93
|
+
"HealthStatus",
|
|
94
|
+
"Inventory",
|
|
95
|
+
"LanguageInventory",
|
|
96
|
+
"MetricsReport",
|
|
97
|
+
"NodeRank",
|
|
98
|
+
"RelationshipGraphs",
|
|
99
|
+
"RuleCandidate",
|
|
100
|
+
"RuleKind",
|
|
101
|
+
"RuleSource",
|
|
102
|
+
"SideEffectCandidate",
|
|
103
|
+
"SideEffectGroup",
|
|
104
|
+
"SideEffectReport",
|
|
105
|
+
"SideEffectSite",
|
|
106
|
+
"SqlStatement",
|
|
107
|
+
"TableCrud",
|
|
108
|
+
"UnresolvedEdge",
|
|
109
|
+
"build_business_rules",
|
|
110
|
+
"build_crud",
|
|
111
|
+
"build_crud_from_records",
|
|
112
|
+
"build_data_access",
|
|
113
|
+
"build_dead_code",
|
|
114
|
+
"build_entrypoints",
|
|
115
|
+
"build_graphs",
|
|
116
|
+
"build_health_report",
|
|
117
|
+
"build_inventory",
|
|
118
|
+
"build_metrics",
|
|
119
|
+
"build_side_effect_report",
|
|
120
|
+
"build_side_effect_report_from_records",
|
|
121
|
+
"build_side_effects",
|
|
122
|
+
"classify_java_constructor",
|
|
123
|
+
"classify_java_method",
|
|
124
|
+
"classify_jsp_process",
|
|
125
|
+
"classify_jsp_session_write",
|
|
126
|
+
"classify_php_function_call",
|
|
127
|
+
"classify_php_session_write",
|
|
128
|
+
"classify_php_shell_command",
|
|
129
|
+
"collect_function_metrics",
|
|
130
|
+
"detect_driver",
|
|
131
|
+
"looks_like_sql",
|
|
132
|
+
"parse_sql",
|
|
133
|
+
"resolve_java_type",
|
|
134
|
+
"split_sql_statements",
|
|
135
|
+
]
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"""CRUD coverage derived from stored data-access facts.
|
|
2
|
+
|
|
3
|
+
``data_access`` rows are statement/table pairs, so this module pivots them into a stable
|
|
4
|
+
table -> operations -> functions matrix. It reports absent CRUD letters for each table
|
|
5
|
+
instead of inventing tables the repository never mentions; there is no schema snapshot to
|
|
6
|
+
compare against yet.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from collections import defaultdict
|
|
12
|
+
from collections.abc import Iterable
|
|
13
|
+
from dataclasses import dataclass
|
|
14
|
+
|
|
15
|
+
from legacylenscli.ir.models import DataAccessRecord, SqlOperation
|
|
16
|
+
from legacylenscli.ir.store import FactStore
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"CrudMatrix",
|
|
20
|
+
"CrudOperation",
|
|
21
|
+
"TableCrud",
|
|
22
|
+
"build_crud",
|
|
23
|
+
"build_crud_from_records",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
_CRUD_ORDER = ("R", "C", "U", "D")
|
|
27
|
+
_OPERATION_ORDER = {
|
|
28
|
+
SqlOperation.SELECT: 0,
|
|
29
|
+
SqlOperation.INSERT: 1,
|
|
30
|
+
SqlOperation.REPLACE: 2,
|
|
31
|
+
SqlOperation.UPDATE: 3,
|
|
32
|
+
SqlOperation.DELETE: 4,
|
|
33
|
+
SqlOperation.MERGE: 5,
|
|
34
|
+
SqlOperation.DDL: 6,
|
|
35
|
+
SqlOperation.EXEC: 7,
|
|
36
|
+
SqlOperation.OTHER: 8,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass(frozen=True, slots=True)
|
|
41
|
+
class CrudOperation:
|
|
42
|
+
"""One operation observed against one table."""
|
|
43
|
+
|
|
44
|
+
operation: SqlOperation
|
|
45
|
+
letter: str | None
|
|
46
|
+
records: int
|
|
47
|
+
functions: tuple[str, ...]
|
|
48
|
+
files: tuple[str, ...]
|
|
49
|
+
|
|
50
|
+
def as_dict(self) -> dict[str, object]:
|
|
51
|
+
return {
|
|
52
|
+
"operation": self.operation.value,
|
|
53
|
+
"letter": self.letter,
|
|
54
|
+
"records": self.records,
|
|
55
|
+
"functions": list(self.functions),
|
|
56
|
+
"files": list(self.files),
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@dataclass(frozen=True, slots=True)
|
|
61
|
+
class TableCrud:
|
|
62
|
+
"""CRUD coverage for one table."""
|
|
63
|
+
|
|
64
|
+
table_name: str
|
|
65
|
+
crud: str
|
|
66
|
+
missing: tuple[str, ...]
|
|
67
|
+
operations: tuple[CrudOperation, ...]
|
|
68
|
+
functions: tuple[str, ...]
|
|
69
|
+
files: tuple[str, ...]
|
|
70
|
+
|
|
71
|
+
def as_dict(self) -> dict[str, object]:
|
|
72
|
+
return {
|
|
73
|
+
"table": self.table_name,
|
|
74
|
+
"crud": self.crud,
|
|
75
|
+
"missing": list(self.missing),
|
|
76
|
+
"functions": list(self.functions),
|
|
77
|
+
"files": list(self.files),
|
|
78
|
+
"operations": [item.as_dict() for item in self.operations],
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@dataclass(frozen=True, slots=True)
|
|
83
|
+
class CrudMatrix:
|
|
84
|
+
"""The whole table/operation/function matrix plus rows with no table."""
|
|
85
|
+
|
|
86
|
+
tables: tuple[TableCrud, ...]
|
|
87
|
+
unknown_table: tuple[DataAccessRecord, ...]
|
|
88
|
+
records: int
|
|
89
|
+
script_records: int
|
|
90
|
+
|
|
91
|
+
def as_dict(self) -> dict[str, object]:
|
|
92
|
+
read_only = [item.table_name for item in self.tables if item.crud == "R"]
|
|
93
|
+
write_only = [item.table_name for item in self.tables if item.crud and "R" not in item.crud]
|
|
94
|
+
return {
|
|
95
|
+
"records": self.records,
|
|
96
|
+
"script_records": self.script_records,
|
|
97
|
+
"tables": [item.as_dict() for item in self.tables],
|
|
98
|
+
"unknown_table": [_record_dict(item) for item in self.unknown_table],
|
|
99
|
+
"summary": {
|
|
100
|
+
"tables": len(self.tables),
|
|
101
|
+
"read_only": read_only,
|
|
102
|
+
"write_only": write_only,
|
|
103
|
+
"complete": [
|
|
104
|
+
item.table_name for item in self.tables if item.crud and not item.missing
|
|
105
|
+
],
|
|
106
|
+
"missing_operations": {
|
|
107
|
+
item.table_name: list(item.missing) for item in self.tables if item.missing
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def build_crud(store: FactStore) -> CrudMatrix:
|
|
114
|
+
"""Build the CRUD matrix from every stored ``data_access`` row."""
|
|
115
|
+
|
|
116
|
+
return build_crud_from_records(store.list_data_access())
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def build_crud_from_records(records: Iterable[DataAccessRecord]) -> CrudMatrix:
|
|
120
|
+
"""Build the CRUD matrix from an existing record sequence."""
|
|
121
|
+
|
|
122
|
+
materialised = tuple(records)
|
|
123
|
+
by_table: dict[str, list[DataAccessRecord]] = defaultdict(list)
|
|
124
|
+
unknown: list[DataAccessRecord] = []
|
|
125
|
+
for record in materialised:
|
|
126
|
+
if record.table_name:
|
|
127
|
+
by_table[record.table_name].append(record)
|
|
128
|
+
else:
|
|
129
|
+
unknown.append(record)
|
|
130
|
+
|
|
131
|
+
tables = [_table_crud(table_name, by_table[table_name]) for table_name in sorted(by_table)]
|
|
132
|
+
unknown.sort(
|
|
133
|
+
key=lambda item: (
|
|
134
|
+
item.file_path,
|
|
135
|
+
item.line,
|
|
136
|
+
item.operation.value,
|
|
137
|
+
item.sql,
|
|
138
|
+
)
|
|
139
|
+
)
|
|
140
|
+
return CrudMatrix(
|
|
141
|
+
tables=tuple(tables),
|
|
142
|
+
unknown_table=tuple(unknown),
|
|
143
|
+
records=len(materialised),
|
|
144
|
+
script_records=sum(1 for item in materialised if item.function_id is None),
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _table_crud(table_name: str, records: list[DataAccessRecord]) -> TableCrud:
|
|
149
|
+
grouped: dict[SqlOperation, list[DataAccessRecord]] = defaultdict(list)
|
|
150
|
+
for record in records:
|
|
151
|
+
grouped[record.operation].append(record)
|
|
152
|
+
|
|
153
|
+
operations = [
|
|
154
|
+
CrudOperation(
|
|
155
|
+
operation=operation,
|
|
156
|
+
letter=operation.crud,
|
|
157
|
+
records=len(grouped[operation]),
|
|
158
|
+
functions=tuple(
|
|
159
|
+
sorted(
|
|
160
|
+
{
|
|
161
|
+
item.function_id
|
|
162
|
+
for item in grouped[operation]
|
|
163
|
+
if item.function_id is not None
|
|
164
|
+
}
|
|
165
|
+
)
|
|
166
|
+
),
|
|
167
|
+
files=tuple(sorted({item.file_path for item in grouped[operation]})),
|
|
168
|
+
)
|
|
169
|
+
for operation in sorted(grouped, key=lambda item: _OPERATION_ORDER[item])
|
|
170
|
+
]
|
|
171
|
+
letters = {item.letter for item in operations if item.letter is not None}
|
|
172
|
+
crud = "".join(letter for letter in _CRUD_ORDER if letter in letters)
|
|
173
|
+
missing = tuple(letter for letter in _CRUD_ORDER if letter not in letters) if crud else ()
|
|
174
|
+
return TableCrud(
|
|
175
|
+
table_name=table_name,
|
|
176
|
+
crud=crud,
|
|
177
|
+
missing=missing,
|
|
178
|
+
operations=tuple(operations),
|
|
179
|
+
functions=tuple(
|
|
180
|
+
sorted({item.function_id for item in records if item.function_id is not None})
|
|
181
|
+
),
|
|
182
|
+
files=tuple(sorted({item.file_path for item in records})),
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _record_dict(record: DataAccessRecord) -> dict[str, object]:
|
|
187
|
+
return {
|
|
188
|
+
"file_path": record.file_path,
|
|
189
|
+
"line": record.line,
|
|
190
|
+
"operation": record.operation.value,
|
|
191
|
+
"sql": record.sql,
|
|
192
|
+
"parameters": list(record.parameters),
|
|
193
|
+
"function_id": record.function_id,
|
|
194
|
+
"driver": record.driver,
|
|
195
|
+
"confidence": record.confidence.value,
|
|
196
|
+
}
|