Nucleus-Resynthesis / runtime /src /resynthesis /language_experts.py
Wl6adams's picture
Add portable Release 188 generation runtime
919fd68 verified
Raw
History Blame Contribute Delete
19.2 kB
"""Declarative NoNE language-expert catalog.
These rows are capability identities and page-training objectives, not claims
that a language expert has already been trained. A family becomes promotable
only after the normal NoNE route, gradient, held-out, retention, and cold-reload
proofs pass.
"""
from __future__ import annotations
import hashlib
from typing import Final
from resynthesis.language_catalog import (
BROAD_LANGUAGE_PACK_IDS,
BROAD_LANGUAGE_PACK_IDS_SHA256,
LANGUAGE_ABILITY_AXIS_IDS,
LANGUAGE_ABILITY_IDS_BY_SOURCE_TYPE,
LINGUIST_LANGUAGE_SOURCE_PACK_RECORDS,
NATIVE_LANGUAGE_PACK_PREFIX_IDS,
)
NONE_LANGUAGE_EXPERT_CATALOG_SCHEMA: Final = (
"nnf.resynthesis.none_language_expert_catalog.v4"
)
_LANGUAGE_EXPERT_SPECS: Final[
tuple[tuple[str, str, str, tuple[str, ...]], ...]
] = (
(
"language_python",
"Python",
"CPython, typing, asyncio, packaging, data, and scientific computing",
("python", "py", "python_source"),
),
(
"language_go",
"Go",
"modules, interfaces, goroutines, channels, services, and tooling",
("go", "golang", "go_source"),
),
(
"language_java",
"Java",
"JVM behavior, generics, concurrency, Maven, Gradle, and services",
("java", "jvm_java", "java_source"),
),
(
"language_ruby",
"Ruby",
"MRI behavior, gems, metaprogramming, Rails, and services",
("ruby", "ruby_source", "rails"),
),
(
"language_php",
"PHP",
"Composer, PHP runtimes, Laravel, Symfony, and web applications",
("php", "php_source", "composer_php"),
),
(
"language_dotnet",
".NET",
"CLR semantics, assemblies, NuGet, MSBuild, ASP.NET, and interop",
("dotnet", "clr", "msbuild", "nuget"),
),
(
"language_native",
"Native systems",
"ABIs, linking, FFI, ownership, concurrency, and platform toolchains",
("native", "native_code", "abi", "system_programming"),
),
(
"language_c",
"C",
"standards, pointers, layouts, preprocessors, compilers, and embedded code",
("c", "c_source", "iso_c"),
),
(
"language_cpp",
"C++",
"templates, RAII, modern standards, CMake, ABI, and performance",
("cpp", "c++", "cplusplus", "cpp_source"),
),
(
"language_rust",
"Rust",
"ownership, lifetimes, traits, Cargo, async, unsafe code, and FFI",
("rust", "rust_source", "cargo"),
),
(
"language_csharp",
"C#",
"CLR types, LINQ, async, Roslyn, .NET libraries, and applications",
("csharp", "c#", "c_sharp"),
),
(
"language_fsharp",
"F#",
"functional .NET, algebraic types, computation expressions, and interop",
("fsharp", "f#", "f_sharp"),
),
(
"language_visual_basic",
"Visual Basic",
"VB.NET, legacy Visual Basic, COM, forms, and .NET interop",
("visual_basic", "vb", "vbnet"),
),
(
"language_javascript",
"JavaScript",
"ECMAScript, browser and Node runtimes, events, modules, and services",
("javascript", "js", "ecmascript", "nodejs"),
),
(
"language_typescript",
"TypeScript",
"structural typing, compiler configuration, declarations, and JS interop",
("typescript", "ts", "typescript_source"),
),
(
"language_swift",
"Swift",
"value semantics, protocols, concurrency, SwiftPM, Apple, and servers",
("swift", "swift_source", "swiftpm"),
),
(
"language_objective_c",
"Objective-C",
"runtime messaging, ARC, Cocoa, C interop, and mixed Apple codebases",
("objective_c", "objective-c", "objc"),
),
(
"language_kotlin",
"Kotlin",
"JVM and native targets, coroutines, Gradle, Android, and multiplatform",
("kotlin", "kotlin_source", "kotlin_multiplatform"),
),
(
"language_scala",
"Scala",
"JVM functional and object models, implicits, sbt, and data systems",
("scala", "scala_source", "sbt"),
),
(
"language_dart",
"Dart",
"sound typing, async execution, packages, Flutter, web, and native",
("dart", "dart_source", "flutter"),
),
(
"language_lua",
"Lua",
"tables, metatables, coroutines, embedding, LuaJIT, and scripting",
("lua", "lua_source", "luajit"),
),
(
"language_perl",
"Perl",
"references, regex processing, CPAN, automation, and legacy services",
("perl", "perl_source", "cpan"),
),
(
"language_r",
"R",
"vectors, statistical modeling, packages, data frames, and visualization",
("r", "r_source", "rstats"),
),
(
"language_julia",
"Julia",
"multiple dispatch, numerical computing, environments, and performance",
("julia", "julia_source", "julia_language"),
),
(
"language_matlab",
"MATLAB",
"matrix computing, toolboxes, Simulink, and numerical workflows",
("matlab", "matlab_source", "simulink"),
),
(
"language_sas",
"SAS",
"DATA steps, procedures, macros, analytics, and clinical workflows",
("sas", "sas_source", "sas_macro"),
),
(
"language_sql",
"SQL",
"relational schemas, queries, transactions, tuning, and dialect interop",
("sql", "sql_source", "relational_query"),
),
(
"language_html",
"HTML",
"semantic markup, accessibility, forms, parsing, and templates",
("html", "html_source", "web_markup"),
),
(
"language_css",
"CSS",
"cascade, layout, responsive design, animation, and browser behavior",
("css", "css_source", "stylesheets"),
),
(
"language_graphql",
"GraphQL",
"schemas, queries, resolvers, federation, clients, and API evolution",
("graphql", "graphql_source", "graphql_schema"),
),
(
"language_bash",
"Bash and POSIX shell",
"expansion, pipelines, process control, portability, and automation",
("bash", "shell", "posix_shell", "shell_script"),
),
(
"language_powershell",
"PowerShell",
"object pipelines, modules, remoting, administration, and automation",
("powershell", "pwsh", "powershell_source"),
),
(
"language_haskell",
"Haskell",
"lazy evaluation, type classes, monads, effects, Cabal, and Stack",
("haskell", "haskell_source", "cabal"),
),
(
"language_ocaml",
"OCaml",
"modules, algebraic types, pattern matching, effects, and dune",
("ocaml", "ocaml_source", "dune_ocaml"),
),
(
"language_clojure",
"Clojure",
"persistent data, macros, sequences, concurrency, and JVM interop",
("clojure", "clojure_source", "clj"),
),
(
"language_elixir",
"Elixir",
"BEAM processes, OTP, supervision, Mix, Phoenix, and distribution",
("elixir", "elixir_source", "mix_elixir"),
),
(
"language_erlang",
"Erlang",
"BEAM semantics, OTP behaviors, supervision, messaging, and resilience",
("erlang", "erlang_source", "beam_erlang"),
),
(
"language_scheme",
"Scheme",
"lexical scope, continuations, macros, interpreters, and reasoning",
("scheme", "scheme_source", "r7rs"),
),
(
"language_common_lisp",
"Common Lisp",
"CLOS, macros, conditions, packages, interactive work, and compilation",
("common_lisp", "common-lisp", "lisp"),
),
(
"language_prolog",
"Prolog",
"unification, backtracking, constraints, logic programs, and symbols",
("prolog", "prolog_source", "logic_programming"),
),
(
"language_groovy",
"Groovy",
"dynamic JVM semantics, closures, Gradle DSLs, tests, and Java interop",
("groovy", "groovy_source", "gradle_groovy"),
),
(
"language_fortran",
"Fortran",
"arrays, modules, numerical kernels, interoperability, and HPC",
("fortran", "fortran_source", "modern_fortran"),
),
(
"language_assembly",
"Assembly",
"instructions, calling conventions, registers, linking, and debugging",
("assembly", "asm", "machine_assembly"),
),
(
"language_cuda",
"CUDA",
"kernels, memory hierarchy, synchronization, streams, and profiling",
("cuda", "cuda_source", "cuda_kernel"),
),
(
"language_opencl",
"OpenCL",
"portable kernels, devices, memory spaces, synchronization, and interop",
("opencl", "opencl_source", "opencl_kernel"),
),
(
"language_webassembly",
"WebAssembly",
"modules, linear memory, WASI, components, toolchains, and embedding",
("webassembly", "wasm", "wasi"),
),
(
"language_zig",
"Zig",
"comptime, explicit allocation, build tooling, C interop, and systems",
("zig", "zig_source", "ziglang"),
),
(
"language_nim",
"Nim",
"macros, generics, memory management, native compilation, and C interop",
("nim", "nim_source", "nim_lang"),
),
(
"language_apex",
"Apex",
"Salesforce data, triggers, limits, testing, and deployment",
("apex", "salesforce_apex", "apex_source"),
),
(
"language_verilog",
"Verilog",
"RTL, simulation, synthesis, testbenches, timing, and interfaces",
("verilog", "verilog_source", "rtl_verilog"),
),
(
"language_systemverilog",
"SystemVerilog",
"RTL, assertions, interfaces, UVM, simulation, and synthesis",
("systemverilog", "system_verilog", "uvm"),
),
(
"language_vhdl",
"VHDL",
"typed RTL, simulation, synthesis, testbenches, and hardware packages",
("vhdl", "vhdl_source", "rtl_vhdl"),
),
(
"language_cobol",
"COBOL",
"divisions, records, files, transactions, mainframes, and modernization",
("cobol", "cobol_source", "mainframe_cobol"),
),
(
"language_ada",
"Ada",
"typing, contracts, tasks, packages, safety-critical systems, and SPARK",
("ada", "ada_source", "spark_ada"),
),
(
"language_pascal",
"Pascal and Object Pascal",
"structured programs, units, classes, Delphi, and native applications",
("pascal", "object_pascal", "delphi"),
),
(
"language_tcl",
"Tcl",
"commands, substitutions, event loops, Tk, embedding, and EDA",
("tcl", "tcl_source", "tcl_tk"),
),
(
"language_solidity",
"Solidity",
"EVM semantics, contracts, storage, testing, security, and upgrades",
("solidity", "solidity_source", "evm"),
),
(
"language_move",
"Move",
"resources, modules, bytecode, verification, and blockchain applications",
("move", "move_source", "move_language"),
),
(
"language_hcl",
"HashiCorp Configuration Language",
"infrastructure, expressions, modules, Terraform, and provider schemas",
("hcl", "terraform_hcl", "terraform"),
),
(
"language_nix",
"Nix",
"pure expressions, derivations, flakes, reproducible builds, and systems",
("nix", "nix_language", "nix_flakes"),
),
)
def _build_curated_language_expert_families(
specs: tuple[tuple[str, str, str, tuple[str, ...]], ...],
) -> tuple[tuple[str, str, frozenset[str]], ...]:
"""Validate and materialize the inherited curated prefix once."""
family_ids = tuple(spec[0] for spec in specs)
if len(family_ids) < 60 or len(set(family_ids)) != len(family_ids):
raise RuntimeError("language expert catalog is incomplete or duplicated")
if any(not family_id.startswith("language_") for family_id in family_ids):
raise RuntimeError("language expert family IDs require language_ prefix")
return tuple(
(
family_id,
(
f"{display_name} syntax and semantics, idioms, build/test/debug "
f"workflows, interoperability, security, performance, and {focus}"
),
frozenset((family_id, *aliases)),
)
for family_id, display_name, focus, aliases in specs
)
_CURATED_LANGUAGE_EXPERT_FAMILIES: Final = _build_curated_language_expert_families(
_LANGUAGE_EXPERT_SPECS
)
_CURATED_LANGUAGE_EXPERT_IDS: Final = tuple(
family_id
for family_id, _description, _claims in _CURATED_LANGUAGE_EXPERT_FAMILIES
)
NONE_LANGUAGE_EXPERT_INHERITED_CATALOG_SCHEMA: Final = (
"nnf.resynthesis.none_language_expert_catalog.v1"
)
NONE_LANGUAGE_EXPERT_INHERITED_PREFIX_COUNT: Final = len(
_CURATED_LANGUAGE_EXPERT_IDS
)
NONE_LANGUAGE_EXPERT_INHERITED_PREFIX_IDS_SHA256: Final = hashlib.sha256(
"\n".join(_CURATED_LANGUAGE_EXPERT_IDS).encode("utf-8")
).hexdigest()
if (
_CURATED_LANGUAGE_EXPERT_IDS
!= NATIVE_LANGUAGE_PACK_PREFIX_IDS[: len(_CURATED_LANGUAGE_EXPERT_IDS)]
):
raise RuntimeError("curated language experts are not the native catalog prefix")
_LINGUIST_METADATA_BY_FAMILY_ID: Final = {
family_id: (source_name, source_type)
for family_id, source_name, source_type in reversed(
LINGUIST_LANGUAGE_SOURCE_PACK_RECORDS
)
}
_ABILITY_IDS_BY_SOURCE_TYPE: Final = dict(
LANGUAGE_ABILITY_IDS_BY_SOURCE_TYPE
)
_NATIVE_PREFIX_ORDINAL_BY_ID: Final = {
family_id: ordinal
for ordinal, family_id in enumerate(NATIVE_LANGUAGE_PACK_PREFIX_IDS)
}
def _native_domain_ability_ids(family_id: str) -> frozenset[str]:
"""Return additive ability objectives for the frozen native graph row."""
ordinal = _NATIVE_PREFIX_ORDINAL_BY_ID.get(family_id)
if ordinal is None:
return frozenset()
if 173 <= ordinal < 197:
return frozenset(
{
"serialization_exchange",
"numerical_stability_units",
"chemical_structure_reaction_validation",
"scientific_data_mesh_geometry",
"simulation_boundary_conditions",
}
)
if 197 <= ordinal < 221:
return frozenset(
{
"serialization_exchange",
"systems_biology_simulation",
"clinical_regulatory_validation",
"workflow_provenance_orchestration",
}
)
if 221 <= ordinal < 245:
return frozenset(
{
"numerical_stability_units",
"probabilistic_inference_optimization",
"scientific_data_mesh_geometry",
"simulation_boundary_conditions",
"data_visualization_reporting",
}
)
if 245 <= ordinal < 269:
return frozenset(
{
"numerical_stability_units",
"probabilistic_inference_optimization",
"accelerator_parallel_lowering",
"hardware_hdl_verification",
"quantum_circuit_pulse_validation",
}
)
if 269 <= ordinal < 279:
return frozenset({"formal_proof_model_check"})
if 279 <= ordinal < 289:
return frozenset(
{
"workflow_provenance_orchestration",
"laboratory_robotics_control",
}
)
if 289 <= ordinal:
return frozenset(
{
"serialization_exchange",
"numerical_stability_units",
"laboratory_robotics_control",
"scientific_data_mesh_geometry",
"simulation_boundary_conditions",
}
)
return frozenset()
def _language_ability_ids(
family_id: str,
source_type: str,
) -> tuple[str, ...]:
ability_ids = frozenset(
_ABILITY_IDS_BY_SOURCE_TYPE.get(
source_type,
_ABILITY_IDS_BY_SOURCE_TYPE["programming"],
)
).union(_native_domain_ability_ids(family_id))
return tuple(
ability_id
for ability_id in LANGUAGE_ABILITY_AXIS_IDS
if ability_id in ability_ids
)
def _recovered_language_family(
family_id: str,
) -> tuple[str, str, frozenset[str]]:
metadata = _LINGUIST_METADATA_BY_FAMILY_ID.get(family_id)
if metadata is None:
source_name = family_id.removeprefix("language_").replace("_", " ")
source_type = "programming"
provenance = "the immutable native Resynthesis language graph"
else:
source_name, source_type = metadata
provenance = "the pinned GitHub Linguist source snapshot"
ability_ids = _language_ability_ids(family_id, source_type)
return (
family_id,
(
f"{source_name} {source_type} syntax and semantics, parsing, "
"verification, implementation, interoperability, migration, "
f"and production operation; identity recovered from {provenance}"
),
frozenset((family_id, *ability_ids)),
)
_CURATED_LANGUAGE_FAMILY_BY_ID: Final = {
family_id: (family_id, description, claims)
for family_id, description, claims in _CURATED_LANGUAGE_EXPERT_FAMILIES
}
NONE_LANGUAGE_EXPERT_FAMILIES: Final = tuple(
_CURATED_LANGUAGE_FAMILY_BY_ID.get(
family_id,
_recovered_language_family(family_id),
)
for family_id in BROAD_LANGUAGE_PACK_IDS
)
NONE_LANGUAGE_EXPERT_ABILITY_ASSIGNMENTS: Final = tuple(
(
family_id,
_language_ability_ids(
family_id,
_LINGUIST_METADATA_BY_FAMILY_ID.get(
family_id,
("", "programming"),
)[1],
),
)
for family_id in BROAD_LANGUAGE_PACK_IDS
)
NONE_LANGUAGE_EXPERT_IDS_SHA256: Final = hashlib.sha256(
"\n".join(
family_id
for family_id, _description, _claims in NONE_LANGUAGE_EXPERT_FAMILIES
).encode("utf-8")
).hexdigest()
NONE_LANGUAGE_EXPERT_ABILITY_ASSIGNMENTS_SHA256: Final = hashlib.sha256(
"\n".join(
f"{family_id}:{','.join(ability_ids)}"
for family_id, ability_ids in NONE_LANGUAGE_EXPERT_ABILITY_ASSIGNMENTS
).encode("utf-8")
).hexdigest()
if (
len(NONE_LANGUAGE_EXPERT_FAMILIES) != 936
or NONE_LANGUAGE_EXPERT_IDS_SHA256 != BROAD_LANGUAGE_PACK_IDS_SHA256
or len({row[0] for row in NONE_LANGUAGE_EXPERT_FAMILIES})
!= len(NONE_LANGUAGE_EXPERT_FAMILIES)
or NONE_LANGUAGE_EXPERT_FAMILIES[: len(_CURATED_LANGUAGE_EXPERT_FAMILIES)]
!= _CURATED_LANGUAGE_EXPERT_FAMILIES
or tuple(row[0] for row in NONE_LANGUAGE_EXPERT_ABILITY_ASSIGNMENTS)
!= BROAD_LANGUAGE_PACK_IDS
):
raise RuntimeError("broad language expert catalog identity is invalid")