GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Maps, GIS and field navigation / gridatlas / tools

GridAtlas Recompose and 2 more files

A JavaScript module in the tools folder that uses SHA-256. It reads JSON (`readJson`) and writes JSON (`writeJson`).

649 lines of JavaScript from gridatlas, in 3 files. Topic: Maps, GIS and field navigation. Section 665 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. GridAtlas Recompose storage · gridatlas / tools/recompose.mjs lines 1–484
  2. Acceptance automation · gridatlas / tools/release/acceptance.mjs lines 1–80
  3. Check Live automation · gridatlas / tools/release/check-live.mjs lines 1–85

GridAtlas Recompose

A JavaScript module in the tools folder that uses SHA-256. It reads JSON (`readJson`) and writes JSON (`writeJson`).

storagegridatlas / tools/recompose.mjs · lines 1–484 of 484 · pattern scoped (shared by 2 files)

What it does
It loads data. Defines 9 functions or classes, including argv, utcNow, die, scoped, minute. Uses libraries node:fs, node:path, node:child_process, node:crypto, node:url. Side effects: reads or writes files; starts processes.
Why it exists in the grid workflow
Domain stage upstream_foresight (repository name word 'gridatlas'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight.
Inputs & outputs
In: JSON file current.json; JSON file live-set.json; JSON file current-v5.json; command-line arguments.
Downstream impact
Used directly by 2 files: Shift (gridatlas); GridAtlas Rollback (gridatlas). Reached from 28 other entry points, including GridAtlas Cartridge Proof Workflow (gridatlas); GridAtlas PR File Size Guard Workflow (gridatlas); GridAtlas Rollback Composition Workflow (gridatlas).
What it achieves
Cut a new composition generation.
Why it matters
Run by Shift and GridAtlas Rollback.
Application
gridatlas · tools · JavaScript module
Uses
node:fs, node:path, node:child_process, node:crypto, node:url
Used by
run by Shift (script call), run by GridAtlas Rollback (script call)
Produces
argv, utcNow, die, scoped, minute, sha256, readJson, writeJson, forThis
Defines here
argv, utcNow, die, scoped, minute, sha256, readJson, writeJson, forThis
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/recompose.mjs:1-484 · blob a51edfd83c83ccf98b395af75172131d9f8f1d05 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: filesystem, process · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
/**
 * Cut a new composition generation.
 *
 * Every generation tonight was cut by hand: rename the cartridge, rename its
 * proof, edit current.json, write a composition manifest, update three
 * pointers, hope nothing was missed. Three separate identity defects came out
 * of exactly that - a manifest that still named an older composition for four
 * generations, and twice a proof left asserting the generation before the one
 * it was running against. The habit is "restamp what I am editing and trust
 * the rest", and the only fix is to stop doing it by hand.
 *
 * This restamps ONLY the cartridges named on the command line. A cartridge
 * that did not change keeps its own generation, which is why the composition
 * carries mixed stamps and should.
 *
 *   node tools/recompose.mjs --version v9.64 --restamp sld-sandbox \
 *     --scope "..." --proof ... --note "why this generation exists"
 *
 *   --acceptance-json '{"producer":{"commit":"..."}}' replaces named
 *   acceptance fields for this cut. Scope, proof paths and browser status
 *   remain generated by the composer and cannot be overridden.
 *
 *   The generation is read from the clock (UTC). --generation is accepted
 *   only within five minutes of now; --replace-module old=new swaps a
 *   module for its successor; --replace-part old=new can replace a carried
 *   engine or body with an immutable successor; --add-module appends one.
 *
 * A restamped cartridge with a parts manifest is REASSEMBLED from the same
 * part list through tools/build-cartridge.mjs, so an edited part actually
 * reaches the served bytes. One without is copied forward verbatim.
 *
 * It does not touch the immutable shell, and it never rewrites an existing
 * generation: build-cartridge refuses that, and so does this.
 */

import fs from 'node:fs';
import path from 'node:path';
import { spawnSync } from 'node:child_process';
import { createHash } from 'node:crypto';
import { fileURLToPath } from 'node:url';

const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const ATLAS = path.join(ROOT, 'atlas');

function argv(flag, { many = false } = {}) {
  const values = [];
  for (let i = 2; i < process.argv.length; i += 1) {
    if (process.argv[i] === flag) values.push(process.argv[i + 1]);
  }
  return many ? values : values[0];
}

/* The generation is READ FROM THE CLOCK, never typed.
   ------------------------------------------------------------------------
   On the evening of 1 Sep 2026 two agents typed stamps by hand and both ran
   ahead of the clock: v9.67 is named 202609012250 and was cut at 18:51 UTC,
   four hours before the time its name claims. The CVAA vaccine
   monotonic-utc-generations had said since 30 Aug that "generations are
   read from date -u at commit time, never chosen"; it was in the registry
   and not in the loop, and it fired 122 times when it was finally run.

   So --generation is optional and defaults to UTC now. Given explicitly it
   must be within five minutes of UTC now: a stamp is a clock reading, and
   a reading the clock has not reached is not a reading. */
const utcNow = () => new Date().toISOString().replace(/[-:T]/g, '').slice(0, 12);
/* Validation can fail before any filesystem mutation (for example while
   parsing --acceptance-json), so the rollback stack must exist before the
   first call site that can invoke die(). */
const undo = [];
function die(message) {
  while (undo.length) {
    const step = undo.pop();
    try { step(); } catch { /* best effort; the message below matters more */ }
  }
  console.error(message);
  process.exit(1);
}
const generation = argv('--generation') || utcNow();
const version = argv('--version');
const restamp = argv('--restamp', { many: true });
/* Module edits may be scoped to ONE restamped cartridge.
   ------------------------------------------------------------------------
   `--add-module path` applied to every cartridge named by --restamp, which
   was harmless while exactly one was ever restamped. The moment a cut moves
   computation from one cartridge to another - 202609012350, when the
   sandbox reached 95% of its 400 kB boundary - it stops being harmless: the
   same module would be added to both halves of the move.

   So both flags now accept `cartridge-id=path` as well as a bare `path`.
   A bare path keeps the old meaning (every restamped cartridge), because
   every existing caller writes one. */
const scoped = (flag) => argv(flag, { many: true }).map((raw) => {
  const text = String(raw);
  const split = text.indexOf('=');
  /* A path never contains '=', and a cartridge id is never a path, so the
     first '=' is unambiguous - but only when what precedes it looks like an
     id rather than the start of a path. */
  if (split > 0 && !text.slice(0, split).includes('/')) {
    return { id: text.slice(0, split), path: text.slice(split + 1) };
  }
  return { id: null, path: text };
});
const addModules = scoped('--add-module');
const removeModules = scoped('--remove-module');
const partsSeeds = scoped('--parts-from');
const replaceModules = argv('--replace-module', { many: true })
  .map(pair => {
    const [from, to] = String(pair).split('=');
    if (!from || !to) die(`--replace-module wants old/path.js=new/path.js, got ${pair}`);
    return { from, to };
  });
const replaceParts = argv('--replace-part', { many: true })
  .map(pair => {
    const [from, to] = String(pair).split('=');
    if (!from || !to) die(`--replace-part wants old/path.js=new/path.js, got ${pair}`);
    return { from, to };
  });
const scope = argv('--scope');
/* A caller that does not know the clock minute (the overnight runner, which
   lets this tool read it) writes {generation} in the proof path; it resolves
   to the generation this cut is stamped with, i.e. the renamed proof. */
const proofs = argv('--proof', { many: true })
  .map(proofPath => String(proofPath).split('{generation}').join(generation));
const note = argv('--note') || '';
const acceptanceRaw = argv('--acceptance-json');
let acceptanceOverrides = {};
if (acceptanceRaw) {
  try {
    acceptanceOverrides = JSON.parse(acceptanceRaw);
  } catch (error) {
    die(`--acceptance-json is not JSON: ${error?.message || error}`);
  }
  if (!acceptanceOverrides || Array.isArray(acceptanceOverrides)
      || typeof acceptanceOverrides !== 'object') {
    die('--acceptance-json must be a JSON object');
  }
}

/* A failed cut must not leave a half-composed tree.
   ------------------------------------------------------------------------
   The first run of this tool died on its own acceptance guard AFTER it had
   assembled a cartridge and renamed a proof, leaving exactly the half-state
   the assembler was hardened against an hour earlier. Every mutation
   registers its undo; die() runs them newest first. */
if (!/^[0-9]{12}$/.test(generation)) die('--generation must be YYYYMMDDHHMM (UTC), or omitted to read the clock');
{
  const minute = (s) => Date.UTC(+s.slice(0, 4), +s.slice(4, 6) - 1, +s.slice(6, 8), +s.slice(8, 10), +s.slice(10, 12)) / 60000;
  const drift = minute(generation) - minute(utcNow());
  if (Math.abs(drift) > 5) {
    die(`--generation ${generation} is ${drift > 0 ? drift + ' minutes ahead of' : (-drift) + ' minutes behind'} `
      + `the clock (UTC now ${utcNow()}). A stamp is read from the clock, not chosen; omit --generation.`);
  }
}
if (!version || !/^v\d+\.\d+$/.test(version)) die('--version vX.Y is required');
if (!restamp.length) die('--restamp <cartridge-id> is required at least once');
/* The first cut of this tool spread the previous composition manifest and
   inherited its acceptance block whole, so the new generation shipped
   claiming the PREVIOUS generation's scope sentence and proof paths. That
   is the identity lie this tool exists to prevent, reproduced by the tool
   itself. Both are now required per generation and checked. */
if (!scope) die('--scope "what this generation changes" is required');
if (!proofs.length) die('--proof <path> is required at least once');

const sha256 = (text) => createHash('sha256')
  .update(String(text).replace(/\r\n/g, '\n'), 'utf8').digest('hex');
const readJson = (file) => JSON.parse(fs.readFileSync(file, 'utf8'));
const writeJson = (file, value) =>
  fs.writeFileSync(file, `${JSON.stringify(value, null, 1)}\n`, 'utf8');

const currentPath = path.join(ATLAS, 'current.json');
const current = readJson(currentPath);
const previousGeneration = current.generation;

/* Ordering is a consequence of the clock, not a rule of its own.
   ------------------------------------------------------------------------
   This used to refuse a generation that sorted before the current one.
   Read from the clock, a new cut sorts after the previous one whenever the
   previous one was honest. The one time it does not is the time this note
   describes: the generation after v9.67 (202609012250, cut at 18:51 UTC)
   was read from the clock at 21:xx UTC and sorts before it. The chain is
   previous_generation, which is a pointer; a listing sorted by name shows
   the lie of the earlier stamp, and should. */
if (generation <= previousGeneration) {
  console.warn(`  note: ${generation} sorts before the current ${previousGeneration} - `
    + 'the earlier stamp was typed ahead of the clock; the chain is previous_generation');
}
const compositionPath = path.join(ATLAS, 'manifests', `${generation}-composition.json`);
if (fs.existsSync(compositionPath)) {
  die(`refusing to rewrite an existing composition: ${generation}-composition.json`);
}

const changed = [];
const followUps = [];

for (const id of restamp) {
  const cartridge = (current.cartridges || []).find(entry => entry.id === id);
  if (!cartridge) die(`no cartridge with id ${id} in the current composition`);

  const oldGeneration = cartridge.generation;
  const oldFile = path.basename(cartridge.path);
  const stem = oldFile.replace(new RegExp(`^${oldGeneration}-`), '').replace(/\.js$/, '');
  const newFile = `${generation}-${stem}.js`;
  const newPath = path.join(ATLAS, 'cartridges', newFile);
  if (fs.existsSync(newPath)) die(`refusing to overwrite ${newFile}`);

  /* A cartridge that has never been assembled has no manifest to read.
     ----------------------------------------------------------------------
     `--parts-from <id>=<path>` seeds one for exactly that case. The seed is
     NOT written into atlas/manifests/: a manifest there is a record of how
     a shipped generation was actually built, and back-dating one that
     cannot reproduce its own cartridge byte-for-byte would be a false
     record of the kind this estate keeps finding. The seed is an input to
     THIS cut; the manifest the cut writes is stamped with the new
     generation and does reproduce its cartridge, because it built it. */
  let partsManifest = path.join(ATLAS, 'manifests', `${oldGeneration}-${stem}-parts.json`);
  if (!fs.existsSync(partsManifest)) {
    const seed = partsSeeds.find(s => s.id === id);
    if (seed) {
      const seedPath = path.join(ROOT, seed.path);
      if (!fs.existsSync(seedPath)) die(`--parts-from: no such seed ${seed.path}`);
      partsManifest = seedPath;
      console.log(`  seed       ${id} assembled from ${seed.path}`);
    }
  }
  if (fs.existsSync(partsManifest)) {
    /* Reassembled, not copied: the point of restamping an assembled
       cartridge is that one of its parts moved. */
    const parts = readJson(partsManifest).assembled_from || [];

    /* A carried shell script is immutable at its release path, but the
       cartridge that supersedes its slot may deliberately carry a reviewed
       successor. Replace the input path in THIS generation's derived parts
       list; never rewrite the earlier parts manifest or payload. */
    for (const swap of replaceParts) {
      const entry = parts.find(e => e.path === swap.from);
      if (!entry) continue;
      if (!fs.existsSync(path.join(ROOT, swap.to))) die(`no such replacement part: ${swap.to}`);
      entry.path = swap.to;
      swap.applied = true;
      console.log(`  ~part      ${swap.from} -> ${swap.to}  (in ${id})`);
    }

    /* A cartridge can gain a module at a cut.
       -------------------------------------------------------------------
       Without this, the reassembly reproduces the previous part list
       exactly, and a new module written for this generation is simply not
       in the served bytes - the body calls `sourceRegistry` and finds
       undefined. That happened on the first attempt at v9.67. A module is
       inserted BEFORE the non-module parts, because a body that depends on
       a module must be evaluated after it. */
    /* A swap must land somewhere, but not necessarily in EVERY restamped
       cartridge - dying per cartridge was correct only while one was ever
       restamped at a time. Misses are tolerated here and the miss is
       reported after the loop if no cartridge took it. */
    for (const swap of replaceModules) {
      const entry = parts.find(e => e.role === 'module' && e.path === swap.from);
      if (!entry) continue;
      if (!fs.existsSync(path.join(ROOT, swap.to))) die(`no such module: ${swap.to}`);
      entry.path = swap.to;
      swap.applied = true;
      console.log(`  ~module    ${swap.from} -> ${swap.to}  (in ${id})`);
    }
    const forThis = (edit) => edit.id === null || edit.id === id;

    /* Removals run BEFORE additions so a cut can move a module from one
       cartridge to another in a single generation without the two edits
       racing over the same part list. */
    for (const edit of removeModules.filter(forThis)) {
      const at = parts.findIndex(e => e.role === 'module' && e.path === edit.path);
      if (at < 0) die(`--remove-module: ${edit.path} is not a module of ${id}`);
      parts.splice(at, 1);
      console.log(`  -module    ${edit.path}  (from ${id})`);
    }
    for (const edit of addModules.filter(forThis)) {
      const modulePath = edit.path;
      if (parts.some(entry => entry.path === modulePath)) continue;
      if (!fs.existsSync(path.join(ROOT, modulePath))) die(`no such module: ${modulePath}`);
      const lastModule = parts.map(e => e.role).lastIndexOf('module');
      parts.splice(lastModule + 1, 0, { role: 'module', path: modulePath });
      console.log(`  +module    ${modulePath}  (into ${id})`);
    }

    /* The version ledger the page shows is written by the cut, not by hand.
       -------------------------------------------------------------------
       v9.64 shipped with a ledger whose newest entry said v9.63, so the
       page told its reader it was running the generation before the one it
       was actually running. That list is generated metadata — the scope
       sentence is already required above — and the only reason it ever went
       stale is that appending to it was a separate manual step. */
    for (const entry of parts) {
      const partPath = path.join(ROOT, entry.path);
      if (!fs.existsSync(partPath)) continue;
      const before = fs.readFileSync(partPath, 'utf8');
      const found = before.match(/const VERSION_LEDGER = (\[[\s\S]*?\]);/);
      if (!found) continue;
      const ledger = JSON.parse(found[1]);
      if (ledger.some(row => row.g === generation)) continue;
      ledger.push({ g: generation, v: version, s: scope });
      const after = before.slice(0, found.index)
        + `const VERSION_LEDGER = ${JSON.stringify(ledger)};`
        + before.slice(found.index + found[0].length);
      fs.writeFileSync(partPath, after, 'utf8');
      undo.push(() => fs.writeFileSync(partPath, before, 'utf8'));
      console.log(`  ledger     ${entry.path}  += ${version}`);
    }

    const args = ['--generation', generation, '--name', stem];
    const flagFor = { carried_shell_script: '--carry', module: '--module', part: '--part' };
    for (const entry of parts) {
      const flag = flagFor[entry.role];
      if (!flag) die(`unknown part role ${entry.role} in ${path.basename(partsManifest)}`);
      args.push(flag, entry.path);
    }
    const built = spawnSync(process.execPath,
      [path.join(ROOT, 'tools', 'build-cartridge.mjs'), ...args],
      { cwd: ROOT, encoding: 'utf8' });
    if (built.status !== 0) die(`assembly failed for ${id}: ${built.stderr || built.stdout}`);
    const partsOut = path.join(ATLAS, 'manifests', `${generation}-${stem}-parts.json`);
    undo.push(() => { fs.rmSync(newPath, { force: true }); fs.rmSync(partsOut, { force: true }); });
    /* The pointer follows the manifest that was actually written.
       --------------------------------------------------------------------
       It did not, and the drift was silent: at 202609012350 the sld-sandbox
       entry was on generation 202609012345 while its assembled_from still
       named ./manifests/202609012045-...-parts.json, five generations
       behind. Nothing read the field, which is exactly why it rotted -
       and a reader who did trust it would have been handed the wrong part
       list. This tool exists to stop that class of drift; it should not
       leave one in its own output. */
    const previousPointer = cartridge.assembled_from;
    cartridge.assembled_from = `./manifests/${generation}-${stem}-parts.json`;
    if (previousPointer && previousPointer !== cartridge.assembled_from) {
      console.log(`  pointer    assembled_from ${previousPointer} -> ${cartridge.assembled_from}`);
    }
    console.log(`  assembled  ${newFile}  from ${parts.length} part(s)`);
  } else {
    fs.copyFileSync(path.join(ATLAS, 'cartridges', oldFile), newPath);
    undo.push(() => fs.rmSync(newPath, { force: true }));
    console.log(`  copied     ${newFile}`);
  }

  // The proof travels with the cartridge, by the runner's own convention.
  const oldProof = path.join(ROOT, 'tools', 'proofs', `${oldGeneration}-${id}.proof.mjs`);
  const newProof = path.join(ROOT, 'tools', 'proofs', `${generation}-${id}.proof.mjs`);
  if (!fs.existsSync(oldProof)) die(`no proof to carry forward at ${path.relative(ROOT, oldProof)}`);
  if (fs.existsSync(newProof)) die(`refusing to overwrite ${path.basename(newProof)}`);
  fs.renameSync(oldProof, newProof);
  undo.push(() => fs.renameSync(newProof, oldProof));
  console.log(`  proof      ${path.basename(newProof)}`);

  /* Deliberately NOT rewritten. A proof that mentions an older generation is
     sometimes right - it may be asserting that the old identity is gone -
     and blanket substitution is the same reflex that caused the drift this
     tool exists to stop. They are reported, and a human decides. */
  const proofText = fs.readFileSync(newProof, 'utf8');
  const stale = proofText.split('\n')
    .map((line, index) => ({ line, number: index + 1 }))
    .filter(row => row.line.includes(oldGeneration) || row.line.includes(cartridge.version));
  if (stale.length) {
    followUps.push({ proof: path.relative(ROOT, newProof).replace(/\\/g, '/'), stale });
  }

  const bytes = fs.readFileSync(newPath, 'utf8');
  cartridge.generation = generation;
  cartridge.version = version;
  cartridge.path = `./cartridges/${newFile}`;
  cartridge.sha256 = sha256(bytes);
  changed.push({ id, from: oldFile, to: newFile, sha256: cartridge.sha256, oldGeneration });
}

/* A swap that matched no restamped cartridge is a typo, not a no-op. */
for (const swap of replaceModules) {
  if (!swap.applied) die(`--replace-module: ${swap.from} is not a module of any restamped cartridge`);
}
for (const swap of replaceParts) {
  if (!swap.applied) die(`--replace-part: ${swap.from} is not a part of any restamped cartridge`);
}

current.previous_generation = previousGeneration;
current.generation = generation;
current.composition_version = version;
current.composition_id = `${generation}-gridatlas-${version}`;
current.composition_manifest = `./manifests/${generation}-composition.json`;
if (note) current.composition_note = note;

/* The composition manifest is DERIVED from current.json, never restated.
   The four-generation identity lie came from restating it. */
const previousComposition = readJson(
  path.join(ATLAS, 'manifests', `${previousGeneration}-composition.json`));
for (const proof of proofs) {
  if (!fs.existsSync(path.join(ROOT, proof))) die(`no such proof: ${proof}`);
}
const composition = {
  ...previousComposition,
  // Rejection belongs to the generation that failed review. Inheriting it
  // would quarantine every successor even after the defect was repaired;
  // undefined is omitted by writeJson/JSON.stringify.
  candidate_status: undefined,
  generation,
  parent_generation: previousGeneration,
  cartridge_order: current.cartridge_order,
  cartridges: current.cartridges,
  composition_version: version,
  composition_id: current.composition_id,
  version,
  /* The clock, recorded beside the stamp, so a later reader can verify the
     name against the time without opening git. */
  cut_at_utc: new Date().toISOString(),
  acceptance: {
    ...previousComposition.acceptance,
    /* A new producer/corpus must replace its inherited receipt explicitly;
       carrying an old commit beneath a new exact-corpus claim is provenance
       drift. The three identity fields below remain composer-owned. */
    ...acceptanceOverrides,
    // Never inherited: these three describe THIS generation or they lie.
    scope,
    proof: proofs.join(', '),
    golden_browser_verification: 'PENDING_THIS_GENERATION'
  }
};
if (note) composition.note = note;

/* Last guard before it is written, and deliberately precise.
   ------------------------------------------------------------------------
   A proof path naming an older generation is usually CORRECT - a cartridge
   that did not change keeps its stamp, and so does its proof. What is never
   correct is naming the superseded proof of a cartridge that DID change, or
   describing this generation with the previous one's identity. */
for (const entry of changed) {
  const superseded = `${entry.oldGeneration}-${entry.id}.proof.mjs`;
  if (proofs.some(proofPath => proofPath.endsWith(superseded))) {
    die(`${superseded} was renamed by this cut; name the ${generation} proof instead`);
  }
}
for (const stale of [previousGeneration, previousComposition.composition_version]) {
  if (stale && String(scope).includes(stale)) {
    die(`--scope describes ${stale}; write the sentence for ${generation}`);
  }
}

writeJson(compositionPath, composition);
writeJson(currentPath, current);

const liveSetPath = path.join(ATLAS, 'state', 'live-set.json');
if (fs.existsSync(liveSetPath)) {
  const liveSet = readJson(liveSetPath);
  liveSet.generation = generation;
  liveSet.composition_manifest = current.composition_manifest;
  liveSet.cartridge_order = current.cartridge_order;
  writeJson(liveSetPath, liveSet);
}

for (const pointerPath of [path.join(ROOT, 'releases', 'current-v5.json'),
  path.join(ROOT, 'state', 'live-set.json')]) {
  if (!fs.existsSync(pointerPath)) continue;
  const pointer = readJson(pointerPath);
  if (pointer?.current?.atlas_composition) {
    pointer.current.atlas_composition.generation = generation;
    pointer.current.atlas_composition.manifest =
      current.composition_manifest.replace(/^\.\//, 'atlas/');
    pointer.current.atlas_composition.cartridge_order = current.cartridge_order;
    writeJson(pointerPath, pointer);
  }
}

const verified = spawnSync(process.execPath,
  [path.join(ROOT, 'tools', 'scope', 'verify-compose.mjs')],
  { cwd: ROOT, encoding: 'utf8' });
console.log(`\n${(verified.stdout || verified.stderr).trim()}`);
if (verified.status !== 0) die('composition verification failed; the tree is mid-cut and needs review');

console.log(`\ncomposed ${current.composition_id} from ${previousGeneration}`);
for (const entry of changed) console.log(`  ${entry.id}: ${entry.from} -> ${entry.to}`);

if (followUps.length) {
  console.log('\nproofs carried forward that still name the previous identity -'
    + '\nread each one and decide; do not assume it is stale:');
  for (const item of followUps) {
    console.log(`  ${item.proof}`);
    for (const row of item.stale.slice(0, 12)) {
      console.log(`    ${String(row.number).padStart(4)}  ${row.line.trim().slice(0, 96)}`);
    }
    if (item.stale.length > 12) console.log(`    ... ${item.stale.length - 12} more`);
  }
}

Acceptance

A JavaScript module in the tools folder of GridAtlas that labels cmd (`labelCmd`).

automationgridatlas / tools/release/acceptance.mjs · lines 1–80 of 80 · Entry point

What it does
Defines die, commentCmd, labelCmd. Side effects: starts processes.
Why it exists in the grid workflow
Domain stage upstream_foresight (repository name word 'gridatlas'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight.
Inputs & outputs
In: command-line arguments.
Downstream impact
It is itself an entry point (JavaScript module); no other file was found loading it.
What it achieves
It labels cmd (`labelCmd`) and is built from the die step (`die`) and the comment cmd helper (`commentCmd`). Step 3 of the delivery flow: the owner's acceptance of a preview generation.
Why it matters
No other file in the estate was found to import it; it is an entry point.
Application
gridatlas · tools/release · JavaScript module
Uses
GridAtlas — Release (import), Flow Lib (import)
Used by
none found
Produces
die, commentCmd, labelCmd
Defines here
die, commentCmd, labelCmd
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/release/acceptance.mjs:1-80 · blob 264ecc4e24175f257e9a185eba9bddc8fc20f2d4 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: unknown · effects: process · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
#!/usr/bin/env node
/**
 * Step 3 of the delivery flow: the owner's acceptance of a preview generation.
 *
 *   node tools/release/acceptance.mjs --generation G [--json]      read it (exit 0 accepted, 3 none, 4 rejected)
 *   node tools/release/acceptance.mjs --generation G --how --pr N  print the owner's one-line commands
 *   node tools/release/acceptance.mjs --generation G --record --pr N --i-am-the-owner [--note TEXT]
 *
 * HOW ACCEPTANCE IS RECORDED (by the owner, on GitHub, nowhere else)
 *   - a comment on the preview PR (or any gridatlas issue) whose FIRST line is
 *       ACCEPT <G>
 *     with anything the owner wants to add on later lines; or
 *   - the label  accepted:<G>  on the preview PR.
 *   `REJECT <G>` as a later comment, or removing the label, withdraws it.
 *
 * WHAT COUNTS (tools/release/flow-lib.mjs decideAcceptance)
 *   - the author is an owner login (GRIDATLAS_OWNER_LOGINS, default Ventusltd);
 *   - it was not posted through a GitHub App (Codex and other connectors post
 *     as the owner with an app marker) and carries no agent signature
 *     (Claude-Session:, "Generated with [Claude Code]", ...);
 *   - it was made after G was cut (the manifest's cut_at_utc);
 *   - the latest qualifying verdict wins.
 *
 * Agents work with the owner's token, so GitHub cannot tell an agent's comment
 * from the owner's by login alone. The rule is therefore procedural as well:
 * no agent and no script posts an ACCEPT line or the label. --record refuses
 * to run under Claude Code, Codex or CI, and needs --i-am-the-owner.
 */

import { parseArgs } from './lib.mjs';
import { GRIDATLAS, readAcceptance, acceptLabel, runningAsAgent, gh, cutAtUtc, OWNER_LOGINS } from './flow-lib.mjs';

const TOOL = 'acceptance';
const die = (m, code = 1) => { console.error(`${TOOL}: STOP: ${m}`); process.exit(code); };

let args;
try {
  args = parseArgs(process.argv.slice(2), {
    generation: {}, json: { bool: true }, how: { bool: true }, record: { bool: true }, pr: {},
    'i-am-the-owner': { bool: true }, note: {}, label: { bool: true }
  });
} catch (error) { die(error.message); }
const G = args.generation;
if (!G || !/^\d{12}$/.test(G)) die('--generation G (12 digits) is required');

const commentCmd = (pr) => `gh api -X POST repos/${GRIDATLAS}/issues/${pr}/comments -f body='ACCEPT ${G}'`;
const labelCmd = (pr) => `gh api -X POST repos/${GRIDATLAS}/issues/${pr}/labels -f 'labels[]=${acceptLabel(G)}'`;

if (args.how) {
  if (!args.pr) die('--how needs --pr N (the preview PR)');
  console.log(`Owner, to accept ${G} (either one; the first line of the comment must be exactly "ACCEPT ${G}"):\n` +
    `  on GitHub: comment "ACCEPT ${G}" on https://github.com/${GRIDATLAS}/pull/${args.pr}\n` +
    `  or:        ${commentCmd(args.pr)}\n  or:        ${labelCmd(args.pr)}\n` +
    `To withdraw: comment "REJECT ${G}" or remove the label.`);
  process.exit(0);
}

if (args.record) {
  if (runningAsAgent()) die('refused: an agent or CI is running this. Only the owner records acceptance; run with --how and pass the command to the owner.');
  if (!args['i-am-the-owner']) die('--record needs --i-am-the-owner');
  if (!args.pr) die('--record needs --pr N');
  if (args.label) {
    gh(`repos/${GRIDATLAS}/issues/${args.pr}/labels`, { method: 'POST', input: JSON.stringify({ labels: [acceptLabel(G)] }) });
    console.log(`label ${acceptLabel(G)} added to #${args.pr}`);
  } else {
    const c = gh(`repos/${GRIDATLAS}/issues/${args.pr}/comments`, { method: 'POST', input: JSON.stringify({ body: `ACCEPT ${G}${args.note ? `\n\n${args.note}` : ''}` }) });
    console.log(`acceptance recorded: ${c.html_url}`);
  }
  process.exit(0);
}

const since = cutAtUtc(G);
const a = readAcceptance(G, { since: since || undefined });
if (args.json) console.log(JSON.stringify({ generation: G, since, owner_logins: OWNER_LOGINS, ...a }, null, 1));
else {
  console.log(`${G}: ${a.state.toUpperCase()}${a.url ? `  ${a.via} by ${a.by} at ${a.at}  ${a.url}` : ''}`);
  for (const i of a.ignored) console.log(`  ignored: ${i.url}  ${i.why}`);
  if (a.state === 'none') console.log(`  (looked for "ACCEPT ${G}" comments and the ${acceptLabel(G)} label since ${since || 'the beginning'})`);
}
process.exit(a.state === 'accepted' ? 0 : a.state === 'rejected' ? 4 : 3);

Check Live

A JavaScript module in the tools folder of GridAtlas that works with live bytes job (`liveBytesJob`).

automationgridatlas / tools/release/check-live.mjs · lines 1–85 of 85 · Entry point

What it does
Defines die, sleep, liveBytesJob. Uses libraries node:child_process. Side effects: starts processes.
Why it exists in the grid workflow
Domain stage upstream_foresight (repository name word 'gridatlas'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight.
Inputs & outputs
In: JSON file current.json; command-line arguments.
Downstream impact
It is itself an entry point (JavaScript module); no other file was found loading it.
What it achieves
It is built from the die step (`die`), the sleep step (`sleep`) and the live bytes job helper (`liveBytesJob`). Step 5 of the delivery flow: prove the public Pages site serves the committed bytes after a release (or a rollback) reached main.
Why it matters
No other file in the estate was found to import it; it is an entry point.
Application
gridatlas · tools/release · JavaScript module
Uses
GridAtlas — Release (script call), Flow Lib (script call), Verify Live Bytes (script call), node:child_process
Used by
none found
Produces
die, sleep, liveBytesJob
Defines here
die, sleep, liveBytesJob
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 tools/release/check-live.mjs:1-85 · blob 6d6d6166bcf89a82768f0c9efe8e11ba98398bd4 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: unknown · effects: process · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
#!/usr/bin/env node
/**
 * Step 5 of the delivery flow: prove the public Pages site serves the
 * committed bytes after a release (or a rollback) reached main.
 *
 *   node tools/release/check-live.mjs [--generation G] [--sha SHA] [--wait] [--timeout-min 40]
 *   node tools/release/check-live.mjs --dispatch            re-run the live-bytes job on main now
 *   node tools/release/check-live.mjs --local               run the verifier from this machine instead
 *
 * PRE-CONDITIONS
 *   - with --generation: gridatlas main's atlas/current.json names G (the release PR is merged);
 *   - the default commit is main's head; --sha picks another commit on main.
 *
 * HOW
 *   The live-bytes job of .github/workflows/202608301321-verify-live.yml runs
 *   on every push to main: it waits for Pages and compares every file
 *   atlas/current.json references, the loader and every atlas/v/<gen>/ file
 *   byte for byte (tools/scope/verify-live-bytes.mjs). This script finds that
 *   run for the commit and reports its live-bytes job; --wait polls until it
 *   finishes. A run superseded by a later push to main passes with a warning,
 *   and the later run is authoritative, so --wait follows main's head.
 *   --local runs the same verifier here (needs network access to
 *   ventusltd.github.io; some sandboxes block it).
 *
 * Exit 0 when live-bytes passed, 1 when it failed, 3 when it has not finished
 * (without --wait), 2 when it cannot be checked.
 */

import { spawnSync } from 'node:child_process';
import { ROOT, parseArgs } from './lib.mjs';
import { GRIDATLAS, LIVE_BYTES_WORKFLOW, gh, ghFile, ghHeadSha, workflowRuns, dispatchWorkflow } from './flow-lib.mjs';

const TOOL = 'check-live';
const die = (m, code = 2) => { console.error(`${TOOL}: STOP: ${m}`); process.exit(code); };

let args;
try {
  args = parseArgs(process.argv.slice(2), {
    generation: {}, sha: {}, wait: { bool: true }, 'timeout-min': { default: '40' }, dispatch: { bool: true }, local: { bool: true }
  });
} catch (error) { die(error.message); }

const sleep = (s) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, s * 1000);

if (args.local) {
  const r = spawnSync('node', ['tools/scope/verify-live-bytes.mjs', '--root', ROOT, '--timeout-s', String(Number(args['timeout-min']) * 60)], { cwd: ROOT, stdio: 'inherit' });
  process.exit(r.status ?? 2);
}

const main = JSON.parse(ghFile(GRIDATLAS, 'main', 'atlas/current.json'));
if (args.generation && String(main.generation) !== args.generation)
  die(`gridatlas main serves ${main.generation}, not ${args.generation}: the release PR is not merged`, 1);
console.log(`gridatlas main: generation ${main.generation} (${main.composition_id})`);

if (args.dispatch) {
  dispatchWorkflow(GRIDATLAS, LIVE_BYTES_WORKFLOW, 'main', { mode: 'live-bytes', compare_ref: 'main' });
  console.log(`dispatched ${LIVE_BYTES_WORKFLOW} mode=live-bytes on main; run again with --wait to follow it`);
  process.exit(0);
}

function liveBytesJob(sha) {
  const runs = workflowRuns(GRIDATLAS, LIVE_BYTES_WORKFLOW, { headSha: sha, perPage: 10 });
  for (const run of runs) {
    const jobs = gh(`repos/${GRIDATLAS}/actions/runs/${run.id}/jobs?per_page=50`).jobs || [];
    const job = jobs.find(j => j.name === 'live-bytes');
    if (job) return { run, job };
  }
  return { run: runs[0] || null, job: null };
}

const deadline = Date.now() + Number(args['timeout-min']) * 60_000;
for (;;) {
  const sha = args.sha || ghHeadSha(GRIDATLAS, 'main');
  const { run, job } = liveBytesJob(sha);
  const where = run ? `${run.html_url}` : 'no run yet';
  if (job && job.status === 'completed') {
    const pass = job.conclusion === 'success';
    console.log(`live-bytes ${pass ? 'PASS' : `FAIL (${job.conclusion})`} for ${sha.slice(0, 12)}  ${job.html_url || where}`);
    process.exit(pass ? 0 : 1);
  }
  console.log(`live-bytes for ${sha.slice(0, 12)}: ${job ? job.status : run ? `run ${run.status}, job not started` : 'no run yet'}  ${where}`);
  if (!args.wait) process.exit(3);
  if (Date.now() > deadline) die(`timed out after ${args['timeout-min']} min`, 3);
  sleep(30);
}