Files
hermes-agent/apps/desktop/scripts/bundle-env.mjs
ethernet 86efc1f945 fix(release): allow explicit environment clears in commit bundles
An inherited HERMES_HOME can defeat a test bundle's data-directory suffix.
Older Windows installers also persisted that variable in the user registry.
This gives the app fresh UI state while its backend reads existing sessions.

Add --bundle-unset NAME, encoded as null in the existing bundle environment
object. Apply each clear as an explicit empty value before module startup.
Do not restore an explicitly empty HERMES_HOME from the Windows registry.
Ordinary defaults still preserve runtime overrides.

Verified the release parser, builder handoff, compiled startup ordering,
registry opt-out, and child environment with focused regression tests.
A native Windows probe passed with an inherited home. No MSIX was rebuilt.
2026-09-11 15:59:08 -04:00

17 lines
981 B
JavaScript

// Defaults must run before bundled modules resolve paths or onboarding flags.
// An esbuild define would replace reads, not populate the child process env.
/** @param {string} raw @returns {string} */
export function environmentDefaultsBanner(raw) {
const values = JSON.parse(raw)
if (!values || Array.isArray(values) || typeof values !== 'object') {
throw new Error('Bundle environment must be a JSON object')
}
for (const [key, value] of Object.entries(values)) {
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key) || (value !== null && (typeof value !== 'string' || value.includes('\0')))) {
throw new Error('Bundle environment requires valid names and string values without NUL, or null to clear')
}
}
// Keep clears present-but-empty so path resolution cannot restore registry defaults.
return `\nfor (const [key, value] of ${JSON.stringify(Object.entries(values))}) { if (value === null) process.env[key] = ''; else process.env[key] ??= value; }\n`
}