GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Grid network and substations / gridatlas / atlas/modules

Single-Line Diagram (SLD) Without Layout (part 1)

A JavaScript file in the atlas folder of GridAtlas that maps connection points, GB transmission network, price decade rollup and grid substations, using haversine.

700 lines of JavaScript from gridatlas, in 1 file. Topic: Grid network and substations. Section 397 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Single-Line Diagram (SLD) Without Layout geodesy · gridatlas / atlas/modules/202611222130-sld-without-layout.js lines 1–700

Single-Line Diagram (SLD) Without Layout

A JavaScript file in the atlas folder of GridAtlas that maps connection points, GB transmission network, price decade rollup and grid substations, using haversine.

Set aside from the main view: 100% of its lines are the same as atlas/modules/202612020205-secondary-neon-engine.js (gridatlas), which stays. (near-copy-of, proposed by families.py). 99% of lines shared with Secondary Neon Engine; read that one first. All set-aside files, with reasons. Nothing was deleted.

Evidence
  • line-jaccard 0.9961 to gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 atlas/modules/202612020205-secondary-neon-engine.js:1-9008 26e5045a356c11088820207d3cbe95eb4b89374f
  • sha256 6870cfb365c18b90363b664f89623c9217c3d0111a67b87fdd1b6b3a26aeba6b
  • target sha256 b9e2b3ce36d3f46184c4a0f0416d70892feb49507d1c93833d3ab00a27c84263
  • group of 3 (identity.json near-copy edges >= 0.9)
  • canonical rule: reachable, newest stamp, core repo, most lines

geodesygridatlas / atlas/modules/202611222130-sld-without-layout.js · lines 1–700 of 8986 · version 2026-11-22 21:30 · Not reached from any entry point (candidate for review) · pattern isInterconnectorArrival (shared by 3 files)

