16 lines
800 B
TypeScript
16 lines
800 B
TypeScript
/** Startup variables required by native executables before model evaluation. */
|
|
|
|
/** Native executable search, Windows system paths, and sandbox temporary paths retained in the OS environment. */
|
|
export const STARTUP_ENVIRONMENT_NAMES: ReadonlySet<string> = new Set(['PATH', 'PATHEXT', 'SYSTEMROOT', 'WINDIR', 'TEMP', 'TMP'])
|
|
|
|
/**
|
|
* Clear inherited credentials while preserving native child-process startup paths.
|
|
* @param state - Child process environment, replaced with an empty program-visible object.
|
|
*/
|
|
export function clearProgramEnvironment(state: { env: NodeJS.ProcessEnv }): void {
|
|
for (const key of Object.keys(state.env)) {
|
|
if (!STARTUP_ENVIRONMENT_NAMES.has(key.toUpperCase())) Reflect.deleteProperty(state.env, key)
|
|
}
|
|
state.env = Object.create(null) as NodeJS.ProcessEnv
|
|
}
|