replace execSync cases with spawnSync, use correct package @openai/codex

This commit is contained in:
Shawn Morreau
2025-11-13 07:31:45 -05:00
parent 586477f456
commit 5f9a839ef0
5 changed files with 6008 additions and 6835 deletions
+5 -5
View File
@@ -8,9 +8,9 @@ export const codex = agent({
inputKey: "openai_api_key",
install: async () => {
return await installFromNpmTarball({
packageName: "codex",
packageName: "@openai/codex",
version: "latest",
executablePath: "bin/codex",
executablePath: "bin/codex.js",
installDependencies: true,
});
},
@@ -43,8 +43,8 @@ export const codex = agent({
}
log.info(`Adding MCP server '${serverName}'...`);
const addResult = spawnSync(cliPath, addArgs, {
stdio: "inherit",
const addResult = spawnSync("node", [cliPath, ...addArgs], {
stdio: "pipe",
encoding: "utf-8",
env: {
...process.env,
@@ -70,7 +70,7 @@ export const codex = agent({
log.info("Running Codex via CLI...");
try {
const result = spawnSync(cliPath, ["exec", addInstructions(prompt)], {
const result = spawnSync("node", [cliPath, "exec", addInstructions(prompt)], {
encoding: "utf-8",
env: {
...process.env,
+20 -3
View File
@@ -1,4 +1,4 @@
import { execSync } from "node:child_process";
import { spawnSync } from "node:child_process";
import { createWriteStream, existsSync } from "node:fs";
import { mkdtemp } from "node:fs/promises";
import { tmpdir } from "node:os";
@@ -105,7 +105,15 @@ export async function installFromNpmTarball({
// Extract tarball
log.info(`Extracting tarball...`);
execSync(`tar -xzf "${tarballPath}" -C "${tempDir}"`, { stdio: "pipe" });
const extractResult = spawnSync("tar", ["-xzf", tarballPath, "-C", tempDir], {
stdio: "pipe",
encoding: "utf-8",
});
if (extractResult.status !== 0) {
throw new Error(
`Failed to extract tarball: ${extractResult.stderr || extractResult.stdout || "Unknown error"}`
);
}
// Find executable in the extracted package
const extractedDir = join(tempDir, "package");
@@ -120,7 +128,16 @@ export async function installFromNpmTarball({
const packageJsonPath = join(extractedDir, "package.json");
if (existsSync(packageJsonPath)) {
log.info(`Installing dependencies for ${packageName}...`);
execSync(`npm install --production`, { cwd: extractedDir, stdio: "pipe" });
const installResult = spawnSync("npm", ["install", "--production"], {
cwd: extractedDir,
stdio: "pipe",
encoding: "utf-8",
});
if (installResult.status !== 0) {
throw new Error(
`Failed to install dependencies: ${installResult.stderr || installResult.stdout || "Unknown error"}`
);
}
}
}