// src/runtime/env.ts
import os from "os";
var REMNIC_ENGRAM_PREFIX_PAIRS = [
  ["REMNIC_", "ENGRAM_"],
  ["ENGRAM_", "REMNIC_"]
];
function getEnvMap() {
  const runtimeProcess = globalThis.process;
  return runtimeProcess?.["env"];
}
function legacyEnvCandidates(name) {
  const candidates = [name];
  for (const [primary, legacy] of REMNIC_ENGRAM_PREFIX_PAIRS) {
    if (name.startsWith(primary)) {
      candidates.push(`${legacy}${name.slice(primary.length)}`);
    }
  }
  return candidates;
}
function readEnvVar(name) {
  const env = getEnvMap();
  for (const candidate of legacyEnvCandidates(name)) {
    const value = env?.[candidate];
    if (typeof value === "string") return value;
  }
  return void 0;
}
function resolveHomeDir() {
  return readEnvVar("HOME") || os.homedir();
}
function cloneEnv() {
  return { ...getEnvMap() ?? {} };
}
function mergeEnv(overrides) {
  const merged = cloneEnv();
  for (const [key, value] of Object.entries(overrides)) {
    if (typeof value === "string") merged[key] = value;
    else delete merged[key];
  }
  return merged;
}

export {
  readEnvVar,
  resolveHomeDir,
  mergeEnv
};
//# sourceMappingURL=chunk-MARWOCVP.js.map