Skip to main content

Module builtin

Module builtin 

Source
Expand description

The metric catalog, read from metrics/builtin.toml: [categories.*], [ast.*] (tier-1 measured), [fields.*] (derived, each a formula_cel), and the [report] view section (+ [report.stats] aggregate formulas). The crate root re-exports the accessors below; the tier-1 input types (MetricInputs / FunctionUnit) come from code-ranker-plugin-api.

Wire encoding:

  • the executable formula_cel is internal; the emitted AttributeSpec carries formula (from formula_pretty) and calc (from formula_js);
  • name / short fall back to label (a field only spells out what differs);
  • \n in a description (TOML multiline) is encoded as <br> on the wire;
  • the stats block is produced by crate::stats::compute_stats over the keys whose [report.stats] entry is a plain mean (agg('<k>','avg','not_empty')); the richer aggregate formulas are parsed and available but not yet wired into the built-in stats.

Structs§

Views
The canonical view orders read from builtin.toml. columns and featured are flat ordered lists (they may include non-field tokens like kind, cycle and coupling keys); default_sort is the signed-rank list.

Functions§

aggregate_formulas
All [report.stats] formulas (output key → graph-scope CEL). Parsed and available for the future graph-scope aggregate engine; not yet driving the built-in stats block (see stat_keys).
coupling_specs
The coupling/cycle attribute dictionary (fan_in / fan_out / fan_out_external / cycle) + the coupling group, read from builtin.toml [coupling.*]. The VALUES are computed post-walk by annotate_coupling / annotate_cycles; these are the display specs only (incl. the description = why and remediation = fix shown by check). The orchestrator merges them into each level’s node_attributes / groups. (hk’s spec ships with the derived [fields.*] via metric_specs.)
cycle_specs
The cycle-kind diagnostic vocabulary (mutual / chain) from builtin.toml [cycles.*] — label + description (why) + remediation (fix). The orchestrator overlays these onto each level’s cycle_kinds.
metric_specs
The metric attribute dictionary + category groups, read from builtin.toml. Includes the emitted measured metrics ([ast.*] entries that carry a display spec, i.e. have a label) and every derived [fields.*] metric. Pure AST inputs (no label) are excluded — they are formula inputs, not emitted.
prompt_template
The Prompt-Generator scaffolding prose, parsed from metrics/prompt.md — the language-neutral framing carried in the snapshot so the CLI prompt format and the HTML viewer render the same text. Each ## <field> section maps to a PromptTemplate field; ## task keeps one entry per non-blank line (verbatim, including the leading - ), the rest join their body into one line.
prompt_template_from
Parse caller-supplied prompt-scaffolding Markdown (same ## <field> shape as the built-in metrics/prompt.md) into a PromptTemplate — the hook a [templates] prompt = "…" config override flows through.
stat_keys
The metric keys aggregated into the per-graph stats block via the mean (compute_stats). Derived from [report.stats]: the keys whose formula is a plain mean of their own metric over not_empty (agg('<k>', 'avg', 'not_empty')). The richer aggregate formulas (percentiles, all population, …) are parsed but not yet wired into the built-in stats.
views
The canonical view orders (table columns + default sort, card metrics, map size/filter), all from the single [report] section of builtin.toml.
write_derived
Compute the graph-derived built-in metrics ([GRAPH_DERIVED], e.g. hk) onto node, AFTER the coupling pass has written fan_in/fan_out. Reads the node’s own (already-rounded) numeric attributes — exactly the values the former Rust hk read via attr_f64 — so emitted values are unchanged. Pre-graph fields (volume/mi/…) are NOT recomputed here: they are written by write_metrics from the raw, unrounded tier-1 counts and must not be re-derived from the rounded node attributes. Each value is dropped at its omit_at. No-op when no [fields.*] is graph-derived.
write_metrics
Write the per-unit built-in metrics onto node: the tier-1 measured values (the LOC block is emitted only when sloc > 0) plus the pre-graph derived metrics ([DERIVED]) computed from the raw tier-1 counts. Graph-derived fields (e.g. hk) are written later by write_derived, once the coupling pass has run. Each value is dropped at its omit_at.