import { execFile, spawn } from "node:child_process";
//#region src/infra/exec.ts
function execFileAsync(file, args, opts) {
	return new Promise((resolve, reject) => {
		execFile(file, args, {
			encoding: "utf8",
			maxBuffer: opts.maxBuffer ?? 1024 * 1024,
			cwd: opts.cwd,
			env: opts.env,
			timeout: opts.timeoutMs
		}, (err, stdout, stderr) => {
			if (err) {
				const enriched = err;
				enriched.stdout = typeof stdout === "string" ? stdout : String(stdout ?? "");
				enriched.stderr = typeof stderr === "string" ? stderr : String(stderr ?? "");
				reject(enriched);
				return;
			}
			resolve({
				stdout: typeof stdout === "string" ? stdout : String(stdout ?? ""),
				stderr: typeof stderr === "string" ? stderr : String(stderr ?? "")
			});
		});
	});
}
/** Run a subprocess and capture stdout/stderr (OpenClaw-aligned). */
async function runExec(file, args, opts = {}) {
	return execFileAsync(file, args, opts);
}
function spawnDetached(file, args, opts) {
	return spawn(file, args, {
		stdio: opts.stdio ?? "ignore",
		detached: false
	});
}
//#endregion
export { runExec, spawnDetached };

//# sourceMappingURL=exec.js.map