Repository navigation
Description
Part of #3122.
Found by a design review of gitgalaxy/metrics/archetype_classifier.py, the baked brains in gitgalaxy/standards/archetype_brains/, and gitgalaxy/metrics/statistical_auditor.py.
The problem
The industry's standing failure mode for legacy migration is transpiled code no human will own — Java that is structurally COBOL with Java keywords, which technically "migrates" while trapping the customer worse than before. The suite has no way to detect this today.
#3121 adds a compile gate. Compiling is necessary and says nothing about whether the output looks like code a Java team would maintain. This is the third verification rung:
compiles → runs → looks native
The key insight: the engine already ships the classifier for this
gitgalaxy/standards/archetype_brains/file_archetype_brain.json and repo_archetype_brain.json are baked, corpus-trained k-means artifacts, loaded at gitgalaxy/standards/analysis_lens.py:33-34. Unlike the statistical auditor (see the alternative below) they are already external — committed, not derived from the scan under test — and already vector rather than scalar.
classify_file(gitgalaxy/metrics/archetype_classifier.py:54) builds a 23-dimensional feature vector: 14 stoichiometric function-archetype proportions scaled bystoich_weight, plus 9 quantile-ranked aux features —log_coding_loc,log_function_count,log_class_count,log_import_count,encapsulation_ratio,doc_ratio,control_flow_ratio,log_pagerank,log_blast_radius. It takes the nearest ofk=15centroids and returns(composition_archetype, fit_z_score)via_fit_z.classify_repo(:98) aggregates per-file composition archetypes plus scale (log_file_count,log_total_loc), noncode fraction, and coupling (pagerank gini) into a repo-level archetype + drift z.
The discriminator is already in the centroid names
The file brain's 15 buckets include the native-framework-shaped Annotated Framework Methods Files, Interface Declarations Files, Encapsulated Accessors Files, Callbacks & Closures Files, Generic / Templated Code Files — and the procedural/mainframe-shaped I/O & Config Routines Files, State Mutators Files, Many-Argument Workhorses Files.
Empirical evidence the separation is real
From a scan of IBM's zopeneditor-sample (COBOL/PL-I/JCL/HLASM/REXX), per-file composition_file_archetype:
| language | buckets assigned |
|---|---|
| cobol | I/O & Config Routines Files (5), Declarative / Non-Code (6), Data / Markup / Trivial (2) |
| pli | I/O & Config Routines Files (2), Many-Argument Workhorses Files (1) |
| jcl | I/O & Config Routines Files (7), Interface Declarations Files (2), Data / Markup / Trivial (1) |
| hlasm | I/O & Config Routines Files (1) |
PLI/PSAM2.pli classifies as Many-Argument Workhorses Files (z -0.164).
The load-bearing result: across every mainframe-language file in the repo, the count landing in a framework-shaped bucket is zero — Annotated Framework Methods Files 0, Encapsulated Accessors Files 0, Callbacks & Closures Files 0, Generic / Templated Code Files 0, Compute Cores Files 0. Mainframe-shaped code lands in mainframe-shaped buckets and nowhere near the framework ones.
The repo-level verdict is Assigned Ecosystem Baseline: Mainframe / COBOL & Config, with an architectural drift z of -0.592 on the five-language scan of main. (A re-scan on a checkout without the rexx profile returns the same label at z -0.426 — the label is the stable signal, the z moves with corpus content. Design point 4 below should lean on the label.)
If generated Java lands in the procedural buckets rather than the framework ones, that is the failure mode — already measured, by a shipped classifier.
Requested design
- Scan a native Spring Boot reference corpus to establish the expected archetype-mix distribution and repo-level composition archetype for idiomatic modern Java.
- Scan the generated project and compute the distance between its mix and that reference — the "nativeness" score.
- Per-file, name the specific offenders: generated units landing in procedural/mainframe-shaped buckets are the files a developer should look at first.
- Surface a one-line verdict where a non-engineer can read it.
classify_repomay give this outright: if generated Java is assigned a mainframe ecosystem baseline instead of a Java/Spring one, the migration failed its style test in a single sentence.
Alternative/complementary mechanism, recorded so it is not re-derived
statistical_auditor.py has the right robust-statistics machinery — per-language median/MAD with a modified z-score (0.6745 * (rho - median_rho)) / mad (:450) — but two properties make it unsuitable as-is:
- Its baseline is self-referential.
median_rhoandmadare computed from the group being audited, in-scan (:385-387). A corpus of 200 generated files would have the generated style AS its median and read as perfectly healthy. It answers "which file is unlike its siblings", never "is this population unlike real Java". - Its
rhois scalar —signal_hits / total_physical_loc(:358-360). A file can have wholly normal total density with a wildly abnormal signal composition (highstate_mutation, near-zeroclosures/generics/comprehensions), which is exactly the failure shape.
Generalizing the auditor to accept committed cross-scan baselines and a vector rho is independently useful — it would also answer "is this customer's Python unusual versus the world" — but the archetype path is preferred here because it is already external and already vector.
Also note its gates would skip statistics entirely on a small generated project: population density N >= 50 (:373-374) and cohesion R-MAD < 1.0.
Prerequisites / sequencing
- CI: compile the generated Spring Boot output (no Java toolchain in CI today) #3121 should land first — uncompilable output makes style moot.
- A native Spring Boot reference corpus must be sourced and pinned.
- Archetype brains carry no training provenance #3124 is a hard prerequisite for making the claim publicly. A conformance verdict is only as credible as the corpus behind the brain, and today that corpus is unrecorded.
- If a Java-specific brain is trained rather than reusing the general one, the feature-dimension parity check between engine, model and trainer is CRITICAL — the
train-archetypesskill flags it as such, and it is the drift class behind File-level K-Means archetype classification silently truncates against its own trained models (115-dim global vs. 83-dim live vector) #1158 (115-dim global vs 83-dim live vector) and its epic Epic: K-Means archetype clustering (function/file/repo) has drifted out of sync with its own live feature pipeline #1160, which predated the v2.8.1 self-describing file brain. See also File-level: retrain per-language ("local") archetype model — needs a broader corpus #3085, the still-open per-language ("local micro-species") model, for why corpus breadth gates this kind of work.
Commercial note
Of the three rungs, this is the only one no competitor can claim, because it requires a cross-language archetype model none of them has. "Our generated code is statistically indistinguishable from hand-written Spring Boot, and here is the z-score" is a materially sharper claim than "it compiles."
Activity