import { runShellStreaming, } from "../util/shell.js";
import { buildChildEnv } from "./child-env.js";
export async function runProcessSession(options) {
    const startedAt = Date.now();
    const signal = options.signal;
    const env = buildChildEnv({
        parentEnv: options.parentEnv,
        overrideEnv: options.env,
        inheritParentEnv: options.inheritParentEnv,
        allowedParentEnvNames: options.allowedParentEnvNames,
        allowedSecretEnvNames: options.allowedSecretEnvNames,
        allowSecretPassthrough: options.allowSecretPassthrough,
    });
    const result = await runShellStreaming(options.command, [...(options.args ?? [])], {
        cwd: options.cwd,
        env,
        timeout: options.timeoutMs,
        maxBuffer: options.maxBuffer,
        stdio: options.stdio,
        logPath: options.logPath,
        input: options.input,
        signal,
        inheritEnv: false,
        onStdout: options.onStdout,
        onStderr: options.onStderr,
    });
    const aborted = signal?.aborted === true;
    return {
        ...result,
        exitCode: aborted ? 130 : result.exitCode,
        failed: aborted ? true : result.failed,
        aborted,
        durationMs: Date.now() - startedAt,
    };
}
