GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Electricity markets and data pipelines / globalgrid2050 / testcode/202609051152/pipeline/scripts/data

Canonical Projects and 7 more files

A JavaScript module in the data folder of GlobalGrid2050 that validates projects contract (`validateProjectsContract`), builds canonical project model (`buildCanonicalProjectModel`) and loads canonical project model (`loadCanonicalProjectModel`) (units: MW).

567 lines of JavaScript from globalgrid2050, in 8 files. Topic: Electricity markets and data pipelines. Section 901 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. Canonical Projects V9 5 render · globalgrid2050 / testcode/202609051152/pipeline/scripts/data/canonical-projects-v9-5.js lines 1–33
  2. Canonical Projects ingest · globalgrid2050 / testcode/202609051152/pipeline/scripts/data/canonical-projects.js lines 1–335
  3. Committed JSON V9 7 transform · globalgrid2050 / testcode/202609051152/pipeline/scripts/news/adapters/committed-json-v9-7.mjs lines 1–14
  4. Classifier V9 7 transform · globalgrid2050 / testcode/202609051152/pipeline/scripts/news/classifier-v9-7.mjs lines 1–38
  5. Ledger V9 7 transform · globalgrid2050 / testcode/202609051152/pipeline/scripts/news/ledger-v9-7.mjs lines 1–76
  6. Geography V9 7 transform · globalgrid2050 / testcode/202609051152/pipeline/scripts/news/rules/geography-v9-7.mjs lines 1–32
  7. Technology V9 7 transform · globalgrid2050 / testcode/202609051152/pipeline/scripts/news/rules/technology-v9-7.mjs lines 1–17
  8. UK Veto V9 7 transform · globalgrid2050 / testcode/202609051152/pipeline/scripts/news/rules/uk-veto-v9-7.mjs lines 1–22

Canonical Projects V9 5

A JavaScript module in the data folder of GlobalGrid2050 that fetches release (`fetchRelease`) (units: MW). It fetches release (`fetchRelease`) and loads canonical projects v9 (`loadCanonicalProjectsV9_5`).

renderglobalgrid2050 / testcode/202609051152/pipeline/scripts/data/canonical-projects-v9-5.js · lines 1–33 of 33 · version 2026-09-05 11:52 · pattern fetchRelease (shared by 9 files)