What it does
It maps connection points, GB transmission network, price decade rollup and grid substations. Defines 273 functions or classes, including distanceKm, distanceKm, representativePoint, voltagesKv, destinationPoint. Side effects: changes the web page (DOM); reads or writes files; makes network requests; uses storage (browser storage, DuckDB or Parquet).
Why it exists in the grid workflow
Domain stage sub33kv_design (path word 'layout'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: 750kV, 415kV, 400kV, 275kV, 220kV, 132kV.
Inputs & outputs
In: JSON file connection-points.v3.json; JSON file gb-transmission-network.v1.json; JSON file price-decade-rollup.json; GeoJSON file grid_substations.geojson; JSON file neso-connection-sites.lean.json; GeoJSON file interconnectors.geojson; browser storage (getItem); DuckDB queries. Out: browser storage (setItem); interactive map. Coordinate systems named: WGS84 / EPSG:4326. Voltage levels named: 750kV, 415kV, 400kV, 275kV, 220kV, 132kV, 110kV, 66kV.
What it achieves
It creates compute observer (`createComputeObserver`), describes compute receipt (`describeComputeReceipt`) and builds stats (`buildStats`). Receipt and distance owner: Ventusltd/ventus-grid-engine. Its code works with 400 kV, 132 kV and 33 kV. It responds to click, keydown and touchstart events.
Why it matters
No other file in the estate was found to import it.
Application
gridatlas · atlas/modules · script
VEDIC
MEASURE (GG2050-VEDIC-000001): GridAtlas / Geodesy · Mathematics / Spherical geometry. coordinate_pair, coordinate_pair → distance_km
VEDIC
REPRESENT (GG2050-VEDIC-000002): GridAtlas / Geodesy · Computer science / Geometry processing. geojson_geometry → coordinate_pair_or_null
VEDIC
VOLTAGE (GG2050-VEDIC-000003): GridAtlas / Geodesy · Computer science / Data normalisation. voltage_properties → kilovolt_list
Uses
none found
Used by
none found
Produces
distanceKm, distanceKm, representativePoint, voltagesKv, destinationPoint, initialBearingDeg, copy, finite, located, sameLocation, sameEntity, createComputeObserver
Defines here
distanceKm, distanceKm, representativePoint, voltagesKv, destinationPoint, initialBearingDeg, copy, finite, located, sameLocation, sameEntity, createComputeObserver, publish, get, describeComputeReceipt, classOf, scope, survey, ready
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 atlas/modules/202611222130-sld-without-layout.js:1-700 · blob ab6fc6992aa26e51a3c82d7e2d26172a50798c60 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, filesystem, network, storage · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: unreached_review
/* Receipt and distance owner: Ventusltd/ventus-grid-engine 487ec7bd38dfa5aecb1c75da53b4a866ab2101cb */
/* Ventus Grid Engine: generated receipt observer; not a substitute nearest engine. */
(() => {
'use strict';
const distanceKm = (() => {
/**
 * Module: geodesy
 *
 * Extracted verbatim (formula and constant unchanged) from
 * gridatlas/atlas/modules/202609011950-geodesy.js.
 *
 * One Earth radius for the whole estate, and the three operations every
 * measurement here is built from. This existed three times tonight - in
 * the sandbox, in the substation cartridge and in the data repository -
 * which is exactly how two of them end up on different radii without
 * anyone noticing.
 *
 * Radius 6378.137 km, matching Ventusltd/grid-distance-maths. Haversine.
 * No projection, no turf, no second radius for geometry.
 *
 * Pure functions. No DOM, no network, no state.
 *
 * CHANGED: source wraps this in `(() => { ... NS.geodesy = Object.freeze({...}) })()`
 * and registers itself on `window.__GRIDATLAS_MODULES__.geodesy`. That
 * closure/global-namespace wiring is removed; every function below is
 * otherwise byte-identical to the source, including the atan2 argument
 * order that the source's own comment insists on for numerical parity
 * with ventus-corev8engine.js haversine() (see distanceKm below).
 */

const EARTH_RADIUS_KM = 6378.137;
const DEG = Math.PI / 180;

function distanceKm(lon1, lat1, lon2, lat2) {
  const dLat = (lat2 - lat1) * DEG;
  const dLon = (lon2 - lon1) * DEG;
  const a = Math.sin(dLat / 2) ** 2
    + Math.cos(lat1 * DEG) * Math.cos(lat2 * DEG) * Math.sin(dLon / 2) ** 2;
  /* atan2, in this operand order, because that is the form every version
     of this estate has shipped - ventus-corev8engine.js haversine() and
     every cartridge carried from it.
     -------------------------------------------------------------------
     The extraction wrote 2 * R * asin(sqrt(a)) instead. Algebraically the
     same; numerically one unit in the last place apart, which the
     all-versions proof caught on West Burton Solar to Cottam:
     7.050150827184836 shipped, 7.050150827184837 from the module. It is
     1e-15 km and changes no figure any reader will ever see - and it is
     still wrong, because the claim being made is PARITY. A module that is
     nearly the incumbent is a module that has to be argued about every
     time a digit differs. */
  return EARTH_RADIUS_KM * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
}

/* A polygon reduces to the mean of its outer ring, not its first corner.
   A substation drawn as a compound outline would otherwise be measured
   from whichever vertex the mapper happened to start at.

   Point, Polygon and MultiPolygon, and NOTHING ELSE. The first draft of
   this module accepted any nested coordinate array and so returned a
   mean for a LineString where the incumbent returns null; the parity
   proof caught it against the live cartridge. Extraction is not the
   moment to change behaviour, so the behaviour is pinned here and any
   widening becomes its own version with its own reasoning.

   One deliberate difference, on malformed input only: this returns null
   where the incumbent would throw on a Point with no coordinates. No
   real geometry reaches that path, and a proof asserts it. */
function representativePoint(geometry) {
  if (!geometry) return null;
  const { type, coordinates } = geometry;
  if (type === 'Point') {
    return Array.isArray(coordinates) && coordinates.length >= 2
      ? [coordinates[0], coordinates[1]] : null;
  }
  const ring = type === 'Polygon' ? coordinates && coordinates[0]
    : type === 'MultiPolygon' ? coordinates && coordinates[0] && coordinates[0][0]
      : null;
  if (!Array.isArray(ring) || !ring.length) return null;
  let sumLon = 0;
  let sumLat = 0;
  for (const point of ring) {
    sumLon += point[0];
    sumLat += point[1];
  }
  return [sumLon / ring.length, sumLat / ring.length];
}

/* OpenStreetMap's `voltage` is VOLTS at every magnitude, and a feature
   may carry several separated by a semicolon. Magnitude is not the unit:
   750 is a DC traction supply at a railway depot, not 750 kV. An audit
   of the served payload found 229 features (3.95%) carrying a token
   below 1,000, every one of which had been misread. An explicit `kv`
   property is already kilovolts and is trusted as such. */
function voltagesKv(properties) {
  if (!properties) return [];
  const out = [];
  const explicit = properties.kv ?? properties.KV;
  if (explicit != null && String(explicit).trim() !== '') {
    for (const token of String(explicit).match(/\d+(?:\.\d+)?/g) || []) {
      const value = Number(token);
      if (Number.isFinite(value) && value > 0) out.push(value);
    }
  }
  const volts = properties.voltage ?? properties.VOLTAGE;
  if (volts != null) {
    for (const token of String(volts).match(/\d+(?:\.\d+)?/g) || []) {
      const value = Number(token);
      if (Number.isFinite(value) && value > 0) out.push(value / 1000);
    }
  }
  return [...new Set(out)].sort((a, b) => b - a);
}

/* Projection and bearing, carried in from the sandbox verbatim.
   ----------------------------------------------------------------------
   The deep scan found the body carrying a SECOND geodesy section - "the
   geodesy the layout needs, all on R_ATLAS" - four hundred lines away
   from the first. Two geodesies in one file, on a constant that must
   never differ, is the configuration that produced the divergence the
   all-versions proof caught. Both belong here, on the one radius, and
   the body now delegates rather than defining.

   The bodies below are the incumbent's, character for character apart
   from the radius identifier, so parity is a property of the move rather
   than something to argue about afterwards. */
function destinationPoint(lon, lat, km, bearingDeg) {
  const ad = km / EARTH_RADIUS_KM;
  const brg = bearingDeg * DEG;
  const p1 = lat * DEG;
  const p2 = Math.asin(Math.sin(p1) * Math.cos(ad)
    + Math.cos(p1) * Math.sin(ad) * Math.cos(brg));
  const l2 = lon * DEG + Math.atan2(
    Math.sin(brg) * Math.sin(ad) * Math.cos(p1),
    Math.cos(ad) - Math.sin(p1) * Math.sin(p2));
  return [l2 / DEG, p2 / DEG];
}

function initialBearingDeg(lon1, lat1, lon2, lat2) {
  const p1 = lat1 * DEG; const p2 = lat2 * DEG;
  const dl = (lon2 - lon1) * DEG;
  const y = Math.sin(dl) * Math.cos(p2);
  const x = Math.cos(p1) * Math.sin(p2) - Math.sin(p1) * Math.cos(p2) * Math.cos(dl);
  return (Math.atan2(y, x) / DEG + 360) % 360;
}

const schema = 'gridatlas.module.geodesy.v1';

return distanceKm;
})();
/** Actual-computation receipts, shared by Node and browsers. No DOM or network. */

const schema = 'ventus.grid-compute-receipt.v1';
const copy = value => JSON.parse(JSON.stringify(value));
const finite = value => typeof value === 'number' && Number.isFinite(value);
const located = point => point && finite(point.lon) && finite(point.lat)
  && Math.abs(point.lon) <= 180 && Math.abs(point.lat) <= 90;
const sameLocation = (a, b) => located(a) && located(b) && a.lon === b.lon && a.lat === b.lat;
const sameEntity = (a, b) => a && b && a.kind === b.kind && String(a.id) === String(b.id);

/**
 * Create one observer per selection surface, not one per project. Every request
 * invalidates the previous selection for assessment, including repeated IDs.
 * Receipts are evidence about the supplied callback, not proof that a renderer
 * used this module. Attach run() at the real calculation call site.
 */
function createComputeObserver({ onEvent = () => {}, now = () => Date.now() } = {}) {
  const attempts = new Map();
  let sequence = 0;
  let latest = null;
  const publish = (attempt, status, extra = {}) => {
    Object.assign(attempt, extra, { status, sequence: ++sequence, updated_at_ms: now() });
    attempt.events.push({ status, sequence: attempt.sequence, at_ms: attempt.updated_at_ms });
    // A broken logging consumer must never break the grid calculation itself.
    try { onEvent(copy(attempt)); } catch { /* receipt remains queryable */ }
    return copy(attempt);
  };
  const get = id => {
    const attempt = attempts.get(id);
    if (!attempt) throw new Error('Unknown computation attempt: ' + id);
    return attempt;
  };
  return {
    request({ entity, location = null, operation = 'nearest-grid', dataset = null }) {
      if (!entity || typeof entity.kind !== 'string' || !entity.kind.trim()
          || entity.id == null || !String(entity.id).trim()) {
        throw new TypeError('A computation request requires an entity kind and ID');
      }
      const id = 'compute-' + (sequence + 1);
      const attempt = {
        schema, id, entity: { kind: entity.kind, id: String(entity.id) },
        location: located(location) ? { lon: location.lon, lat: location.lat } : null,
        operation, dataset, requested_at_ms: now(), events: []
      };
      attempts.set(id, attempt);
      latest = id;
      publish(attempt, 'requested');
      return id;
    },
    unsupported(id, reason) {
      const attempt = get(id);
      if (attempt.status !== 'requested') throw new Error('Attempt already invoked or terminal');
      return publish(attempt, 'unsupported', { reason: String(reason || 'Unsupported input') });
    },
    async run(id, compute) {
      const attempt = get(id);
      if (attempt.status !== 'requested') throw new Error('Attempt already invoked or terminal');
      if (!attempt.location) return publish(attempt, 'unsupported', { reason: 'No valid project location' });
      if (typeof compute !== 'function') return publish(attempt, 'failed', { reason: 'No computation callback' });
      publish(attempt, 'started');
      try {
        const result = await compute(copy(attempt));
        if (!sameLocation(result?.origin, attempt.location)) throw new Error('Result origin does not match this request');
        if (!sameEntity(result?.entity, attempt.entity)) throw new Error('Result entity does not match this request');
        if (!Array.isArray(result.measurements)) throw new Error('Computation returned no measurements array');
        if (result.measurements.length === 0) {
          if (result.search_completed !== true || !Number.isInteger(result.scanned_count) || result.scanned_count < 0) {
            throw new Error('Empty result lacks completed-search and scanned-count evidence');
          }
          return publish(attempt, 'completed_empty', { measurements: [],
            summary: { measured_count: 0, scanned_count: result.scanned_count, nearest_km: null } });
        }
        const measurements = result.measurements.map(row => {
          if (!row || row.node_id == null || !String(row.node_id).trim()
              || !located(row) || !finite(row.km) || row.km < 0) {
            throw new Error('Computation returned an invalid grid measurement');
          }
          const expected = distanceKm(attempt.location.lon, attempt.location.lat, row.lon, row.lat);
          // Receipts carry unrounded values from the shared geodesy, not UI text.
          if (Math.abs(expected - row.km) > Math.max(1e-6, expected * 1e-9)) {
            throw new Error('Grid distance does not match the request and measured node');
          }
          return { node_id: String(row.node_id), lon: row.lon, lat: row.lat, km: row.km };
        });
        return publish(attempt, 'completed', { measurements,
          summary: { measured_count: measurements.length, nearest_km: Math.min(...measurements.map(row => row.km)) } });
      } catch (error) {
        return publish(attempt, 'failed', { reason: String(error?.message || error) });
      }
    },
    snapshot(id = latest) { return id == null ? null : copy(get(id)); },
    assess(id, expected) {
      if (!attempts.has(id)) return { passed: false, reason: 'never-requested' };
      const attempt = get(id);
      if (id !== latest) return { passed: false, reason: 'stale-attempt' };
      if (!sameEntity(attempt.entity, expected?.entity) || !sameLocation(attempt.location, expected?.location)) {
        return { passed: false, reason: 'selection-mismatch' };
      }
      return { passed: attempt.status === 'completed', reason: attempt.status };
    }
  };
}

/** Honest UI projection of computation receipts. No inference from a URL. */
function describeComputeReceipt(receipt) {
  const status = receipt?.status || 'not_requested';
  const summary = receipt?.summary;
  const nearest = summary?.nearest_km;
  const labels = {
    not_requested: 'Grid calculation not requested', requested: 'Grid calculation queued',
    started: 'Calculating nearest mapped substations', completed_empty: 'Search completed: no mapped substations returned',
    unsupported: 'Grid calculation unavailable', failed: 'Grid calculation failed',
  };
  if (status === 'completed' && Number.isFinite(nearest) && nearest >= 0) {
    return { status, text: `Nearest mapped substation: ${nearest.toFixed(2)} km`,
      distance_km: nearest, unit: 'km', scope: 'Geometric screening only; not an electrical connection, capacity or offer.' };
  }
  return { status, text: labels[status] || 'Grid calculation result unavailable',
    reason: receipt?.reason || null, distance_km: null, unit: null,
    scope: 'Geometric screening only; not an electrical connection, capacity or offer.' };
}

globalThis.VentusGridCompute = Object.freeze({ schema, distanceKm, createComputeObserver, describeComputeReceipt });
})();

/**
 * CARRIED FORWARD AND EDITED, NOT ASSEMBLED. The notice below was true at generation 202609050354. Every generation
 * since has been cut by copying the previous cartridge and editing the copy; the parts it names were not touched again
 * and no longer reproduce this file (they build 363 KB; this is over 420 KB). Do NOT rebuild this cartridge from those
 * parts: that would silently discard everything added since 5 September. Said here at 202609200022 because a header
 * that misdescribes how a file is made is the kind of false record this estate keeps finding.
 *
 * sld-sandbox-v9-8, generation 202609050354 (UTC).
 *
 * ASSEMBLED by tools/build-cartridge.mjs from the parts below. Do not edit
 * this file: edit a part and rebuild under a new generation. Each part is
 * hashed in manifests/202609050354-sld-sandbox-v9-8-parts.json.
 *
 *   module                 atlas/modules/202609012040-grid-scope.js
 *   module                 atlas/modules/202609012217-source-registry.js
 *   module                 atlas/modules/202609012128-declared-connections.js
 *   module                 atlas/modules/202609012205-sizing-arithmetic.js
 *   module                 atlas/modules/202609031310-technology-coverage.js
 *   part                   atlas/parts/202609041234-sld-sandbox-technology-buckets.js
 */

/**
 * Module: grid-scope
 *
 * "When you click on a blank space, the user should be able to see grid in
 * the vicinity. Call it the GRID FINDING SCOPE — analysis of what is
 * there, NOT indicative of capacity." — Vikram, 2026-09-01.
 *
 * So this answers exactly one question: WHAT IS MAPPED HERE. It counts
 * what the served payload contains around a point, by voltage class and
 * by distance band, and names the nearest few. It is a census of the map,
 * not a study of the network.
 *
 * WHAT IT WILL NOT DO, EVER
 * It does not say whether a connection is available, likely, cheap or
 * possible. Nothing in a payload of substation positions can support any
 * of that: capacity depends on queue position, committed connections,
 * thermal and fault headroom, consent and commercial terms, and none of
 * those is a distance. A scope that counted substations and implied
 * opportunity would be the most dangerous thing this estate could ship,
 * because it would look like analysis.
 *
 * Pure. No DOM, no network, no state. Depends on: geodesy.
 */
(() => {
  'use strict';

  const NS = (window.__GRIDATLAS_MODULES__ = window.__GRIDATLAS_MODULES__ || {});
  if (NS.gridScope) return;

  const geodesy = NS.geodesy;
  if (!geodesy) throw new Error('grid-scope requires the geodesy module');

  /* Bands, not a single radius. A reader asking "what is around here"
     wants the shape of the answer - is the nearest thing on top of me or
     twenty kilometres away - and one number hides that. */
  const DEFAULT_BANDS_KM = [2, 5, 10, 25];
  const CLASSES_KV = [400, 275, 220, 132, 66, 33];

  /* A voltage is classified ONLY as a class it actually is.
     ------------------------------------------------------------------
     The first version walked the classes and returned the first one the
     value exceeded, so it labelled 750 kV as 400, 110 kV as 66 and 50 kV
     as 33 - a false label on anything the list does not contain, which is
     exactly the sort of quiet relabelling this estate exists to avoid.
     Codex caught it on the committed module before it reached a card
     (stop-ship 202609012025).

     Now: membership, within a tolerance for the fractions OSM carries.
     Anything else is UNCLASSIFIED and counted as such, because a voltage
     the standard classes do not contain is a fact about the data, not a
     value to be rounded into the nearest familiar number. */
  const CLASS_TOLERANCE_KV = 0.5;

  function classOf(kv) {
    if (!Number.isFinite(kv)) return null;
    for (const known of CLASSES_KV) {
      if (Math.abs(kv - known) <= CLASS_TOLERANCE_KV) return known;
    }
    return null;
  }

  /**
   * @param origin [lon, lat]
   * @param substations  [{ at:[lon,lat], kv:[numbers], name, operator }]
   * @param options { bandsKm, minimumKv, nearestCount }
   */
  function scope(origin, substations, options) {
    const bandsKm = (options && options.bandsKm) || DEFAULT_BANDS_KM;
    const minimumKv = (options && options.minimumKv) || 0;
    const nearestCount = (options && options.nearestCount) || 5;
    const maximumKm = bandsKm[bandsKm.length - 1];

    const within = [];
    for (const substation of substations || []) {
      if (!substation || !Array.isArray(substation.at)) continue;
      const voltages = (Array.isArray(substation.kv) ? substation.kv : [])
        .filter(Number.isFinite);
      /* Non-finite voltages are dropped BEFORE the maximum.
         ----------------------------------------------------------------
         Codex, 202609012055: Math.max over a NaN gives NaN, and NaN < floor
         is false, so a substation whose voltage did not parse survived a
         132 kV floor and was censused as though it qualified. A voltage
         that is not a number is not a voltage above the floor. */
      const top = voltages.length ? Math.max(...voltages) : 0;
      if (top < minimumKv) continue;
      const km = geodesy.distanceKm(origin[0], origin[1],
        substation.at[0], substation.at[1]);
      if (km > maximumKm) continue;
      within.push({
        name: substation.name || '',
        operator: substation.operator || '',
        kv: top,
        class_kv: classOf(top),
        km,
        at: substation.at
      });
    }
    within.sort((a, b) => a.km - b.km);

    const bands = bandsKm.map((band) => {
      const inBand = within.filter(entry => entry.km <= band);
      const counts = {};
      let unclassified = 0;
      const unclassifiedKv = [];
      for (const entry of inBand) {
        if (entry.class_kv == null) {
          // Counted, never folded into a class it is not.
          unclassified += 1;
          if (Number.isFinite(entry.kv) && !unclassifiedKv.includes(entry.kv)) {
            unclassifiedKv.push(entry.kv);
          }
          continue;
        }
        counts[entry.class_kv] = (counts[entry.class_kv] || 0) + 1;
      }
      const highest = inBand.reduce(
        (best, entry) => (entry.class_kv != null && (best == null || entry.class_kv > best)
          ? entry.class_kv : best), null);
      return {
        within_km: band,
        substations: inBand.length,
        by_class_kv: counts,
        highest_class_kv: highest,
        unclassified_voltage: unclassified,
        unclassified_kv: unclassifiedKv.sort((a, b) => b - a)
      };
    });

    /* Named first, because an unnamed OSM node is a fact about the map
       rather than a place anyone can look up. Both are reported: the
       nearest thing, and the nearest thing with an identity. */
    const named = within.filter(entry => entry.name);
    return {
      schema: 'gridatlas.grid-scope.v1',
      origin: [origin[0], origin[1]],
      radius_km: maximumKm,
      minimum_kv: minimumKv,
      counted: within.length,
      bands,
      nearest: within.slice(0, nearestCount),
      nearest_named: named.slice(0, nearestCount),
      nearest_transmission: within.find(entry => entry.kv >= 275 - 0.5) || null,
      /* Carried in the result itself so it cannot be separated from the
         numbers by a renderer, a screenshot or a quote. */
      what_this_is: 'A census of the substations in the served map payload '
        + 'around this point, by voltage class and distance band.',
      what_this_is_not: 'Not a statement about capacity, headroom, '
        + 'availability or the cost of connecting here. Distance is not '
        + 'capacity: queue position, committed connections, thermal and '
        + 'fault headroom, consent and commercial terms decide that, and '
        + 'none of them is in this payload.',
      method: 'haversine on a single Earth radius of '
        + geodesy.EARTH_RADIUS_KM + ' km, straight line to mapped geometry'
    };
  }

  NS.gridScope = Object.freeze({
    schema: 'gridatlas.module.grid-scope.v2',
    CLASS_TOLERANCE_KV,
    DEFAULT_BANDS_KM,
    CLASSES_KV,
    classOf,
    scope
  });
})();

/**
 * Module: source-registry
 *
 * "Click anywhere on a map and the neons that already work via Pipeline News
 * look for cartridges and code." — Vikram, 2026-09-01.
 *
 * The looking is this module. The Atlas is a composition of cartridges that
 * find each other through `window.__GRIDATLAS_*` globals, and the deep scan
 * of 1 Sep 2026 found fifteen such surfaces ever registered, thirteen live,
 * and nothing anywhere that documents them. Every consumer therefore does
 * its own `window.__GRIDATLAS_NETWORK__?.something` and quietly does less
 * when the answer is undefined. That is how a click on blank space came to
 * report only what OpenStreetMap has mapped, while the cartridge holding
 * NESO's 886 published connection points sat loaded in the same page.
 *
 * So: one registry, declared once, that answers three questions.
 *
 *   WHAT COULD ANSWER      the sources this estate knows about, each with
 *                          what it contributes and whether it is required.
 *   WHAT IS ANSWERING NOW  probed live, by looking for the surface AND the
 *                          specific capability, because a cartridge that
 *                          has loaded but not yet fetched is present and
 *                          not yet useful, and those are different states.
 *   WHAT DID NOT           named, with the reason, in the result itself.
 *
 * The third is the point. A reader who is told "3 of 4 sources answered;
 * NESO's published network did not, because its payload had not loaded" can
 * judge the answer. A reader shown a shorter answer cannot, and will
 * reasonably assume the map has told them everything it knows.
 *
 * It reads. It never fetches, never renders, and never decides what a
 * finding means.
 *
 * Successor to 202609012135 at generation 202609012217: every source that
 * fetches a product declares what it REQUIRES (repository, product, schema)
 * and the survey carries that in every state, because a contract stated
 * only once the load has succeeded is no help to the reader of a failure.
 * The GB price rollup, fetched since v9.41 without a row here, is
 * registered with the loader state the sandbox now publishes.
 *
 * Depends on: nothing.
 */
(() => {
  'use strict';

  const NS = (window.__GRIDATLAS_MODULES__ = window.__GRIDATLAS_MODULES__ || {});
  if (NS.sourceRegistry) return;

  /* The registry is DECLARED, not discovered by scanning window.
     ----------------------------------------------------------------------
     Enumerating every __GRIDATLAS_* global would report whatever happens to
     be there, including surfaces this estate has never agreed to consume,
     and would silently start using a new one the day someone adds it. A
     declared list is a contract: adding a source is an edit here, with a
     reason, and a proof that the probe actually works. */
  const SOURCES = [
    {
      id: 'map',
      surface: '__GRIDATLAS_V9_MAP__',
      contributes: 'the map itself: where the click happened, and what is drawn',
      probe: (w) => (w.__GRIDATLAS_V9_MAP__ ? 'ready' : 'absent')
    },
    {
      id: 'mapped-substations',
      surface: '__GRIDATLAS_NEON_LINKS__',
      contributes: 'substations as OpenStreetMap has them mapped, and the '
        + 'measurement the neon links already use',
      probe: (w) => {
        const links = w.__GRIDATLAS_NEON_LINKS__;
        if (!links) return 'absent';
        if (typeof links.measure?.distanceKm !== 'function') return 'loaded, cannot measure';
        if (!links.substations_loaded) return 'loaded, no substations yet';
        return 'ready';
      },
      detail: (w) => ({ substations: w.__GRIDATLAS_NEON_LINKS__?.substations_loaded || 0 })
    },
    {
      id: 'neso-connection-points',
      surface: '__GRIDATLAS_NETWORK__',
      requires: { repository: 'Ventusltd/data-grid-gb',
        product: 'derived/connection-points.v3.json',
        schema: 'data-grid-gb.connection-points.v3' },
      contributes: "NESO's published connection points: circuits, transformers, "
        + 'per-voltage fault current and planned changes',
      probe: (w) => {
        const network = w.__GRIDATLAS_NETWORK__;
        if (!network) return 'absent';
        if (network.failed) return 'failed to load';
        if (!network.loaded) return 'loading';
        return 'ready';
      },
      detail: (w) => ({ connection_points: w.__GRIDATLAS_NETWORK__?.count || null,
        schema: w.__GRIDATLAS_NETWORK__?.schema || null })
    },
    {
      id: 'grid-scope',
      surface: '__GRIDATLAS_MODULES__.gridScope',
      contributes: 'the census of what is mapped around a point, in distance bands',
      probe: (w) => (w.__GRIDATLAS_MODULES__?.gridScope ? 'ready' : 'absent')
    },
    {
      id: 'network-topology',
      surface: '__GRIDATLAS_MODULES__.networkTopology + __GRIDATLAS_TOPOLOGY__',
      requires: { repository: 'Ventusltd/data-grid-gb',
        product: 'derived/gb-transmission-network.v1.json',
        schema: 'data-grid-gb.transmission-network.v1' },
      contributes: 'circuits, transformers, planned changes and neighbouring '
        + 'sites at a named substation, per voltage',
      /* Generation 202609012135: the module alone is not the source. At v9.67
         this probe said "ready" because the module object existed, while
         the ten-megabyte product it indexes had never been fetched by any
         cartridge - the module was on disk and answered nothing. Ready now
         means the product is indexed; idle means it will load on the first
         click that asks; the other states are what the loader says. */
      probe: (w) => {
        if (!w.__GRIDATLAS_MODULES__?.networkTopology) return 'absent';
        const loader = w.__GRIDATLAS_TOPOLOGY__;
        if (!loader) return 'module present, no loader in this composition';
        if (loader.state === 'ready') return 'ready';
        if (loader.state === 'loading') return 'loading';
        if (loader.state === 'failed') return 'failed to load';
        return 'idle, loads on first use';
      },
      detail: (w) => ({ sites: w.__GRIDATLAS_TOPOLOGY__?.sites || null,
        bytes: w.__GRIDATLAS_TOPOLOGY__?.bytes || null,
        schema: w.__GRIDATLAS_TOPOLOGY__?.schema || null })
    },
    {
      id: 'declared-connections',
      surface: '__GRIDATLAS_MODULES__.declaredConnections',
      contributes: 'points of connection bound to a made Order or a published '
        + 'planning document',
      probe: (w) => (w.__GRIDATLAS_MODULES__?.declaredConnections?.count > 0 ? 'ready' : 'absent'),
      detail: (w) => ({ records: w.__GRIDATLAS_MODULES__?.declaredConnections?.count || null })
    },
    {
      id: 'gb-electricity-conditions',
      surface: '__GRIDATLAS_GB_CONDITIONS__',
      contributes: 'the GB wholesale price context a project card carries: '
        + 'negative-price days and the record daily mean, from the owner rollup',
      requires: { repository: 'Ventusltd/data-gb-electricity',
        product: 'derived/price-decade-rollup.json',
        schema: 'data-gb-electricity.price-decade-rollup.v2' },
      /* Withheld is its own state: the product was reached and was not the
         schema this consumer answers, so the panel shows nothing and says
         why. That is neither a failure of the network nor a source ready. */
      probe: (w) => {
        const loader = w.__GRIDATLAS_GB_CONDITIONS__;
        if (!loader) return 'absent';
        if (loader.state === 'ready') return 'ready';
        if (loader.state === 'loading') return 'loading';
        if (loader.state === 'failed') return 'failed to load';
        if (loader.state === 'withheld') return 'withheld: ' + String(loader.reason || 'schema not supported');
        return 'idle, loads on first use';
      },
      detail: (w) => ({ schema: w.__GRIDATLAS_GB_CONDITIONS__?.schema || null,
        renders: w.__GRIDATLAS_GB_CONDITIONS__?.renders || 0 })
    }
  ];

  const READY = 'ready';

  /**
   * Probe every declared source against a window.
   * @param scope  the window to read; defaults to this one. Passing it in is
   *               what lets a proof drive the probe without a browser.
   */
  function survey(scope) {
    const w = scope || window;
    const sources = SOURCES.map((source) => {
      let state = 'absent';
      let detail = null;
      try { state = source.probe(w) || 'absent'; }
      catch (error) { state = `probe threw: ${error && error.message}`; }
      if (state === READY && typeof source.detail === 'function') {
        try { detail = source.detail(w); } catch (_) { detail = null; }
      }
      return { id: source.id, surface: source.surface,
        contributes: source.contributes, requires: source.requires || null,
        state, ready: state === READY, detail };
    });

    const ready = sources.filter(s => s.ready);
    const missing = sources.filter(s => !s.ready);

    return {
      schema: 'gridatlas.module.source-registry.v1',
      sources,
      ready: ready.map(s => s.id),
      missing: missing.map(s => ({ id: s.id, state: s.state })),
      counts: { declared: sources.length, ready: ready.length, missing: missing.length },
      /* Written as a sentence here so a card cannot compose its own and get
         it wrong, and so an absence is never presented as an absence in the
         world rather than in this page. */
      sentence: missing.length === 0
        ? `All ${sources.length} sources answered.`
        : `${ready.length} of ${sources.length} sources answered. Not answering: `
          + missing.map(s => `${s.id} (${s.state})`).join(', ')
          + '. What they would have added is missing from this answer, not '
          + 'absent from the world.'
    };
  }

  /** Is one source usable right now. */
  function ready(id, scope) {
    const source = SOURCES.find(s => s.id === id);
    if (!source) return false;
    try { return source.probe(scope || window) === READY; }
    catch (_) { return false; }
  }

  NS.sourceRegistry = Object.freeze({
    schema: 'gridatlas.module.source-registry.v1',
    declared: SOURCES.map(s => s.id),
    survey,
    ready
  });
})();

/**
 * Module: declared-connections
 *
 * The 400 kV public record: what each DCO-scale scheme has DECLARED as its
 * point of connection, taken from Development Consent Orders, Planning
 * Inspectorate documents and public project statements. The table binds a
 * register identity (REPD ref) to a NAMED substation, and the functions
 * here bind that name to the served payload and measure the distance -
 * measured, never asserted.
 *
 * The rule this exists to keep: bind to the public record or say nothing.
 * A nearest-substations list is a measurement; it was listing closer 33 and
 * 132 kV points under schemes whose Order names a 400 kV connection, which
 * read as connecting them to the wrong network. This table is the answer,
 * and it is data with three small functions, so it lives in a module where
 * a proof can read every record and a cut can hash it on its own.
 *
 * WHAT IT WILL NOT DO
 * It does not say whether a connection is available, likely or adequate. A
 * declared point of connection is a fact about a consent, not a judgement