legacylenscli 0.1.0__tar.gz
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-0.1.0/.gitignore +32 -0
- legacylenscli-0.1.0/CHANGELOG.md +133 -0
- legacylenscli-0.1.0/LICENSE +21 -0
- legacylenscli-0.1.0/PKG-INFO +254 -0
- legacylenscli-0.1.0/README.md +211 -0
- legacylenscli-0.1.0/docs/architecture.md +379 -0
- legacylenscli-0.1.0/docs/ir-spec.md +581 -0
- legacylenscli-0.1.0/pyproject.toml +110 -0
- legacylenscli-0.1.0/src/legacylenscli/__init__.py +3 -0
- legacylenscli-0.1.0/src/legacylenscli/analysis/__init__.py +135 -0
- legacylenscli-0.1.0/src/legacylenscli/analysis/crud.py +196 -0
- legacylenscli-0.1.0/src/legacylenscli/analysis/entrypoints.py +427 -0
- legacylenscli-0.1.0/src/legacylenscli/analysis/graph.py +457 -0
- legacylenscli-0.1.0/src/legacylenscli/analysis/health.py +392 -0
- legacylenscli-0.1.0/src/legacylenscli/analysis/inventory.py +128 -0
- legacylenscli-0.1.0/src/legacylenscli/analysis/metrics.py +200 -0
- legacylenscli-0.1.0/src/legacylenscli/analysis/rules.py +1036 -0
- legacylenscli-0.1.0/src/legacylenscli/analysis/side_effects.py +640 -0
- legacylenscli-0.1.0/src/legacylenscli/analysis/sql_extract.py +623 -0
- legacylenscli-0.1.0/src/legacylenscli/cli.py +224 -0
- legacylenscli-0.1.0/src/legacylenscli/config.py +6 -0
- legacylenscli-0.1.0/src/legacylenscli/evaluation/__init__.py +49 -0
- legacylenscli-0.1.0/src/legacylenscli/evaluation/metrics.py +270 -0
- legacylenscli-0.1.0/src/legacylenscli/evaluation/runner.py +556 -0
- legacylenscli-0.1.0/src/legacylenscli/ingestion/__init__.py +53 -0
- legacylenscli-0.1.0/src/legacylenscli/ingestion/hashing.py +134 -0
- legacylenscli-0.1.0/src/legacylenscli/ingestion/scanner.py +406 -0
- legacylenscli-0.1.0/src/legacylenscli/ir/__init__.py +76 -0
- legacylenscli-0.1.0/src/legacylenscli/ir/models.py +784 -0
- legacylenscli-0.1.0/src/legacylenscli/ir/schema.sql +230 -0
- legacylenscli-0.1.0/src/legacylenscli/ir/store.py +1162 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/__init__.py +50 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/cache.py +128 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/claims.py +154 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/context_builder.py +674 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/prompts/explain_function.md +19 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/prompts/qa.md +17 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/prompts/summarize_module.md +17 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/prompts.py +65 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/providers/__init__.py +47 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/providers/base.py +119 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/providers/hosted.py +190 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/providers/local.py +166 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/service.py +123 -0
- legacylenscli-0.1.0/src/legacylenscli/llm/settings.py +150 -0
- legacylenscli-0.1.0/src/legacylenscli/parsers/__init__.py +62 -0
- legacylenscli-0.1.0/src/legacylenscli/parsers/ast_metrics.py +154 -0
- legacylenscli-0.1.0/src/legacylenscli/parsers/base.py +118 -0
- legacylenscli-0.1.0/src/legacylenscli/parsers/edges.py +212 -0
- legacylenscli-0.1.0/src/legacylenscli/parsers/java/__init__.py +7 -0
- legacylenscli-0.1.0/src/legacylenscli/parsers/java/jsp.py +521 -0
- legacylenscli-0.1.0/src/legacylenscli/parsers/java/parser.py +1292 -0
- legacylenscli-0.1.0/src/legacylenscli/parsers/java/servlet_api.py +71 -0
- legacylenscli-0.1.0/src/legacylenscli/parsers/java/xml_config.py +308 -0
- legacylenscli-0.1.0/src/legacylenscli/parsers/php/__init__.py +5 -0
- legacylenscli-0.1.0/src/legacylenscli/parsers/php/parser.py +1494 -0
- legacylenscli-0.1.0/src/legacylenscli/parsers/web.py +79 -0
- legacylenscli-0.1.0/src/legacylenscli/publisher/__init__.py +37 -0
- legacylenscli-0.1.0/src/legacylenscli/publisher/diagrams.py +235 -0
- legacylenscli-0.1.0/src/legacylenscli/publisher/markdown_gen.py +1184 -0
- legacylenscli-0.1.0/src/legacylenscli/publisher/site.py +317 -0
- legacylenscli-0.1.0/src/legacylenscli/publisher/templates/index.md.j2 +3 -0
- legacylenscli-0.1.0/src/legacylenscli/publisher/templates/page.md.j2 +3 -0
- legacylenscli-0.1.0/src/legacylenscli/py.typed +0 -0
- legacylenscli-0.1.0/src/legacylenscli/qa/__init__.py +19 -0
- legacylenscli-0.1.0/src/legacylenscli/qa/__main__.py +79 -0
- legacylenscli-0.1.0/src/legacylenscli/qa/answers.py +445 -0
- legacylenscli-0.1.0/src/legacylenscli/qa/retrieval.py +1302 -0
- legacylenscli-0.1.0/src/legacylenscli/qa/server.py +222 -0
- legacylenscli-0.1.0/src/legacylenscli/qa/static/app.css +1094 -0
- legacylenscli-0.1.0/src/legacylenscli/qa/static/app.js +489 -0
- legacylenscli-0.1.0/src/legacylenscli/qa/static/index.html +251 -0
- legacylenscli-0.1.0/src/legacylenscli/verification/__init__.py +24 -0
- legacylenscli-0.1.0/src/legacylenscli/verification/citations.py +174 -0
- legacylenscli-0.1.0/src/legacylenscli/verification/verifier.py +524 -0
- legacylenscli-0.1.0/tests/conftest.py +199 -0
- legacylenscli-0.1.0/tests/fixtures/java_app/src/main/java/com/example/User.java +24 -0
- legacylenscli-0.1.0/tests/fixtures/java_app/src/main/java/com/example/UserRepository.java +21 -0
- legacylenscli-0.1.0/tests/fixtures/java_app/src/main/java/com/example/UserServlet.java +26 -0
- legacylenscli-0.1.0/tests/fixtures/java_app/src/main/webapp/WEB-INF/web.xml +14 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/public/export.php +4 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/public/inc/analytics.php +6 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/public/inc/helpers.php +37 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/public/index.php +8 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/java/com/example/AuthFilter.java +18 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/java/com/example/SaveUserAction.java +54 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/java/com/example/UserForm.java +27 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/java/com/example/UserServlet.java +29 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/java/com/example/WidgetAction.java +10 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/resources/struts-config.xml +14 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/resources/struts.xml +11 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/webapp/WEB-INF/example.tld +11 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/webapp/WEB-INF/tags/widget.tag +3 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/webapp/WEB-INF/views/secret.jsp +6 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/webapp/WEB-INF/web.xml +31 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/webapp/inc/footer.jspf +2 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/webapp/inc/header.jspf +2 -0
- legacylenscli-0.1.0/tests/fixtures/legacy_web/src/main/webapp/users/list.jsp +22 -0
- legacylenscli-0.1.0/tests/fixtures/php_app/inc/db.php +7 -0
- legacylenscli-0.1.0/tests/fixtures/php_app/index.php +14 -0
- legacylenscli-0.1.0/tests/fixtures/php_app/src/User.php +20 -0
- legacylenscli-0.1.0/tests/integration/.gitkeep +1 -0
- legacylenscli-0.1.0/tests/integration/test_entrypoints_end_to_end.py +178 -0
- legacylenscli-0.1.0/tests/integration/test_evaluation_runner.py +237 -0
- legacylenscli-0.1.0/tests/integration/test_inventory_metrics_end_to_end.py +95 -0
- legacylenscli-0.1.0/tests/integration/test_java_parser_end_to_end.py +49 -0
- legacylenscli-0.1.0/tests/integration/test_php_parser_end_to_end.py +44 -0
- legacylenscli-0.1.0/tests/integration/test_publisher_end_to_end.py +102 -0
- legacylenscli-0.1.0/tests/integration/test_relationship_graphs_end_to_end.py +73 -0
- legacylenscli-0.1.0/tests/integration/test_side_effects_end_to_end.py +108 -0
- legacylenscli-0.1.0/tests/integration/test_sql_crud_end_to_end.py +112 -0
- legacylenscli-0.1.0/tests/unit/.gitkeep +4 -0
- legacylenscli-0.1.0/tests/unit/test_analysis_reports.py +59 -0
- legacylenscli-0.1.0/tests/unit/test_ast_metrics.py +88 -0
- legacylenscli-0.1.0/tests/unit/test_cli.py +80 -0
- legacylenscli-0.1.0/tests/unit/test_context_builder.py +80 -0
- legacylenscli-0.1.0/tests/unit/test_crud.py +148 -0
- legacylenscli-0.1.0/tests/unit/test_entrypoint_analysis.py +181 -0
- legacylenscli-0.1.0/tests/unit/test_evaluation_metrics.py +128 -0
- legacylenscli-0.1.0/tests/unit/test_graph_resolution.py +271 -0
- legacylenscli-0.1.0/tests/unit/test_health.py +127 -0
- legacylenscli-0.1.0/tests/unit/test_ingestion_hashing.py +100 -0
- legacylenscli-0.1.0/tests/unit/test_ingestion_scanner.py +212 -0
- legacylenscli-0.1.0/tests/unit/test_ir_models.py +185 -0
- legacylenscli-0.1.0/tests/unit/test_ir_store.py +391 -0
- legacylenscli-0.1.0/tests/unit/test_java_entrypoints.py +156 -0
- legacylenscli-0.1.0/tests/unit/test_java_parser.py +215 -0
- legacylenscli-0.1.0/tests/unit/test_jsp_parser.py +121 -0
- legacylenscli-0.1.0/tests/unit/test_llm_cache.py +102 -0
- legacylenscli-0.1.0/tests/unit/test_llm_claims.py +122 -0
- legacylenscli-0.1.0/tests/unit/test_llm_providers.py +196 -0
- legacylenscli-0.1.0/tests/unit/test_llm_service.py +103 -0
- legacylenscli-0.1.0/tests/unit/test_package.py +7 -0
- legacylenscli-0.1.0/tests/unit/test_packaging.py +40 -0
- legacylenscli-0.1.0/tests/unit/test_parser_edges.py +285 -0
- legacylenscli-0.1.0/tests/unit/test_php_entrypoints.py +147 -0
- legacylenscli-0.1.0/tests/unit/test_php_parser.py +241 -0
- legacylenscli-0.1.0/tests/unit/test_publisher.py +509 -0
- legacylenscli-0.1.0/tests/unit/test_qa_answers.py +224 -0
- legacylenscli-0.1.0/tests/unit/test_qa_retrieval.py +232 -0
- legacylenscli-0.1.0/tests/unit/test_qa_server.py +174 -0
- legacylenscli-0.1.0/tests/unit/test_rules.py +239 -0
- legacylenscli-0.1.0/tests/unit/test_side_effects.py +453 -0
- legacylenscli-0.1.0/tests/unit/test_sql_extract.py +162 -0
- legacylenscli-0.1.0/tests/unit/test_verifier.py +470 -0
- legacylenscli-0.1.0/tests/unit/test_xml_config_parser.py +168 -0
- legacylenscli-0.1.0/uv.lock +1095 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
.venv/
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.py[cod]
|
|
5
|
+
*.egg-info/
|
|
6
|
+
.pytest_cache/
|
|
7
|
+
.ruff_cache/
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
|
|
11
|
+
# Environment
|
|
12
|
+
.env
|
|
13
|
+
.env.*
|
|
14
|
+
!.env.example
|
|
15
|
+
|
|
16
|
+
# LegacyLens artefacts
|
|
17
|
+
.legacylens/
|
|
18
|
+
*.db
|
|
19
|
+
*.db-journal
|
|
20
|
+
*.db-wal
|
|
21
|
+
|
|
22
|
+
# Corpus and evaluation output (inputs fetched on demand)
|
|
23
|
+
corpus/*
|
|
24
|
+
!corpus/README.md
|
|
25
|
+
evaluation/results/*
|
|
26
|
+
!evaluation/results/.gitkeep
|
|
27
|
+
|
|
28
|
+
# Editors / OS
|
|
29
|
+
.vscode/
|
|
30
|
+
.idea/
|
|
31
|
+
.DS_Store
|
|
32
|
+
Thumbs.db
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
While the project is pre-1.0, minor versions may include breaking changes.
|
|
8
|
+
|
|
9
|
+
## [Unreleased]
|
|
10
|
+
|
|
11
|
+
## [0.1.0] - 2026-11-25
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Deterministic, streaming repository scanner with legacy PHP/Java/JSP/XML detection,
|
|
16
|
+
binary and size filtering, include/exclude globs, symlink handling and skip diagnostics.
|
|
17
|
+
- SHA-256 content hashing with an extractor version folded into the file digest, plus
|
|
18
|
+
physical line counting.
|
|
19
|
+
- `scripts/bench_scan.py` for measuring scan throughput and peak memory on real repositories.
|
|
20
|
+
- Parser contract (`parsers/base.py`) and a Tree-sitter PHP thin slice that extracts
|
|
21
|
+
class-like declarations and named functions/methods with qualified names, spans,
|
|
22
|
+
visibility and static/abstract flags, while recording recoverable syntax errors on the
|
|
23
|
+
file instead of discarding partial facts.
|
|
24
|
+
- End-to-end test covering scanner -> PHP parser -> SQLite store for a fixture file.
|
|
25
|
+
- Tree-sitter Java thin slice using the same parser contract and IR: package-qualified
|
|
26
|
+
class/interface/enum/record declarations, methods, constructors, visibility and
|
|
27
|
+
static/abstract flags. Overloaded methods are disambiguated by declared parameter types
|
|
28
|
+
so unique function keys are preserved without changing the IR.
|
|
29
|
+
- End-to-end test covering scanner -> Java parser -> SQLite store for a fixture file.
|
|
30
|
+
- Project inventory: file/LOC/byte totals, language mix, class-kind and function counts, and
|
|
31
|
+
parse-error/generated/vendored counters, exposed as JSON-friendly dataclasses.
|
|
32
|
+
- Function metrics: parser-measured cyclomatic complexity and maximum nesting, plus
|
|
33
|
+
span-derived function length, summarised as distributions and deterministic top-N
|
|
34
|
+
rankings. Metric definitions are documented in `docs/architecture.md`.
|
|
35
|
+
- End-to-end analysis test over the PHP and Java fixture apps.
|
|
36
|
+
- Relationship edges from the PHP and Java parsers: imports, includes/requires,
|
|
37
|
+
`extends`/`implements`/`uses_trait` and calls, with same-file resolution and stable
|
|
38
|
+
references for dynamic or cross-file targets.
|
|
39
|
+
- Project-level edge resolution and NetworkX include, inheritance and call graphs with
|
|
40
|
+
aggregated parallel edges, explicit `unresolved:<kind>:<reference>` nodes, dangling
|
|
41
|
+
target counts, cycle groups and deterministic fan-in/fan-out summaries.
|
|
42
|
+
- Entry points and request inputs across PHP pages/CLI scripts, servlets, filters, JSP
|
|
43
|
+
pages and Struts 1/2 actions, including `web.xml`, `struts-config.xml`, `struts.xml` and
|
|
44
|
+
TLD ingestion. Parsers record a pre-resolution `handler_ref`; `analysis/entrypoints.py`
|
|
45
|
+
follows class lineage, calls and static JSP includes to attribute request inputs to
|
|
46
|
+
handlers, reports unassigned reads and emits a deterministic JSON-ready summary.
|
|
47
|
+
- Request-input IR: `RequestInputKind`, `RequestInputRecord`, the `request_inputs` table and
|
|
48
|
+
`FileFacts.request_inputs`. Static keys are `verified`, dynamic keys stay explicit as
|
|
49
|
+
`<dynamic>`, and form-bean-derived fields are `inferred`.
|
|
50
|
+
- JSP parser (pages, EL, scriptlets, form fields, page imports, static/dynamic includes) and
|
|
51
|
+
a namespace-tolerant XML descriptor parser built on stdlib Expat with exact line numbers.
|
|
52
|
+
- End-to-end web fixture app (`tests/fixtures/legacy_web`) covering PHP, servlets, filters,
|
|
53
|
+
Struts, JSP, `WEB-INF` exclusions, fragments and malformed/namespace-prefixed descriptors.
|
|
54
|
+
- Side-effect detection across PHP and Java: file, email, network, process and session sinks
|
|
55
|
+
classified by the analysis module, attributed to the innermost function and reported grouped
|
|
56
|
+
by kind, with dynamic/ambiguous receivers left unreported. JSP scriptlets detect session
|
|
57
|
+
writes and process execution.
|
|
58
|
+
Interpolated or concatenated dynamic fragments stay explicit as `<dynamic>` and are never
|
|
59
|
+
expanded into a table name; drivers are recorded only from PHP/Java file evidence.
|
|
60
|
+
- CRUD matrix (`analysis/crud.py`) pivoting `data_access` statement/table rows into a
|
|
61
|
+
deterministic table → operations → functions report with observed CRUD letters, missing
|
|
62
|
+
operations, read-only/write-only tables, unknown-table statements and JSON-ready output.
|
|
63
|
+
- Static publisher: deterministic Markdown pages for inventory, architecture, entry points,
|
|
64
|
+
CRUD coverage, side effects, hotspots and files, with bounded Mermaid diagrams rendered
|
|
65
|
+
from the resolved analyses.
|
|
66
|
+
- `publisher/site.py` writes the docs tree, Mermaid loader, `mkdocs.yml` and a page manifest,
|
|
67
|
+
removes stale pages and optionally runs `mkdocs build` when the `site` extra is installed.
|
|
68
|
+
Pages contain no AI-generated content, timestamps or absolute paths.
|
|
69
|
+
- Dead-code detection (`analysis/rules.py`) following entry points through project-resolved
|
|
70
|
+
include and call graphs, with conservative exclusions for generated/vendored files, API
|
|
71
|
+
surface, constructors, magic methods, overrides and unresolved callers, plus aggregated
|
|
72
|
+
exclusion reasons and a `skipped_reason` when no entry point exists.
|
|
73
|
+
- Deterministic business-rule candidates from PHP/Java conditions, validation and
|
|
74
|
+
authorisation calls, IR annotations and explicit entry-point auth, each with exact
|
|
75
|
+
evidence, citations and confidence labels.
|
|
76
|
+
- Aggregate health report (`analysis/health.py`) combining every deterministic analysis into
|
|
77
|
+
stable findings with configurable complexity, length, nesting and parse-error thresholds,
|
|
78
|
+
an overall `ok`/`attention`/`critical` status and JSON-ready output. Heuristics and
|
|
79
|
+
thresholds are documented in `docs/architecture.md`.
|
|
80
|
+
- Claim verification (`verification/verifier.py`) parsing the citation grammar, resolving
|
|
81
|
+
citations against the IR and source, assigning `verified`, `inferred` or `unsupported`,
|
|
82
|
+
persisting statuses and reporting verification rates.
|
|
83
|
+
- Published `claims.md` page with verification badges and an index verification summary.
|
|
84
|
+
Unsupported claims are retained in the store but excluded from publication.
|
|
85
|
+
- Provider-agnostic LLM layer: a shared `Provider`/`Completion` interface, OpenAI-compatible
|
|
86
|
+
hosted adapter, Ollama adapter, no-op provider, environment-backed `LLMSettings` with
|
|
87
|
+
redacted API keys, typed errors, retries and per-model cost accounting.
|
|
88
|
+
- Budgeted, citation-first context builder for functions, classes, files and projects,
|
|
89
|
+
deterministic `{{variable}}` prompt rendering and strict JSON claim parsing that drops
|
|
90
|
+
citations not present in the supplied context.
|
|
91
|
+
- Persistent completion cache keyed by provider/model/endpoint/sampling/prompt, with hit,
|
|
92
|
+
token and cost accounting, plus an explanation service that stores accepted claims as
|
|
93
|
+
`origin=llm` and `status=inferred`.
|
|
94
|
+
- Evaluation harness with strictly validated, hand-authored ground truth; set
|
|
95
|
+
precision/recall/F1 for entry points, table/operation pairs and business-rule evidence.
|
|
96
|
+
- Isolated runners for the three configurations (static only, LLM without verification, full
|
|
97
|
+
pipeline), plus claim status counts and verification rates.
|
|
98
|
+
- Usage reporting that separates estimated completion cost from billable cache-miss cost,
|
|
99
|
+
with prompt/completion tokens and cache hit rate, and a `scripts/run_evaluation.py`
|
|
100
|
+
command that writes JSON results under `evaluation/results/`.
|
|
101
|
+
- Local Q&A service (`qa/`): deterministic BM25 retrieval over generated documentation and
|
|
102
|
+
structured IR passages, with weighted fields, exact symbol/path boosts and kind/page
|
|
103
|
+
filters. Extractive answers work offline; optional LLM answers use the cached completion
|
|
104
|
+
layer and reject citations that were not supplied as evidence.
|
|
105
|
+
- Cited-answer status policy aligned with verification (`verified`/`inferred`/`unsupported`)
|
|
106
|
+
and JSON endpoints `GET /health`, `GET /search` and `POST /ask`.
|
|
107
|
+
- Packaged, dependency-free HTML interface with kind/page filters, expandable evidence,
|
|
108
|
+
matched-term chips, citation links, copy actions, status badges and a dark-first
|
|
109
|
+
accessible design. It loads no CDN assets and binds to `127.0.0.1` by default.
|
|
110
|
+
- `python -m legacylenscli.qa` runner with `--db`, `--docs`, provider, model and bind options.
|
|
111
|
+
- Working `legacylenscli` console commands: `analyze` writes the health report, `build` writes
|
|
112
|
+
the static documentation site and `serve` analyses a repository and starts the local Q&A
|
|
113
|
+
interface.
|
|
114
|
+
- Repository scaffold for the LegacyLens analysis pipeline: ingestion, IR, parsers,
|
|
115
|
+
static analyses, LLM integration, verification, publishing, Q&A and evaluation packages.
|
|
116
|
+
- Project configuration, dependency set, test fixtures and documentation skeletons.
|
|
117
|
+
- Packaging for PyPI under the distribution name `legacylenscli`, with the `legacylenscli`
|
|
118
|
+
import package and console command.
|
|
119
|
+
|
|
120
|
+
### Changed
|
|
121
|
+
|
|
122
|
+
- `FactStore` accepts `check_same_thread=False` for local servers that dispatch synchronous
|
|
123
|
+
requests from a worker thread; the default remains thread-confined.
|
|
124
|
+
- `verification.resolve_citation` is now public for callers that validate evidence without
|
|
125
|
+
judging or persisting a claim.
|
|
126
|
+
- IR schema version bumped from `1` to `2`; existing databases must be rebuilt.
|
|
127
|
+
- `EntryPointRecord` gained `handler_ref`, and `FileFacts` gained `request_inputs`.
|
|
128
|
+
- The fixture-tree scanner test now includes the web fixture app (25 files).
|
|
129
|
+
|
|
130
|
+
### Fixed
|
|
131
|
+
|
|
132
|
+
- A docstring in `parsers/edges.py` no longer emits a `SyntaxWarning` for an invalid escape
|
|
133
|
+
sequence when the parser package is imported.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Edmund K. Pereira
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: legacylenscli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AI-assisted static analysis and documentation for legacy PHP and Java web applications
|
|
5
|
+
Project-URL: Homepage, https://github.com/Kay-pereira/legacylens
|
|
6
|
+
Project-URL: Repository, https://github.com/Kay-pereira/legacylens
|
|
7
|
+
Project-URL: Issues, https://github.com/Kay-pereira/legacylens/issues
|
|
8
|
+
Project-URL: Documentation, https://github.com/Kay-pereira/legacylens/tree/main/docs
|
|
9
|
+
Project-URL: Changelog, https://github.com/Kay-pereira/legacylens/blob/main/CHANGELOG.md
|
|
10
|
+
Author: Edmund K. Pereira
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: documentation,java,legacy,llm,php,static-analysis
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Programming Language :: Java
|
|
18
|
+
Classifier: Programming Language :: PHP
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
24
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: <3.14,>=3.12
|
|
27
|
+
Requires-Dist: fastapi>=0.162.7
|
|
28
|
+
Requires-Dist: httpx>=0.28.1
|
|
29
|
+
Requires-Dist: jinja2>=3.1.6
|
|
30
|
+
Requires-Dist: networkx>=3.7
|
|
31
|
+
Requires-Dist: pydantic>=2.14.3
|
|
32
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
33
|
+
Requires-Dist: rich>=15.0.0
|
|
34
|
+
Requires-Dist: sqlglot>=30.31.0
|
|
35
|
+
Requires-Dist: tree-sitter-java>=0.23.5
|
|
36
|
+
Requires-Dist: tree-sitter-php>=0.25.1
|
|
37
|
+
Requires-Dist: tree-sitter>=0.26.1
|
|
38
|
+
Requires-Dist: typer>=0.29.1
|
|
39
|
+
Requires-Dist: uvicorn>=0.54.0
|
|
40
|
+
Provides-Extra: site
|
|
41
|
+
Requires-Dist: mkdocs>=1.6; extra == 'site'
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
|
|
44
|
+
# LegacyLens
|
|
45
|
+
|
|
46
|
+
AI-assisted static analysis and documentation tool for legacy **PHP** and **Java** web apps.
|
|
47
|
+
|
|
48
|
+
> Status: early implementation. The IR, SQLite fact store, ingestion scanner, hashing,
|
|
49
|
+
> language detection, PHP/Java/JSP/XML parsers, inventory/function metrics (counts, length,
|
|
50
|
+
> complexity, nesting), include/import/inheritance/call graphs, entry points/request inputs,
|
|
51
|
+
> SQL extraction, the CRUD matrix, side effects, the static publisher (Markdown, Mermaid,
|
|
52
|
+
> MkDocs), dead-code detection, business-rule candidates, the aggregate health report, the
|
|
53
|
+
> provider-agnostic LLM layer, claim verification, the local Q&A service and the evaluation
|
|
54
|
+
> harness are in place. The `legacylenscli` command exposes `analyze`, `build` and `serve`.
|
|
55
|
+
|
|
56
|
+
## Install
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install legacylenscli
|
|
60
|
+
# with the optional MkDocs build
|
|
61
|
+
pip install "legacylenscli[site]"
|
|
62
|
+
# or
|
|
63
|
+
uv add legacylenscli
|
|
64
|
+
uv add "legacylenscli[site]"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The PyPI distribution, import package and installed command are all **`legacylenscli`**.
|
|
68
|
+
The name avoids the existing `legacylens` project on PyPI:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import legacylenscli
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Requires Python 3.12 or 3.13. The installed `legacylenscli` command provides `analyze`, `build`
|
|
75
|
+
and `serve`; the local Q&A interface is also available through `python -m legacylenscli.qa`.
|
|
76
|
+
|
|
77
|
+
## What it does
|
|
78
|
+
|
|
79
|
+
1. **Ingest** a legacy repository, detecting PHP, Java, JSP and deployment descriptors.
|
|
80
|
+
2. **Extract facts** with Tree-sitter into a flat intermediate representation (IR) stored in SQLite:
|
|
81
|
+
files, classes, functions, edges, data access, entry points, request inputs, side effects.
|
|
82
|
+
3. **Analyse** the IR: inventory, dependency/call graphs, entry points and their request
|
|
83
|
+
inputs, SQL and CRUD coverage, side effects, complexity metrics, business-rule candidates
|
|
84
|
+
and dead code.
|
|
85
|
+
4. **Explain** selected units with an LLM using a budgeted context builder, with responses cached
|
|
86
|
+
locally. Hosted and local (Ollama) providers are supported.
|
|
87
|
+
5. **Verify** every generated claim, labelling it `verified`, `inferred` or `unsupported`, with
|
|
88
|
+
citations back to source.
|
|
89
|
+
6. **Publish** Markdown documentation, Mermaid diagrams and an MkDocs site from stored facts.
|
|
90
|
+
7. **Answer questions** over the generated docs through a local FastAPI service.
|
|
91
|
+
8. **Evaluate** the three pipeline configurations (static only, static + LLM, static + LLM +
|
|
92
|
+
verification) against manually prepared ground truth.
|
|
93
|
+
|
|
94
|
+
## Publishing (static, no AI)
|
|
95
|
+
|
|
96
|
+
The publisher turns the fact store into a deterministic documentation site. It makes no
|
|
97
|
+
model calls: every page is generated from stored IR facts. The generated page set is:
|
|
98
|
+
|
|
99
|
+
| Page | Contents |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| `index.md` | Project totals, page index and scope |
|
|
102
|
+
| `claims.md` | Verification-labelled claims and their evidence |
|
|
103
|
+
| `architecture.md` | Module dependencies, inheritance, calls and unresolved references |
|
|
104
|
+
| `entry-points.md` | Routes, servlets, filters, actions, JSPs and request inputs |
|
|
105
|
+
| `database.md` | CRUD coverage for every table named in SQL |
|
|
106
|
+
| `side-effects.md` | Filesystem, HTTP, email, process and session effects |
|
|
107
|
+
| `hotspots.md` | Function length, complexity and nesting rankings |
|
|
108
|
+
| `files.md` | Every scanned file with size and declaration counts |
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from legacylenscli.publisher import publish_site
|
|
112
|
+
|
|
113
|
+
result = publish_site(store, ".legacylens/site", build=True)
|
|
114
|
+
print(result.pages, result.built, result.skipped_reason)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`publish_site` writes `docs/*.md`, `docs/javascripts/mermaid.js`, `mkdocs.yml` and a
|
|
118
|
+
manifest used to remove stale pages. MkDocs is optional: without the `site` extra the
|
|
119
|
+
Markdown and configuration are still written and the HTML build is skipped with a reason.
|
|
120
|
+
Diagrams are bounded (60 nodes/120 edges for dependencies and inheritance, 50/100 for
|
|
121
|
+
calls, 40 tables for CRUD) and the pages state when a diagram was truncated.
|
|
122
|
+
|
|
123
|
+
## Evaluation
|
|
124
|
+
|
|
125
|
+
The harness scores the three pipeline configurations against a hand-prepared ground-truth
|
|
126
|
+
file. It is a source-checkout tool: `scripts/` and `evaluation/` are not included in the
|
|
127
|
+
installed wheel.
|
|
128
|
+
|
|
129
|
+
| Configuration | LLM | Verification |
|
|
130
|
+
| --- | --- | --- |
|
|
131
|
+
| `static_only` | no | no |
|
|
132
|
+
| `llm_no_verification` | yes | no |
|
|
133
|
+
| `full_pipeline` | yes | yes |
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
uv run python scripts/run_evaluation.py tests/fixtures/legacy_web
|
|
137
|
+
# live LLM configurations are opt-in
|
|
138
|
+
uv run python scripts/run_evaluation.py path/to/app \
|
|
139
|
+
--ground-truth evaluation/ground_truth/app.json \
|
|
140
|
+
--provider openai --model gpt-4o-mini --max-targets 20
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Ground truth lives in `evaluation/ground_truth/<app>.json` and is validated strictly; see
|
|
144
|
+
[`evaluation/ground_truth/README.md`](https://github.com/Kay-pereira/legacylens/blob/main/evaluation/ground_truth/README.md).
|
|
145
|
+
Each configuration uses an isolated SQLite store, so cached completions and generated claims
|
|
146
|
+
cannot leak between runs. Results are written to `evaluation/results/<app>.json`.
|
|
147
|
+
|
|
148
|
+
Metrics are precision/recall/F1 over entry points, table/operation pairs and business-rule
|
|
149
|
+
evidence, plus claim status counts and verification rates. Usage reporting separates
|
|
150
|
+
`estimated_cost_usd` (provider cost for every completion, including cache hits) from
|
|
151
|
+
`billable_cost_usd` (cache misses only), alongside prompt/completion tokens and cache hit
|
|
152
|
+
rate. Without a provider the script runs `static_only` and makes no network calls.
|
|
153
|
+
|
|
154
|
+
## Asking questions locally
|
|
155
|
+
|
|
156
|
+
The Q&A service retrieves over two corpora and answers with citations:
|
|
157
|
+
|
|
158
|
+
- the eight generated documentation pages, rebuilt in memory from the IR at startup, or a
|
|
159
|
+
published Markdown directory passed with `--docs`;
|
|
160
|
+
- one structured passage per file, class, function, table, entry point and publishable
|
|
161
|
+
claim, using the same citations the verifier understands.
|
|
162
|
+
|
|
163
|
+
Ranking is dependency-free BM25 with weighted title/section/citation/body fields, exact
|
|
164
|
+
symbol and path boosts, and filters for passage kind and documentation page. Extractive
|
|
165
|
+
answers are the offline default. LLM mode uses the cached completion layer and validates
|
|
166
|
+
every returned citation against the evidence supplied to the model: a citation outside that
|
|
167
|
+
set is reported as unresolved and can never silently become support.
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
python -m legacylenscli.qa --db .legacylens/legacylens.db --port 8000
|
|
171
|
+
# optional: index a published docs tree and enable hosted synthesis
|
|
172
|
+
python -m legacylenscli.qa --db .legacylens/legacylens.db --docs .legacylens/site/docs \
|
|
173
|
+
--provider openai --model gpt-4o-mini
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Open `http://127.0.0.1:8000`. The interface has kind/page filters, expandable evidence with
|
|
177
|
+
matched terms, citation links, copy actions and an explicit status badge:
|
|
178
|
+
|
|
179
|
+
| Status | Meaning |
|
|
180
|
+
| --- | --- |
|
|
181
|
+
| `verified` | Every returned citation belongs to the retrieved evidence. |
|
|
182
|
+
| `inferred` | Some citations are unresolved, or the model flagged incomplete evidence. |
|
|
183
|
+
| `unsupported` | No retrieved evidence answers the question. |
|
|
184
|
+
|
|
185
|
+
JSON clients can use `GET /health`, `GET /search?q=...&kind=...&page=...` and
|
|
186
|
+
`POST /ask` with `{"question": "...", "mode": "extractive", "kinds": ["table"]}`. Static
|
|
187
|
+
assets are packaged with the module; the UI loads no CDN resources and binds to
|
|
188
|
+
`127.0.0.1` by default. Answers are not persisted as claims.
|
|
189
|
+
|
|
190
|
+
## Commands
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
legacylenscli analyze --root path/to/legacy-app
|
|
194
|
+
legacylenscli build --root path/to/legacy-app
|
|
195
|
+
legacylenscli serve --root path/to/legacy-app --port 8000
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`analyze` writes the health report, `build` writes the static documentation site and `serve`
|
|
199
|
+
analyses the repository before starting the local Q&A interface.
|
|
200
|
+
|
|
201
|
+
## Layout
|
|
202
|
+
|
|
203
|
+
```
|
|
204
|
+
docs/ IR specification and architecture notes
|
|
205
|
+
src/legacylenscli/
|
|
206
|
+
ingestion/ repository walker, language detection, content hashing
|
|
207
|
+
ir/ dataclass models, SQLite schema, fact store
|
|
208
|
+
parsers/ Tree-sitter PHP / Java / JSP / XML front-ends
|
|
209
|
+
analysis/ inventory, graphs, entry points, SQL, CRUD, side effects, metrics, rules
|
|
210
|
+
llm/ provider interface, context builder, prompts, response cache
|
|
211
|
+
verification/ claim verification and citation resolution
|
|
212
|
+
publisher/ Markdown, diagrams, templates, MkDocs site
|
|
213
|
+
qa/ retrieval and local FastAPI server
|
|
214
|
+
evaluation/ metrics and pipeline runner
|
|
215
|
+
tests/ unit, integration and hand-written PHP/Java fixtures
|
|
216
|
+
corpus/ gitignored; scripts fetch sample legacy apps
|
|
217
|
+
evaluation/ ground truth and result artefacts
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Development
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
uv sync
|
|
224
|
+
uv run pytest
|
|
225
|
+
uv run ruff check src tests
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Build and validate the distribution locally:
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
uv build
|
|
232
|
+
uv run twine check dist/*
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Releasing
|
|
236
|
+
|
|
237
|
+
1. Bump `__version__` in `src/legacylenscli/__init__.py` (the single source of truth) and add a
|
|
238
|
+
`CHANGELOG.md` entry.
|
|
239
|
+
2. Merge to `main`, then publish a GitHub release tagged with the same version (for example
|
|
240
|
+
`v0.1.0`).
|
|
241
|
+
3. The `release` workflow builds the sdist and wheel, checks them with Twine and publishes to
|
|
242
|
+
PyPI through trusted publishing. Configure the PyPI trusted publisher for repository
|
|
243
|
+
`Kay-pereira/legacylens`, workflow `release.yml`, environment `pypi`.
|
|
244
|
+
|
|
245
|
+
Do not store PyPI tokens in the repository.
|
|
246
|
+
|
|
247
|
+
## Docs
|
|
248
|
+
|
|
249
|
+
- [`docs/ir-spec.md`](https://github.com/Kay-pereira/legacylens/blob/main/docs/ir-spec.md) — IR specification (project deliverable)
|
|
250
|
+
- [`docs/architecture.md`](https://github.com/Kay-pereira/legacylens/blob/main/docs/architecture.md) — pipeline and module design
|
|
251
|
+
|
|
252
|
+
## License
|
|
253
|
+
|
|
254
|
+
MIT
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# LegacyLens
|
|
2
|
+
|
|
3
|
+
AI-assisted static analysis and documentation tool for legacy **PHP** and **Java** web apps.
|
|
4
|
+
|
|
5
|
+
> Status: early implementation. The IR, SQLite fact store, ingestion scanner, hashing,
|
|
6
|
+
> language detection, PHP/Java/JSP/XML parsers, inventory/function metrics (counts, length,
|
|
7
|
+
> complexity, nesting), include/import/inheritance/call graphs, entry points/request inputs,
|
|
8
|
+
> SQL extraction, the CRUD matrix, side effects, the static publisher (Markdown, Mermaid,
|
|
9
|
+
> MkDocs), dead-code detection, business-rule candidates, the aggregate health report, the
|
|
10
|
+
> provider-agnostic LLM layer, claim verification, the local Q&A service and the evaluation
|
|
11
|
+
> harness are in place. The `legacylenscli` command exposes `analyze`, `build` and `serve`.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install legacylenscli
|
|
17
|
+
# with the optional MkDocs build
|
|
18
|
+
pip install "legacylenscli[site]"
|
|
19
|
+
# or
|
|
20
|
+
uv add legacylenscli
|
|
21
|
+
uv add "legacylenscli[site]"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The PyPI distribution, import package and installed command are all **`legacylenscli`**.
|
|
25
|
+
The name avoids the existing `legacylens` project on PyPI:
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
import legacylenscli
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Requires Python 3.12 or 3.13. The installed `legacylenscli` command provides `analyze`, `build`
|
|
32
|
+
and `serve`; the local Q&A interface is also available through `python -m legacylenscli.qa`.
|
|
33
|
+
|
|
34
|
+
## What it does
|
|
35
|
+
|
|
36
|
+
1. **Ingest** a legacy repository, detecting PHP, Java, JSP and deployment descriptors.
|
|
37
|
+
2. **Extract facts** with Tree-sitter into a flat intermediate representation (IR) stored in SQLite:
|
|
38
|
+
files, classes, functions, edges, data access, entry points, request inputs, side effects.
|
|
39
|
+
3. **Analyse** the IR: inventory, dependency/call graphs, entry points and their request
|
|
40
|
+
inputs, SQL and CRUD coverage, side effects, complexity metrics, business-rule candidates
|
|
41
|
+
and dead code.
|
|
42
|
+
4. **Explain** selected units with an LLM using a budgeted context builder, with responses cached
|
|
43
|
+
locally. Hosted and local (Ollama) providers are supported.
|
|
44
|
+
5. **Verify** every generated claim, labelling it `verified`, `inferred` or `unsupported`, with
|
|
45
|
+
citations back to source.
|
|
46
|
+
6. **Publish** Markdown documentation, Mermaid diagrams and an MkDocs site from stored facts.
|
|
47
|
+
7. **Answer questions** over the generated docs through a local FastAPI service.
|
|
48
|
+
8. **Evaluate** the three pipeline configurations (static only, static + LLM, static + LLM +
|
|
49
|
+
verification) against manually prepared ground truth.
|
|
50
|
+
|
|
51
|
+
## Publishing (static, no AI)
|
|
52
|
+
|
|
53
|
+
The publisher turns the fact store into a deterministic documentation site. It makes no
|
|
54
|
+
model calls: every page is generated from stored IR facts. The generated page set is:
|
|
55
|
+
|
|
56
|
+
| Page | Contents |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| `index.md` | Project totals, page index and scope |
|
|
59
|
+
| `claims.md` | Verification-labelled claims and their evidence |
|
|
60
|
+
| `architecture.md` | Module dependencies, inheritance, calls and unresolved references |
|
|
61
|
+
| `entry-points.md` | Routes, servlets, filters, actions, JSPs and request inputs |
|
|
62
|
+
| `database.md` | CRUD coverage for every table named in SQL |
|
|
63
|
+
| `side-effects.md` | Filesystem, HTTP, email, process and session effects |
|
|
64
|
+
| `hotspots.md` | Function length, complexity and nesting rankings |
|
|
65
|
+
| `files.md` | Every scanned file with size and declaration counts |
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from legacylenscli.publisher import publish_site
|
|
69
|
+
|
|
70
|
+
result = publish_site(store, ".legacylens/site", build=True)
|
|
71
|
+
print(result.pages, result.built, result.skipped_reason)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`publish_site` writes `docs/*.md`, `docs/javascripts/mermaid.js`, `mkdocs.yml` and a
|
|
75
|
+
manifest used to remove stale pages. MkDocs is optional: without the `site` extra the
|
|
76
|
+
Markdown and configuration are still written and the HTML build is skipped with a reason.
|
|
77
|
+
Diagrams are bounded (60 nodes/120 edges for dependencies and inheritance, 50/100 for
|
|
78
|
+
calls, 40 tables for CRUD) and the pages state when a diagram was truncated.
|
|
79
|
+
|
|
80
|
+
## Evaluation
|
|
81
|
+
|
|
82
|
+
The harness scores the three pipeline configurations against a hand-prepared ground-truth
|
|
83
|
+
file. It is a source-checkout tool: `scripts/` and `evaluation/` are not included in the
|
|
84
|
+
installed wheel.
|
|
85
|
+
|
|
86
|
+
| Configuration | LLM | Verification |
|
|
87
|
+
| --- | --- | --- |
|
|
88
|
+
| `static_only` | no | no |
|
|
89
|
+
| `llm_no_verification` | yes | no |
|
|
90
|
+
| `full_pipeline` | yes | yes |
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
uv run python scripts/run_evaluation.py tests/fixtures/legacy_web
|
|
94
|
+
# live LLM configurations are opt-in
|
|
95
|
+
uv run python scripts/run_evaluation.py path/to/app \
|
|
96
|
+
--ground-truth evaluation/ground_truth/app.json \
|
|
97
|
+
--provider openai --model gpt-4o-mini --max-targets 20
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Ground truth lives in `evaluation/ground_truth/<app>.json` and is validated strictly; see
|
|
101
|
+
[`evaluation/ground_truth/README.md`](https://github.com/Kay-pereira/legacylens/blob/main/evaluation/ground_truth/README.md).
|
|
102
|
+
Each configuration uses an isolated SQLite store, so cached completions and generated claims
|
|
103
|
+
cannot leak between runs. Results are written to `evaluation/results/<app>.json`.
|
|
104
|
+
|
|
105
|
+
Metrics are precision/recall/F1 over entry points, table/operation pairs and business-rule
|
|
106
|
+
evidence, plus claim status counts and verification rates. Usage reporting separates
|
|
107
|
+
`estimated_cost_usd` (provider cost for every completion, including cache hits) from
|
|
108
|
+
`billable_cost_usd` (cache misses only), alongside prompt/completion tokens and cache hit
|
|
109
|
+
rate. Without a provider the script runs `static_only` and makes no network calls.
|
|
110
|
+
|
|
111
|
+
## Asking questions locally
|
|
112
|
+
|
|
113
|
+
The Q&A service retrieves over two corpora and answers with citations:
|
|
114
|
+
|
|
115
|
+
- the eight generated documentation pages, rebuilt in memory from the IR at startup, or a
|
|
116
|
+
published Markdown directory passed with `--docs`;
|
|
117
|
+
- one structured passage per file, class, function, table, entry point and publishable
|
|
118
|
+
claim, using the same citations the verifier understands.
|
|
119
|
+
|
|
120
|
+
Ranking is dependency-free BM25 with weighted title/section/citation/body fields, exact
|
|
121
|
+
symbol and path boosts, and filters for passage kind and documentation page. Extractive
|
|
122
|
+
answers are the offline default. LLM mode uses the cached completion layer and validates
|
|
123
|
+
every returned citation against the evidence supplied to the model: a citation outside that
|
|
124
|
+
set is reported as unresolved and can never silently become support.
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
python -m legacylenscli.qa --db .legacylens/legacylens.db --port 8000
|
|
128
|
+
# optional: index a published docs tree and enable hosted synthesis
|
|
129
|
+
python -m legacylenscli.qa --db .legacylens/legacylens.db --docs .legacylens/site/docs \
|
|
130
|
+
--provider openai --model gpt-4o-mini
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Open `http://127.0.0.1:8000`. The interface has kind/page filters, expandable evidence with
|
|
134
|
+
matched terms, citation links, copy actions and an explicit status badge:
|
|
135
|
+
|
|
136
|
+
| Status | Meaning |
|
|
137
|
+
| --- | --- |
|
|
138
|
+
| `verified` | Every returned citation belongs to the retrieved evidence. |
|
|
139
|
+
| `inferred` | Some citations are unresolved, or the model flagged incomplete evidence. |
|
|
140
|
+
| `unsupported` | No retrieved evidence answers the question. |
|
|
141
|
+
|
|
142
|
+
JSON clients can use `GET /health`, `GET /search?q=...&kind=...&page=...` and
|
|
143
|
+
`POST /ask` with `{"question": "...", "mode": "extractive", "kinds": ["table"]}`. Static
|
|
144
|
+
assets are packaged with the module; the UI loads no CDN resources and binds to
|
|
145
|
+
`127.0.0.1` by default. Answers are not persisted as claims.
|
|
146
|
+
|
|
147
|
+
## Commands
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
legacylenscli analyze --root path/to/legacy-app
|
|
151
|
+
legacylenscli build --root path/to/legacy-app
|
|
152
|
+
legacylenscli serve --root path/to/legacy-app --port 8000
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
`analyze` writes the health report, `build` writes the static documentation site and `serve`
|
|
156
|
+
analyses the repository before starting the local Q&A interface.
|
|
157
|
+
|
|
158
|
+
## Layout
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
docs/ IR specification and architecture notes
|
|
162
|
+
src/legacylenscli/
|
|
163
|
+
ingestion/ repository walker, language detection, content hashing
|
|
164
|
+
ir/ dataclass models, SQLite schema, fact store
|
|
165
|
+
parsers/ Tree-sitter PHP / Java / JSP / XML front-ends
|
|
166
|
+
analysis/ inventory, graphs, entry points, SQL, CRUD, side effects, metrics, rules
|
|
167
|
+
llm/ provider interface, context builder, prompts, response cache
|
|
168
|
+
verification/ claim verification and citation resolution
|
|
169
|
+
publisher/ Markdown, diagrams, templates, MkDocs site
|
|
170
|
+
qa/ retrieval and local FastAPI server
|
|
171
|
+
evaluation/ metrics and pipeline runner
|
|
172
|
+
tests/ unit, integration and hand-written PHP/Java fixtures
|
|
173
|
+
corpus/ gitignored; scripts fetch sample legacy apps
|
|
174
|
+
evaluation/ ground truth and result artefacts
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Development
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
uv sync
|
|
181
|
+
uv run pytest
|
|
182
|
+
uv run ruff check src tests
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Build and validate the distribution locally:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
uv build
|
|
189
|
+
uv run twine check dist/*
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Releasing
|
|
193
|
+
|
|
194
|
+
1. Bump `__version__` in `src/legacylenscli/__init__.py` (the single source of truth) and add a
|
|
195
|
+
`CHANGELOG.md` entry.
|
|
196
|
+
2. Merge to `main`, then publish a GitHub release tagged with the same version (for example
|
|
197
|
+
`v0.1.0`).
|
|
198
|
+
3. The `release` workflow builds the sdist and wheel, checks them with Twine and publishes to
|
|
199
|
+
PyPI through trusted publishing. Configure the PyPI trusted publisher for repository
|
|
200
|
+
`Kay-pereira/legacylens`, workflow `release.yml`, environment `pypi`.
|
|
201
|
+
|
|
202
|
+
Do not store PyPI tokens in the repository.
|
|
203
|
+
|
|
204
|
+
## Docs
|
|
205
|
+
|
|
206
|
+
- [`docs/ir-spec.md`](https://github.com/Kay-pereira/legacylens/blob/main/docs/ir-spec.md) — IR specification (project deliverable)
|
|
207
|
+
- [`docs/architecture.md`](https://github.com/Kay-pereira/legacylens/blob/main/docs/architecture.md) — pipeline and module design
|
|
208
|
+
|
|
209
|
+
## License
|
|
210
|
+
|
|
211
|
+
MIT
|