What it does
It fetches data. Defines invariant, fetchRelease, loadCanonicalProjectsV9_5. Side effects: changes the web page (DOM); makes network requests.
Why it exists in the grid workflow
Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
Inputs & outputs
In: JSON file release.v9.5.json.
Downstream impact
Used directly by 2 files: Projects V9 5 (globalgrid2050); Projects V9 5 (globalgrid2050). Reached from 183 other entry points, including GlobalGrid2050 Historical Builds (globalgrid2050, https://globalgrid2050.com/historical_builds.html); GlobalGrid2050 Homepage Before Four Nests (globalgrid2050, https://globalgrid2050.com/homepage-before-four-nests-20260925.html); GlobalGrid2050 — PipelineNews Intelligence Page (globalgrid2050, https://globalgrid2050.com/pipelinenews_intelligence/202609050309/).
What it achieves
Defines `invariant`, `fetchRelease` and `loadCanonicalProjectsV9_5`.
Why it matters
Imported by Projects V9 5.
Application
globalgrid2050 · testcode/202609051152/pipeline/scripts/data · JavaScript module
Uses
Canonical Projects V9 1 (import)
Used by
imported by Projects V9 5 (import), imported by Projects V9 5 (import), mentioned in Standalone (comment link)
Produces
loadCanonicalProjectsV9_5
Defines here
invariant, fetchRelease, loadCanonicalProjectsV9_5
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609051152/pipeline/scripts/data/canonical-projects-v9-5.js:1-33 · blob b789fca9a3b9703af0431925506276ff5857a1d0 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: output · effects: dom, network · domain stage: experimental · users: none · canonical: production_core
import { loadCanonicalProjectsV9_1 } from "./canonical-projects-v9-1.js";

const RELEASE_URL = "contracts/release.v9.5.json";

function invariant(condition, message) {
  if (!condition) throw new Error(`V9.5 canonical projects: ${message}`);
}

async function fetchRelease() {
  const response = await fetch(RELEASE_URL, { cache: "no-store" });
  invariant(response.ok, `${RELEASE_URL} returned HTTP ${response.status}`);
  invariant(new URL(response.url).origin === window.location.origin, `${RELEASE_URL} redirected cross-origin`);
  return response.json();
}

export async function loadCanonicalProjectsV9_5() {
  const [release, model] = await Promise.all([fetchRelease(), loadCanonicalProjectsV9_1()]);
  invariant(release.release === "9.5", "release contract mismatch");
  invariant(release.frozen_parent?.release === "9.4", "frozen-parent release mismatch");
  invariant(release.data_parent?.release === "9.1", "data-parent release mismatch");
  invariant(model.contract.release === "9.1", "canonical data contract mismatch");
  invariant(model.projects.length === release.expected.project_count, "project count mismatch");
  invariant(model.metadata.capacity_mw === release.expected.capacity_mw, "capacity mismatch");
  invariant(model.metadata.largest_mw === release.expected.largest_mw, "largest project mismatch");
  invariant(model.metadata.geometry_count === release.expected.valid_geometry_count, "valid geometry count mismatch");
  invariant(model.metadata.missing_geometry_count === release.expected.missing_geometry_count, "missing geometry count mismatch");
  return Object.freeze({
    release: Object.freeze(release),
    dataContract: model.contract,
    metadata: Object.freeze({ ...model.metadata, ui_release: "9.5" }),
    projects: model.projects,
  });
}

Canonical Projects

A JavaScript module in the data folder of GlobalGrid2050 that validates projects contract (`validateProjectsContract`), builds canonical project model (`buildCanonicalProjectModel`) and loads canonical project model (`loadCanonicalProjectModel`) (units: MW).

ingestglobalgrid2050 / testcode/202609051152/pipeline/scripts/data/canonical-projects.js · lines 1–335 of 335 · version 2026-09-05 11:52 · pattern isObject (shared by 2 files)

What it does
It lists and searches projects plugin, the REPD register, solar and battery storage (BESS). Defines 19 functions or classes, including CanonicalProjectError, invariant, isObject, isFiniteNumber, isIsoDate.
Why it exists in the grid workflow
Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: the REPD register, solar, battery storage (BESS).
Inputs & outputs
In: JSON file projects-plugin.v7.2.json. Coordinate systems named: OSGB36 / EPSG:27700 (British National Grid).
Downstream impact
Used directly by 10 files: Project State (globalgrid2050); Projects (globalgrid2050); Check V7 2 Project Controls (globalgrid2050); Check V7 2 Project Model (globalgrid2050); and 6 more. Reached from 187 other entry points, including GlobalGrid2050 Historical Builds (globalgrid2050, https://globalgrid2050.com/historical_builds.html); GlobalGrid2050 Homepage Before Four Nests (globalgrid2050, https://globalgrid2050.com/homepage-before-four-nests-20260925.html); GlobalGrid2050 — PipelineNews Intelligence Page (globalgrid2050, https://globalgrid2050.com/pipelinenews_intelligence/202609050309/).
What it achieves
It validates projects contract (`validateProjectsContract`), builds canonical project model (`buildCanonicalProjectModel`) and fetches JSON (`fetchJson`). Defines `CanonicalProjectError`, `invariant`, `isObject` and 16 more.
Why it matters
Imported by Project State and Projects. Checked by 7 tests, including Check V7 2 Project Controls.
Application
globalgrid2050 · testcode/202609051152/pipeline/scripts/data · JavaScript module
Uses
none found
Used by
imported by Project State (import), imported by Projects (import), imported by Check V7 2 Project Controls (import), imported by Check V7 2 Project Model (import), imported by Check V7 2 Project Table Export (import), imported by Check V8 1 Mvp (import), imported by Check V9 0 (import), imported by Projects (import), and 2 more, mentioned in Standalone (comment link)
Produces
PROJECTS_CONTRACT_URL, CanonicalProjectError, isSameOriginRelativePath, lifecycleViewFor, validateProjectsContract, adaptCanonicalProject, sortCanonicalProjects, canonicalProjectMetrics, searchCanonicalProjects, buildCanonicalProjectModel, loadCanonicalProjectModel
Defines here
CanonicalProjectError, invariant, isObject, isFiniteNumber, isIsoDate, sameJson, round2, freezeArray, deepFreeze, isSameOriginRelativePath, lifecycleViewFor, validateProjectsContract, adaptCanonicalProject, sortCanonicalProjects, canonicalProjectMetrics, searchCanonicalProjects, buildCanonicalProjectModel, fetchJson, loadCanonicalProjectModel
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609051152/pipeline/scripts/data/canonical-projects.js:1-335 · blob 3468d88cce2c349b63e14d0f8dd02de850899f08 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: production_core
export const PROJECTS_CONTRACT_URL = "contracts/projects-plugin.v7.2.json";

const CONTRACT_SCHEMA = "globalgrid2050.v7.projects-plugin-contract.v1";
const PAYLOAD_SCHEMA = "globalgrid2050.v7.projects.v7.2";
const CONTRACT_STATUSES = new Set([
  "SPECIFICATION_ONLY_UI_NOT_LIVE",
  "LIVE_CANDIDATE",
  "LIVE_VALIDATED",
]);
const PAYLOAD_STATUSES = new Set([
  "VALIDATED_DATA_ONLY_NOT_LIVE",
  "LIVE_CANDIDATE",
  "LIVE_VALIDATED",
]);
const GEOMETRY_STATUSES = new Set(["valid", "missing", "invalid"]);
const FORBIDDEN_NEWS_FIELDS = new Set([
  "headline",
  "news_signal",
  "article_capacity_mw",
  "primary_match",
]);

export class CanonicalProjectError extends Error {
  constructor(code, message, options = {}) {
    super(`V7.2 canonical projects: ${message}`, options);
    this.name = "CanonicalProjectError";
    this.code = code;
  }
}

function invariant(condition, message, code = "INTEGRITY") {
  if (!condition) throw new CanonicalProjectError(code, message);
}

function isObject(value) {
  return value !== null && typeof value === "object" && !Array.isArray(value);
}

function isFiniteNumber(value) {
  return typeof value === "number" && Number.isFinite(value);
}

function isIsoDate(value) {
  if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
  const parsed = new Date(`${value}T00:00:00Z`);
  return Number.isFinite(parsed.getTime()) && parsed.toISOString().slice(0, 10) === value;
}

function sameJson(left, right) {
  if (left === right) return true;
  if (Array.isArray(left) || Array.isArray(right)) {
    return Array.isArray(left)
      && Array.isArray(right)
      && left.length === right.length
      && left.every((value, index) => sameJson(value, right[index]));
  }
  if (isObject(left) || isObject(right)) {
    if (!isObject(left) || !isObject(right)) return false;
    const leftKeys = Object.keys(left).sort();
    const rightKeys = Object.keys(right).sort();
    return sameJson(leftKeys, rightKeys)
      && leftKeys.every((key) => sameJson(left[key], right[key]));
  }
  return false;
}

function round2(value) {
  return Math.round((value + Number.EPSILON) * 100) / 100;
}

function freezeArray(values) {
  return Object.freeze(values.map((value) => (
    isObject(value) ? Object.freeze({ ...value }) : value
  )));
}

function deepFreeze(value) {
  if (!value || typeof value !== "object" || Object.isFrozen(value)) return value;
  Object.values(value).forEach(deepFreeze);
  return Object.freeze(value);
}

export function isSameOriginRelativePath(path) {
  if (typeof path !== "string" || !path || path.startsWith("/") || path.startsWith("//")) return false;
  if (/^[a-z][a-z\d+.-]*:/i.test(path)) return false;
  return !path.split("/").includes("..");
}

export function lifecycleViewFor(project) {
  if (["LIVE_PRE_CONSTRUCTION", "UNDER_CONSTRUCTION", "OPERATIONAL"].includes(project.lifecycle)) {
    return "CURRENT";
  }
  if (project.lifecycle === "INACTIVE") return "HISTORICAL";
  if (project.lifecycle === "UNKNOWN" && project.status === "Appeal Lodged") return "DISPUTED";
  if (project.lifecycle === "UNKNOWN" && project.status === "Revised") return "REVIEW";
  throw new CanonicalProjectError("SCHEMA", `unmapped lifecycle/status for REPD ${project.repd_ref || "unknown"}`);
}

export function validateProjectsContract(contract) {
  invariant(isObject(contract), "contract is not an object", "SCHEMA");
  invariant(contract.schema === CONTRACT_SCHEMA, "unexpected contract schema", "SCHEMA");
  invariant(contract.target_release === "7.2", "unexpected target release", "SCHEMA");
  invariant(CONTRACT_STATUSES.has(contract.status), "unapproved contract status", "SCHEMA");
  invariant(contract.release_state?.target_sources_are_same_origin === true, "same-origin rule is absent", "SOURCE_ORIGIN");
  invariant(
    isSameOriginRelativePath(contract.release_state?.target_project_source),
    "project source is not a safe same-origin relative path",
    "SOURCE_ORIGIN",
  );
  invariant(contract.interface?.combined_capacity_metric_forbidden === true, "combined-capacity prohibition is absent");
  return contract;
}

export function adaptCanonicalProject(record, contract) {
  invariant(isObject(record), "project record is not an object");
  const recordContract = contract.project_record;
  for (const field of recordContract.required_non_null_strings) {
    invariant(typeof record[field] === "string" && record[field].length > 0, `REPD ${record.repd_ref || "unknown"} lacks ${field}`);
  }
  for (const field of recordContract.required_finite_numbers) {
    invariant(isFiniteNumber(record[field]), `REPD ${record.repd_ref} has invalid ${field}`);
  }
  for (const field of recordContract.required_integers) {
    invariant(Number.isInteger(record[field]), `REPD ${record.repd_ref} has invalid ${field}`);
  }
  for (const field of recordContract.required_true_booleans) {
    invariant(record[field] === true, `REPD ${record.repd_ref} has invalid ${field}`);
  }
  for (const field of recordContract.required_arrays) {
    invariant(Array.isArray(record[field]), `REPD ${record.repd_ref} lacks array ${field}`);
  }
  for (const field of recordContract.nullable_iso_dates) {
    invariant(record[field] === null || isIsoDate(record[field]), `REPD ${record.repd_ref} has invalid ${field}`);
  }
  for (const field of recordContract.nullable_strings) {
    invariant(record[field] === null || typeof record[field] === "string", `REPD ${record.repd_ref} has invalid ${field}`);
  }
  for (const field of recordContract.nullable_numbers) {
    invariant(record[field] === null || isFiniteNumber(record[field]), `REPD ${record.repd_ref} has invalid ${field}`);
  }
  for (const field of recordContract.string_may_be_empty) {
    invariant(typeof record[field] === "string", `REPD ${record.repd_ref} has invalid ${field}`);
  }
  invariant(["solar", "bess"].includes(record.technology), `REPD ${record.repd_ref} has out-of-scope technology`);
  invariant(record.gg_project_id === `GG2050-REPD-${record.repd_ref}`, `REPD ${record.repd_ref} has invalid project ID`);
  invariant(record.identity_status === "REPD_BOUND", `REPD ${record.repd_ref} is not REPD-bound`);
  invariant(record.identity_confidence === "authoritative", `REPD ${record.repd_ref} is not authoritative`);
  invariant(record.development_repd_refs.includes(record.repd_ref), `REPD ${record.repd_ref} development omits itself`);
  invariant(GEOMETRY_STATUSES.has(record.geometry_status), `REPD ${record.repd_ref} has invalid geometry status`);
  if (record.geometry_status === "valid") {
    invariant(
      [record.easting, record.northing, record.longitude, record.latitude].every(isFiniteNumber),
      `REPD ${record.repd_ref} has incomplete valid geometry`,
    );
  }
  const relationshipContract = recordContract.relationship_object;
  for (const relationship of record.relationships) {
    invariant(isObject(relationship), `REPD ${record.repd_ref} has invalid relationship`);
    invariant(
      relationshipContract.required_fields.every((field) => typeof relationship[field] === "string" && relationship[field]),
      `REPD ${record.repd_ref} has incomplete relationship`,
    );
    invariant(
      relationshipContract.type_enum.includes(relationship.type),
      `REPD ${record.repd_ref} has unsupported relationship type`,
    );
  }
  invariant(
    !Object.keys(record).some((field) => FORBIDDEN_NEWS_FIELDS.has(field)),
    `REPD ${record.repd_ref} contains a news-derived fact`,
  );

  const technology = contract.interface.technology_labels_and_units[record.technology];
  invariant(isObject(technology), `REPD ${record.repd_ref} has no technology presentation contract`);
  const thresholdKey = record.technology === "solar" ? "solar_mwp_exclusive" : "bess_mw_exclusive";
  invariant(
    record.capacity_mw > contract.canonical_universe.thresholds[thresholdKey],
    `REPD ${record.repd_ref} fails the exclusive capacity threshold`,
  );

  const relationships = freezeArray(record.relationships);
  const directRelated = freezeArray(record.direct_related_repd_refs);
  const planningSiblings = freezeArray(record.planning_sibling_repd_refs);
  const developmentRefs = freezeArray(record.development_repd_refs);
  return Object.freeze({
    ...record,
    relationships,
    direct_related_repd_refs: directRelated,
    planning_sibling_repd_refs: planningSiblings,
    development_repd_refs: developmentRefs,
    technology_label: technology.label,
    capacity_unit: technology.unit,
    lifecycle_view: lifecycleViewFor(record),
  });
}

export function sortCanonicalProjects(projects) {
  return [...projects].sort((left, right) => (
    right.capacity_mw - left.capacity_mw
    || left.gg_project_id.localeCompare(right.gg_project_id)
  ));
}

export function canonicalProjectMetrics(projects) {
  let solarMwp = 0;
  let bessMw = 0;
  let largest = null;
  for (const project of projects) {
    if (project.technology === "solar") solarMwp += project.capacity_mw;
    if (project.technology === "bess") bessMw += project.capacity_mw;
    if (!largest || project.capacity_mw > largest.capacity_mw) largest = project;
  }
  return Object.freeze({
    solar_mwp: round2(solarMwp),
    bess_mw: round2(bessMw),
    project_count: projects.length,
    largest_project: largest ? Object.freeze({
      gg_project_id: largest.gg_project_id,
      name: largest.name,
      technology: largest.technology,
      capacity_mw: largest.capacity_mw,
      capacity_unit: largest.capacity_unit,
    }) : null,
  });
}

export function searchCanonicalProjects(projects, query, fields) {
  const needle = String(query || "").trim().toLocaleLowerCase("en-GB");
  if (!needle) return [...projects];
  const direct = projects.filter((project) => (
    project.repd_ref.toLocaleLowerCase("en-GB") === needle
    || project.gg_project_id.toLocaleLowerCase("en-GB") === needle
  ));
  if (direct.length) return direct;
  return projects.filter((project) => fields.some((field) => {
    const value = project[field];
    const values = Array.isArray(value) ? value : [value];
    return values.some((item) => String(item ?? "").toLocaleLowerCase("en-GB").includes(needle));
  }));
}

export function buildCanonicalProjectModel(payload, rawContract) {
  const contract = validateProjectsContract(rawContract);
  invariant(isObject(payload), "payload is not an object", "SCHEMA");
  invariant(payload.schema === PAYLOAD_SCHEMA, "unexpected payload schema", "SCHEMA");
  invariant(payload.version === "7.2", "unexpected payload version", "SCHEMA");
  invariant(PAYLOAD_STATUSES.has(payload.status), "payload is not validated", "SCHEMA");
  invariant(Array.isArray(payload.projects), "payload projects are absent", "SCHEMA");
  const expectedSnapshot = contract.canonical_universe.published_snapshot;
  invariant(isObject(expectedSnapshot), "published snapshot contract is absent", "SCHEMA");
  for (const field of [
    "projects_sha256",
    "source_identity_sha256",
    "source_coordinate_fixture_sha256",
    "source_workbook_sha256",
  ]) {
    invariant(payload[field] === expectedSnapshot[field], `${field} does not match the published snapshot`, "INTEGRITY");
  }
  invariant(sameJson(payload.geometry_policy, expectedSnapshot.geometry_policy), "geometry policy does not match the published snapshot");
  invariant(sameJson(payload.source_provenance, expectedSnapshot.source_provenance), "source provenance does not match the published snapshot");

  const projects = sortCanonicalProjects(payload.projects.map((record) => adaptCanonicalProject(record, contract)));
  const projectIds = new Set(projects.map((project) => project.gg_project_id));
  const repdRefs = new Set(projects.map((project) => project.repd_ref));
  const developments = new Set(projects.map((project) => project.gg_development_id));
  const solar = projects.filter((project) => project.technology === "solar");
  const bess = projects.filter((project) => project.technology === "bess");
  const metrics = canonicalProjectMetrics(projects);
  const expected = contract.canonical_universe;

  invariant(projects.length === payload.project_count && projects.length === expected.project_count, "project count mismatch");
  invariant(projectIds.size === projects.length, "duplicate GlobalGrid project ID");
  invariant(repdRefs.size === projects.length, "duplicate REPD Ref");
  invariant(developments.size === payload.development_count && developments.size === expected.development_count, "development count mismatch");
  invariant(solar.length === payload.solar_count && solar.length === expected.solar_count, "solar count mismatch");
  invariant(bess.length === payload.bess_count && bess.length === expected.bess_count, "BESS count mismatch");
  invariant(metrics.solar_mwp === payload.solar_mwp && metrics.solar_mwp === expected.solar_mwp, "solar MWp mismatch");
  invariant(metrics.bess_mw === payload.bess_mw && metrics.bess_mw === expected.bess_mw, "BESS MW mismatch");

  return Object.freeze({
    version: "7.2",
    source: contract.release_state.target_project_source,
    contract: deepFreeze(structuredClone(contract)),
    metadata: Object.freeze({
      schema: payload.schema,
      status: payload.status,
      projects_sha256: payload.projects_sha256,
      source_identity_sha256: payload.source_identity_sha256,
      source_coordinate_fixture_sha256: payload.source_coordinate_fixture_sha256,
      source_workbook_sha256: payload.source_workbook_sha256,
      geometry_policy: deepFreeze(structuredClone(payload.geometry_policy)),
      source_provenance: deepFreeze(structuredClone(payload.source_provenance)),
    }),
    projects: Object.freeze(projects),
    metrics,
  });
}

async function fetchJson(fetchImpl, path, label, baseUrl) {
  let response;
  try {
    response = await fetchImpl(path, { cache: "no-store", credentials: "same-origin" });
  } catch (cause) {
    throw new CanonicalProjectError("NETWORK", `${label} request failed`, { cause });
  }
  invariant(response?.ok === true, `${label} request failed (${response?.status ?? "no response"})`, "HTTP");
  if (response.url && baseUrl) {
    let configured;
    let resolved;
    try {
      configured = new URL(path, baseUrl);
      resolved = new URL(response.url, baseUrl);
    } catch (cause) {
      throw new CanonicalProjectError("SOURCE_ORIGIN", `${label} response URL is invalid`, { cause });
    }
    invariant(resolved.origin === configured.origin, `${label} redirected across origins`, "SOURCE_ORIGIN");
  }
  try {
    return await response.json();
  } catch (cause) {
    throw new CanonicalProjectError("JSON", `${label} is not valid JSON`, { cause });
  }
}

export async function loadCanonicalProjectModel({
  fetchImpl = globalThis.fetch,
  contractUrl = PROJECTS_CONTRACT_URL,
  baseUrl = globalThis.document?.baseURI || globalThis.location?.href || null,
} = {}) {
  invariant(typeof fetchImpl === "function", "fetch implementation is unavailable");
  invariant(isSameOriginRelativePath(contractUrl), "contract URL is not a safe same-origin relative path", "SOURCE_ORIGIN");
  const contract = validateProjectsContract(await fetchJson(fetchImpl, contractUrl, "contract", baseUrl));
  const payload = await fetchJson(fetchImpl, contract.release_state.target_project_source, "project payload", baseUrl);
  return buildCanonicalProjectModel(payload, contract);
}

Committed JSON V9 7

A JavaScript module in the adapters folder of GlobalGrid2050.

Set aside from the main view: The function `committedJsonItemsV9_7` (lines 1-14) is the same code, apart from spacing and comments, as `committedJsonItemsV9_7` kept in stars library/standalone.mjs (lines 2636-2649); it is the whole file. (unit-duplicate-of, proposed by units.py). The file that stays: Standalone. All set-aside files, with reasons. Nothing was deleted.

Evidence
  • exact_hash equal: bdba78cfb636e0db (target stars@030ebc202d35959fecd162327892f671d1d9a0cc library/standalone.mjs:2636-2649 fc3d8c8b93e14d4a56b8a26da47071d60bc5bc4d)
  • cluster of 2 units in 2 files across 2 repositories
  • files otherwise different: unit exact_hash Jaccard between the two files 0.00 (< 0.8)
  • target chosen by canonical_status unknown, not a core repository, reachable

transformglobalgrid2050 / testcode/202609051152/pipeline/scripts/news/adapters/committed-json-v9-7.mjs · lines 1–14 of 14 · version 2026-09-05 11:52 · Not reached from any entry point (candidate for review)

What it does
It calculates its inputs. Defines committedJsonItemsV9_7.
Why it exists in the grid workflow
Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
What it achieves
Defines `committedJsonItemsV9_7`.
Why it matters
No other file in the estate was found to import it.
Application
globalgrid2050 · testcode/202609051152/pipeline/scripts/news/adapters · JavaScript module
Uses
none found
Used by
mentioned in Standalone (comment link)
Produces
committedJsonItemsV9_7
Defines here
committedJsonItemsV9_7
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609051152/pipeline/scripts/news/adapters/committed-json-v9-7.mjs:1-14 · blob 10e6699a8721585b32cefcbbe3abacc994d6a75f · GitHub at these lines
State
achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: unreached_review
export function committedJsonItemsV9_7(payload, adapter) {
  if (adapter?.kind !== "committed-json-snapshot" || !adapter.input_collection) {
    throw new Error("unsupported or incomplete V9.7 source adapter");
  }
  const items = payload?.[adapter.input_collection];
  if (!Array.isArray(items)) throw new Error(`missing source collection ${adapter.input_collection}`);
  const required = ["headline", "url", "source", "published"];
  for (const [index, item] of items.entries()) {
    for (const field of required) {
      if (!String(item?.[field] || "").trim()) throw new Error(`source item ${index} missing ${field}`);
    }
  }
  return items;
}

Classifier V9 7

A JavaScript module in the news folder of GlobalGrid2050 that works with solar. It classifies regional v9 (`classifyRegionalV9_7`).

transformglobalgrid2050 / testcode/202609051152/pipeline/scripts/news/classifier-v9-7.mjs · lines 1–38 of 38 · version 2026-09-05 11:52

What it does
It calculates solar. Defines classifyRegionalV9_7.
Why it exists in the grid workflow
Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: solar.
Downstream impact
Used directly by 3 files: Ledger V9 7 (globalgrid2050); Check V9 7 (globalgrid2050); Check V9 7 (globalgrid2050). Reached from 2 other entry points, including GlobalGrid2050 V9 7 Validate Workflow (globalgrid2050); Run V9 7 (globalgrid2050).
What it achieves
Defines `classifyRegionalV9_7`.
Why it matters
Imported by Ledger V9 7. Checked by 2 tests, including Check V9 7.
Application
globalgrid2050 · testcode/202609051152/pipeline/scripts/news · JavaScript module
Uses
Geography V9 7 (import), Technology V9 7 (import), UK Veto V9 7 (import)
Used by
imported by Ledger V9 7 (import), imported by Check V9 7 (import), imported by Check V9 7 (import)
Produces
CLASSIFIER_VERSION, classifyRegionalV9_7
Defines here
classifyRegionalV9_7
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609051152/pipeline/scripts/news/classifier-v9-7.mjs:1-38 · blob 7bb8b22e5a745bc2c8b6f0613377cf77ede3780c · GitHub at these lines
State
achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: production_core
import { geographyEvidenceV9_7 } from "./rules/geography-v9-7.mjs";
import { technologyEvidenceV9_7, utilityContextEvidenceV9_7 } from "./rules/technology-v9-7.mjs";
import { inheritedUkEvidenceV9_7 } from "./rules/uk-veto-v9-7.mjs";

export const CLASSIFIER_VERSION = "v9.7.0";

export function classifyRegionalV9_7(item) {
  const headline = String(item?.headline || "").trim();
  const technology = technologyEvidenceV9_7(headline);
  const ukEvidence = inheritedUkEvidenceV9_7(item);
  const base = { technology: technology.technology, evidence: technology.terms };

  if (item?.canonical_relevant === true) {
    return { ...base, decision: "UK_CANONICAL", reason: "canonical UK story stays outside the regional pipeline", evidence: [ukEvidence] };
  }
  if (ukEvidence) {
    return { ...base, decision: "REJECT_UK_EVIDENCE", reason: "UK evidence vetoed regional classification", evidence: [ukEvidence, ...technology.terms] };
  }
  if (!technology.technology) {
    return { ...base, decision: "ABSTAIN_NO_TECHNOLOGY", reason: "no explicit solar or battery technology evidence" };
  }
  const context = utilityContextEvidenceV9_7(headline);
  if (!context) {
    return { ...base, decision: "ABSTAIN_NO_UTILITY_CONTEXT", reason: "technology term lacks utility-scale project or market context" };
  }
  const location = geographyEvidenceV9_7(headline);
  if (!location) {
    return { ...base, decision: "ABSTAIN_NO_EXPLICIT_GEOGRAPHY", reason: "no explicit, case-safe non-UK geography", evidence: [...technology.terms, context] };
  }
  return {
    decision: "ACCEPT_REGIONAL",
    reason: "explicit non-UK geography with utility-scale solar or battery context",
    region: location.region,
    country: location.country,
    technology: technology.technology,
    evidence: [...technology.terms, context, location.evidence],
  };
}

Ledger V9 7

A JavaScript module in the news folder of GlobalGrid2050 that builds regional artifacts v9 (`buildRegionalArtifactsV9_7`), using SHA-256.

transformglobalgrid2050 / testcode/202609051152/pipeline/scripts/news/ledger-v9-7.mjs · lines 1–76 of 76 · version 2026-09-05 11:52 · Not reached from any entry point (candidate for review) · pattern stableId (shared by 3 files)

What it does
It calculates its inputs. Defines sha256, stableId, buildRegionalArtifactsV9_7. Uses libraries node:crypto.
Why it exists in the grid workflow
Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
What it achieves
It builds regional artifacts v9 (`buildRegionalArtifactsV9_7`) and is built from the stable id helper (`stableId`). Defines `sha256`, `stableId` and `buildRegionalArtifactsV9_7`.
Why it matters
No other file in the estate was found to import it.
Application
globalgrid2050 · testcode/202609051152/pipeline/scripts/news · JavaScript module
Uses
Classifier V9 7 (import), node:crypto
Used by
none found
Produces
buildRegionalArtifactsV9_7
Defines here
sha256, stableId, buildRegionalArtifactsV9_7
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609051152/pipeline/scripts/news/ledger-v9-7.mjs:1-76 · blob fb2a84f95796be16a4b4dbc0e7f302d1dba60904 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: unreached_review
import { createHash } from "node:crypto";
import { CLASSIFIER_VERSION, classifyRegionalV9_7 } from "./classifier-v9-7.mjs";

const sha256 = (value) => createHash("sha256").update(value).digest("hex");
const stableId = (item) => `GG2050-REGION-${sha256(`${item.url || ""}\n${item.headline || ""}`).slice(0, 16).toUpperCase()}`;

export function buildRegionalArtifactsV9_7(items, sourceMeta) {
  const decisions = [];
  const articles = [];
  for (const item of items) {
    const articleId = stableId(item);
    const classification = classifyRegionalV9_7(item);
    const common = {
      article_id: articleId,
      headline: String(item.headline || "").trim(),
      url: String(item.url || "").trim(),
      source: String(item.source || "").trim(),
      published: String(item.published || "").trim(),
    };
    decisions.push({
      ...common,
      decision: classification.decision,
      reason: classification.reason,
      evidence: classification.evidence || [],
      classifier_version: CLASSIFIER_VERSION,
      project_signal_eligible: false,
      canonical_identity: false,
    });
    if (classification.decision === "ACCEPT_REGIONAL") {
      articles.push({
        ...common,
        technology: classification.technology,
        country: classification.country,
        region: classification.region,
        evidence: classification.evidence,
        classifier_version: CLASSIFIER_VERSION,
        project_signal_eligible: false,
        canonical_identity: false,
      });
    }
  }
  const byDecision = Object.fromEntries([...new Set(decisions.map((item) => item.decision))].sort()
    .map((decision) => [decision, decisions.filter((item) => item.decision === decision).length]));
  const byRegion = Object.fromEntries(["US", "EUROPE", "INTERNATIONAL_OTHER"]
    .map((region) => [region, articles.filter((item) => item.region === region).length]));
  const dates = items.map((item) => item.published).filter(Boolean).sort();
  const sources = [...new Set(items.map((item) => item.source).filter(Boolean))].sort();
  return {
    regional: {
      schema: "globalgrid2050.regional-news.v9.7",
      release: "9.7",
      classifier_version: CLASSIFIER_VERSION,
      generated_from: sourceMeta.id,
      articles,
    },
    ledger: {
      schema: "globalgrid2050.regional-news-decisions.v9.7",
      release: "9.7",
      classifier_version: CLASSIFIER_VERSION,
      generated_from: sourceMeta.id,
      decisions,
    },
    telemetry: {
      input_count: items.length,
      accepted_count: articles.length,
      by_decision: byDecision,
      by_region: byRegion,
      source_count: sources.length,
      sources,
      earliest_published: dates[0] || null,
      latest_published: dates.at(-1) || null,
      invalid_url_count: items.filter((item) => !/^https:\/\//.test(String(item.url || ""))).length,
      last_known_good: articles.length > 0,
    },
  };
}

Geography V9 7

A JavaScript module in the rules folder of GlobalGrid2050. It is built from the geography evidence v9 7 helper (`geographyEvidenceV9_7`).

transformglobalgrid2050 / testcode/202609051152/pipeline/scripts/news/rules/geography-v9-7.mjs · lines 1–32 of 32 · version 2026-09-05 11:52

What it does
It calculates its inputs. Defines geographyEvidenceV9_7.
Why it exists in the grid workflow
Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
Downstream impact
Used directly by 1 file: Classifier V9 7 (globalgrid2050). Reached from 2 other entry points, including GlobalGrid2050 V9 7 Validate Workflow (globalgrid2050); Run V9 7 (globalgrid2050).
What it achieves
Defines `geographyEvidenceV9_7`.
Why it matters
Imported by Classifier V9 7.
Application
globalgrid2050 · testcode/202609051152/pipeline/scripts/news/rules · JavaScript module
Uses
none found
Used by
imported by Classifier V9 7 (import)
Produces
geographyEvidenceV9_7
Defines here
geographyEvidenceV9_7
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609051152/pipeline/scripts/news/rules/geography-v9-7.mjs:1-32 · blob 6a66671948c1629865afea292cd072fe30a8a663 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: production_core
const LOCATION_RULES = [
  { region: "US", country: "United States", label: "US acronym", regex: /\b(?:US|USA)\b(?!\$)|\bU\.S\.(?:A\.)?(?!\$)/ },
  { region: "US", country: "United States", label: "United States", regex: /\bUnited States\b/i },
  { region: "US", country: "United States", label: "US state or city", regex: /\b(?:New Jersey|Virginia|California|Arizona|Texas|New York|Florida|Illinois|Ohio|Pennsylvania|Colorado|Nevada|Oregon|Washington State|Massachusetts|Connecticut|Maryland|Michigan|Minnesota|Wisconsin|Georgia|North Carolina|South Carolina|Tennessee|Kentucky|Indiana|Iowa|Kansas|Missouri|Oklahoma|New Mexico|Utah|Idaho|Montan  … [line shortened here: 576 characters; full line on GitHub]
  { region: "EUROPE", country: "European Union", label: "EU acronym", regex: /\bEU\b/ },
  { region: "EUROPE", country: "Europe", label: "Europe", regex: /\b(?:Europe|European Union)\b/i },
  { region: "EUROPE", country: "Ireland", label: "Ireland", regex: /\b(?:Ireland|Irish)\b/i },
  { region: "EUROPE", country: "Germany", label: "Germany", regex: /\b(?:Germany|German)\b/i },
  { region: "EUROPE", country: "France", label: "France", regex: /\b(?:France|French)\b/i },
  { region: "EUROPE", country: "Spain", label: "Spain", regex: /\b(?:Spain|Spanish)\b/i },
  { region: "EUROPE", country: "Italy", label: "Italy", regex: /\b(?:Italy|Italian)\b/i },
  { region: "EUROPE", country: "Switzerland", label: "Switzerland", regex: /\b(?:Switzerland|Swiss)\b/i },
  { region: "EUROPE", country: "Romania", label: "Romania", regex: /\b(?:Romania|Romanian)\b/i },
  { region: "EUROPE", country: "Greece", label: "Greece", regex: /\b(?:Greece|Greek)\b/i },
  { region: "EUROPE", country: "Europe", label: "European country", regex: /\b(?:Netherlands|Dutch|Belgium|Belgian|Poland|Polish|Portugal|Portuguese|Denmark|Danish|Sweden|Swedish|Norway|Norwegian|Finland|Finnish|Austria|Austrian|Czechia|Czech|Bulgaria|Bulgarian|Hungary|Hungarian|Croatia|Croatian|Serbia|Serbian|Slovenia|Slovakia|Estonia|Latvia|Lithuania|Ukraine|Moldova|Luxembourg|Cyprus|Malta|Icela  … [line shortened here: 459 characters; full line on GitHub]
  { region: "INTERNATIONAL_OTHER", country: "Australia", label: "Australia", regex: /\b(?:Australia|Australian)\b/i },
  { region: "INTERNATIONAL_OTHER", country: "Japan", label: "Japan", regex: /\b(?:Japan|Japanese)\b/i },
  { region: "INTERNATIONAL_OTHER", country: "Chile", label: "Chile", regex: /\bChile\b/i },
  { region: "INTERNATIONAL_OTHER", country: "South Korea", label: "South Korea", regex: /\b(?:South Korea|Republic of Korea)\b/i },
  { region: "INTERNATIONAL_OTHER", country: "International", label: "non-UK country", regex: /\b(?:Canada|India|China|Chinese|South Africa|New Zealand|Brazil|Brazilian|Mexico|Mexican|UAE|United Arab Emirates|Saudi Arabia|Taiwan|Philippines|Argentina|Turkey|Turkiye|Israel|Vietnam|Indonesia|Thailand|Singapore|Africa|Asia|Latin America|Middle East)\b/i },
];

export function geographyEvidenceV9_7(headline) {
  const value = String(headline || "");
  const rule = LOCATION_RULES.find((candidate) => candidate.regex.test(value));
  if (!rule) return null;
  return Object.freeze({
    region: rule.region,
    country: rule.country,
    evidence: value.match(rule.regex)?.[0] || rule.label,
  });
}

Technology V9 7

A JavaScript module in the rules folder of GlobalGrid2050 that works with solar and battery storage (BESS). It is built from the technology evidence v9 7 helper (`technologyEvidenceV9_7`).

transformglobalgrid2050 / testcode/202609051152/pipeline/scripts/news/rules/technology-v9-7.mjs · lines 1–17 of 17 · version 2026-09-05 11:52

What it does
It calculates solar and battery storage (BESS). Defines technologyEvidenceV9_7, utilityContextEvidenceV9_7.
Why it exists in the grid workflow
Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: solar, battery storage (BESS).
Downstream impact
Used directly by 1 file: Classifier V9 7 (globalgrid2050). Reached from 2 other entry points, including GlobalGrid2050 V9 7 Validate Workflow (globalgrid2050); Run V9 7 (globalgrid2050).
What it achieves
Defines `technologyEvidenceV9_7` and `utilityContextEvidenceV9_7`.
Why it matters
Imported by Classifier V9 7.
Application
globalgrid2050 · testcode/202609051152/pipeline/scripts/news/rules · JavaScript module
Uses
none found
Used by
imported by Classifier V9 7 (import)
Produces
technologyEvidenceV9_7, utilityContextEvidenceV9_7
Defines here
technologyEvidenceV9_7, utilityContextEvidenceV9_7
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609051152/pipeline/scripts/news/rules/technology-v9-7.mjs:1-17 · blob cc273037c84e835ec33a6a3c3e0a505685250b73 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: production_core
const SOLAR = /\b(?:solar|photovoltaic(?:s)?|pv|agrivoltaic(?:s)?)\b/i;
const BESS = /\b(?:bess|battery|batteries|energy storage|grid storage)\b/i;
const UTILITY_CONTEXT = /\b(?:project|projects|system|systems|portfolio|plant|farm|construction|commission(?:ed|ing)?|financ(?:e|ed|ing|ial)|acquir(?:e|es|ed|ing)|acquisition|stake|market|grid|utility|utilities|capacity|operations|services|deal|deals|proposal|online|developer|cluster|roundup|rfps?|facility|facilities|mw|mwh|gw|gwh|nem|tso)\b/i;

export function technologyEvidenceV9_7(headline) {
  const value = String(headline || "");
  const solar = value.match(SOLAR)?.[0] || "";
  const bess = value.match(BESS)?.[0] || "";
  return {
    technology: solar && bess ? "SOLAR + BESS" : solar ? "SOLAR" : bess ? "BESS" : "",
    terms: [solar, bess].filter(Boolean),
  };
}

export function utilityContextEvidenceV9_7(headline) {
  return String(headline || "").match(UTILITY_CONTEXT)?.[0] || "";
}

UK Veto V9 7

A JavaScript module in the rules folder of GlobalGrid2050.

transformglobalgrid2050 / testcode/202609051152/pipeline/scripts/news/rules/uk-veto-v9-7.mjs · lines 1–22 of 22 · version 2026-09-05 11:52

What it does
It calculates its inputs. Defines normalise, inheritedUkEvidenceV9_7.
Why it exists in the grid workflow
Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
Downstream impact
Used directly by 1 file: Classifier V9 7 (globalgrid2050). Reached from 2 other entry points, including GlobalGrid2050 V9 7 Validate Workflow (globalgrid2050); Run V9 7 (globalgrid2050).
What it achieves
Defines `normalise` and `inheritedUkEvidenceV9_7`.
Why it matters
Imported by Classifier V9 7.
Application
globalgrid2050 · testcode/202609051152/pipeline/scripts/news/rules · JavaScript module
Uses
none found
Used by
imported by Classifier V9 7 (import)
Produces
inheritedUkEvidenceV9_7
Defines here
normalise, inheritedUkEvidenceV9_7
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609051152/pipeline/scripts/news/rules/uk-veto-v9-7.mjs:1-22 · blob 8690f6e9b22c6074f0d8fc20aab680c267f8e4e7 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: production_core
const UK = /\b(?:UK|U\.K\.|United Kingdom|Britain|British|England|English|Scotland|Scottish|Wales|Welsh|Northern Ireland|North Yorkshire|Lincolnshire|Nottinghamshire|Devon|Cornish|Cumbria|Suffolk|Kent|Surrey|Gloucestershire|Oxfordshire|Warwickshire|Yorkshire|Essex|Norfolk|Somerset|Dorset|Lancashire|Derbyshire|Leicestershire|Cambridgeshire|Bedfordshire|Hertfordshire|Buckinghamshire|Worcestershire|S  … [line shortened here: 572 characters; full line on GitHub]
const GENERIC_PROJECT = new Set([
  "and", "the", "farm", "solar", "battery", "bess", "storage", "energy", "park", "site",
  "road", "lane", "wind", "offshore", "onshore", "project", "phase", "extension", "facility",
  "system", "scheme", "development", "power", "limited", "ltd", "centre", "center", "grid",
  "services", "complex", "south", "north", "east", "west", "southern", "northern", "eastern",
  "western", "california", "virginia", "jersey", "australia", "germany", "france", "spain",
  "italy", "ireland", "romania", "greece", "chile", "japan",
]);

const normalise = (value) => String(value || "").toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();

export function inheritedUkEvidenceV9_7(item) {
  if (item?.canonical_relevant === true) return "canonical REPD PRIMARY_MATCH";
  const headline = String(item?.headline || "");
  if (UK.test(headline)) return `explicit UK geography: ${headline.match(UK)?.[0]}`;
  const normalisedHeadline = normalise(headline);
  const projectToken = normalise(item?.project).split(" ")
    .find((token) => token.length >= 5 && !GENERIC_PROJECT.has(token) && normalisedHeadline.includes(token));
  if (projectToken && String(item?.county || "").trim()) return `inherited UK project veto: ${projectToken}`;
  return "";
}