// @generated by scripts/build-runtime.mjs; do not edit. // @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader. import { PRIVATE_STYLE_SELECTOR } from "./chunk-2BNGNI6Y.js"; import { exactAlias, optionBoolean, optionMap, optionString, optionStrings, safeMetadata } from "./chunk-PV5KIAAP.js"; // src/runtime/execution.ts async function collectExecution(context) { if (context.input.reason === "periodic" && context.input.previous) { const retained = {}; for (const name of ["os", "container", "hostname", "username"]) { const values = context.input.previous.modules[name]; if (!context.needs(name) || !values) continue; const selector = context.input.previous.styleSelectors?.[name]; retained[name] = { ...values, ...selector === void 0 ? {} : { [PRIVATE_STYLE_SELECTOR]: selector } }; } return retained; } const result = {}; if (context.needs("os")) result.os = await osValues(context); const container = context.needs("container") ? await containerValues(context) : void 0; if (container) result.container = container; const hostname = context.needs("hostname") ? hostnameValues(context) : void 0; if (hostname) result.hostname = hostname; const username = context.needs("username") ? usernameValues(context) : void 0; if (username) result.username = username; return result; } async function osValues(context) { const wsl = Boolean(safeMetadata(context.input.environment.WSL_DISTRO_NAME)); const type = wsl ? "wsl" : platformType(context.input.platform); const details = context.input.platform === "linux" ? await linuxRelease(context) : {}; const symbols = optionMap(context, "os", "symbols"); return { type, name: details.name ?? platformName(context.input.platform, wsl), ...details.version ? { version: details.version } : {}, ...details.edition ? { edition: details.edition } : {}, ...details.codename ? { codename: details.codename } : {}, ...Object.hasOwn(symbols, type) && safeMetadata(symbols[type]) ? { symbol: safeMetadata(symbols[type]) } : {} }; } async function linuxRelease(context) { const source = await context.fs.readFile("/etc/os-release", 16 * 1024); if (!source) return {}; const values = {}; for (const line of source.split(/\r?\n/u)) { const match = /^([A-Z_]+)=(.*)$/u.exec(line); if (!match?.[1] || match[2] === void 0) continue; const value = safeMetadata(match[2].replace(/^['"]|['"]$/gu, "")); if (value) values[match[1]] = value; } return { name: values.NAME, version: values.VERSION_ID, edition: values.ID, codename: values.VERSION_CODENAME }; } async function containerValues(context) { const env = context.input.environment; if (safeMetadata(env.REMOTE_CONTAINERS) || safeMetadata(env.CODESPACES)) { return { name: "Dev Container", type: "devcontainer" }; } const wsl = safeMetadata(env.WSL_DISTRO_NAME); if (wsl) return { name: `WSL ${wsl}`, type: "wsl" }; if (await context.fs.fileExists("/.dockerenv")) return { name: "Docker", type: "docker" }; if (await context.fs.fileExists("/run/.containerenv")) return { name: "Podman", type: "podman" }; const systemd = safeMetadata(await context.fs.readFile("/run/systemd/container", 256)); return systemd ? { name: systemd, type: "container" } : void 0; } function hostnameValues(context) { const ssh = isSsh(context); if (optionBoolean(context, "hostname", "ssh_only") && !ssh) return void 0; const raw = safeMetadata(context.input.hostname); if (!raw) return void 0; const aliases = optionMap(context, "hostname", "aliases"); const trimAt = optionString(context, "hostname", "trim_at"); const index = trimAt ? raw.indexOf(trimAt) : -1; const trimmed = index >= 0 ? raw.slice(0, index) : raw; const hostname = exactAlias(trimmed, aliases) ?? trimmed; return { hostname, ssh_symbol: ssh ? "\u{1F310} " : "" }; } function usernameValues(context) { const user = safeMetadata(context.input.username); if (!user) return void 0; const env = context.input.environment; const login = safeMetadata(env.LOGNAME ?? env.USER ?? env.USERNAME); const privileged = /^(?:root|administrator)$/iu.test(user); const detected = optionStrings(context, "username", "detect_env_vars").some( (name) => safeMetadata(env[name]) !== void 0 ); if (!optionBoolean(context, "username", "show_always") && !isSsh(context) && !privileged && !(login && login !== user) && !detected) { return void 0; } return { user: exactAlias(user, optionMap(context, "username", "aliases")) ?? user, [PRIVATE_STYLE_SELECTOR]: privileged ? "root" : "user" }; } function isSsh(context) { return Boolean( safeMetadata(context.input.environment.SSH_CONNECTION) || safeMetadata(context.input.environment.SSH_TTY) ); } function platformType(platform) { if (platform === "darwin") return "macos"; if (platform === "win32") return "windows"; return platform; } function platformName(platform, wsl) { if (wsl) return "WSL"; if (platform === "darwin") return "macOS"; if (platform === "win32") return "Windows"; if (platform === "linux") return "Linux"; return platform; } export { collectExecution }; //# sourceMappingURL=execution-YGXH4DK6.ts.map