dox-populi payload

The JavaScript modules nix run .#deploy-local posts to the server: esbuild’s bundles of the harness with the code Paradox generated from the spec.

main.js

"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// harness/main.ts
var main_exports = {};
__export(main_exports, {
  loop: () => loop
});
module.exports = __toCommonJS(main_exports);

// generated/index.ts
var validCreepRole = (x) => {
  const v = x;
  if (v != "harvester") throw new Error("Invalid CreepRole `" + JSON.stringify(x) + "`");
  return x;
};
var harvesterBody = ["work", "carry", "move"];

// harness/main.ts
var roleHarvester = __toESM(require("role.harvester"));
var TRACE_DEAD_LIMIT = 10;
function pruneDeadTraces() {
  if (!Memory.trace) return;
  const traces = Memory.trace;
  const lastTick = (n) => {
    const log = traces[n];
    return log.length > 0 ? log[log.length - 1].t : 0;
  };
  const dead = Object.keys(traces).filter((n) => !(n in Game.creeps)).sort((a, b) => lastTick(a) - lastTick(b));
  while (dead.length > TRACE_DEAD_LIMIT) delete traces[dead.shift()];
}
var loop = () => {
  for (const name in Memory.creeps) {
    if (!(name in Game.creeps)) {
      delete Memory.creeps[name];
    }
  }
  pruneDeadTraces();
  const spawn = Game.spawns["Spawn1"];
  if (spawn && !spawn.spawning && Object.keys(Game.creeps).length < 1) {
    spawn.spawnCreep(harvesterBody, `harvester-${Game.time}`, {
      memory: { role: "harvester" }
    });
  }
  for (const name in Game.creeps) {
    const creep = Game.creeps[name];
    const role = validCreepRole(creep.memory.role);
    if (role === "harvester") {
      roleHarvester.run(creep);
    }
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  loop
});

harvester.js

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// harness/role.harvester.ts
var role_harvester_exports = {};
__export(role_harvester_exports, {
  run: () => run
});
module.exports = __toCommonJS(role_harvester_exports);
var TRACE_LIMIT = 50;
function recordTrace(name, action, rc) {
  const traces = Memory.trace ??= {};
  const log = traces[name] ??= [];
  const last = log[log.length - 1];
  if (last && last.action === action && last.rc === rc) return;
  log.push({ t: Game.time, action, rc });
  if (log.length > TRACE_LIMIT) log.shift();
}
function run(creep) {
  if (creep.store.getFreeCapacity() > 0) {
    const source = creep.pos.findClosestByPath(FIND_SOURCES);
    if (source) {
      const rc = creep.harvest(source);
      if (rc === ERR_NOT_IN_RANGE) {
        recordTrace(creep.name, "moveTo", creep.moveTo(source));
      } else {
        recordTrace(creep.name, "harvest", rc);
      }
    }
  } else {
    const spawn = Game.spawns["Spawn1"];
    if (spawn) {
      const rc = creep.transfer(spawn, RESOURCE_ENERGY);
      if (rc === ERR_NOT_IN_RANGE) {
        recordTrace(creep.name, "moveTo", creep.moveTo(spawn));
      } else {
        recordTrace(creep.name, "transfer", rc);
      }
    }
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  run
});