Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

fix(sdk): register local marketplaces in Codex homes containing a hash (#2547)

Michael D'Angeloe588bcd7fdc0
diff --git a/sdk/typescript/src/runtime.ts b/sdk/typescript/src/runtime.ts
index 301b5ebb1..5d0752907 100644
--- a/sdk/typescript/src/runtime.ts
+++ b/sdk/typescript/src/runtime.ts
@@ -2042,11 +2042,13 @@ export async function runWorkbench(
)
: input,
signal,
- registrationHandshake,
- // Frame Python arguments on stdin to preserve NUL and long diagnostics.
- native
- ? undefined
- : `${JSON.stringify(arguments_.map((argument) => argument.toWellFormed()))}\n`,
+ {
+ registrationHandshake,
+ // Frame Python arguments on stdin to preserve NUL and long diagnostics.
+ stdinPrefix: native
+ ? undefined
+ : `${JSON.stringify(arguments_.map((argument) => argument.toWellFormed()))}\n`,
+ },
);
if (!result.success) {
throw new Error(
@@ -3822,8 +3824,15 @@ export async function runCodexCommand(
environment: ProcessEnvironment,
input?: string | Uint8Array,
signal?: AbortSignal,
- registrationHandshake = false,
- stdinPrefix?: string,
+ {
+ registrationHandshake = false,
+ stdinPrefix,
+ cwd,
+ }: {
+ registrationHandshake?: boolean;
+ stdinPrefix?: string;
+ cwd?: string;
+ } = {},
): Promise<CodexCommandResult> {
const cancellation = registrationHandshake
? new AbortController()
@@ -3834,6 +3843,7 @@ export async function runCodexCommand(
executablePathForSpawn(command.command),
[...(command.args ?? []), ...args],
{
+ cwd,
env: environment,
stdio: registrationHandshake
? ["pipe", "pipe", "pipe", "pipe"]
@@ -3967,13 +3977,21 @@ async function runPluginCommand(
signal?: AbortSignal,
): Promise<string> {
try {
- const { success, exitCode, stdout, stderr } = await runCodexCommand(
- command,
- args,
- environment,
- undefined,
- signal,
- );
+ const run = (argv: readonly string[], cwd?: string) =>
+ runCodexCommand(command, argv, environment, undefined, signal, { cwd });
+ let result = await run(args);
+ const source = args[1] === "marketplace" ? args[3] : undefined;
+ if (
+ result.exitCode === 1 &&
+ source?.includes("#") &&
+ result.stderr
+ .split(/\r?\n/u)
+ .includes("Error: --ref is only supported for git marketplace sources")
+ ) {
+ // Native Codex parsed a literal hash in the local path as a Git ref.
+ result = await run(["plugin", "marketplace", "add", "."], source);
+ }
+ const { success, exitCode, stdout, stderr } = result;
if (!success) {
const detail =
stderr.trim() ||
diff --git a/sdk/typescript/tests-ts/codex-process-cancellation.test.ts b/sdk/typescript/tests-ts/codex-process-cancellation.test.ts
index 2702bff76..5bb4420f7 100644
--- a/sdk/typescript/tests-ts/codex-process-cancellation.test.ts
+++ b/sdk/typescript/tests-ts/codex-process-cancellation.test.ts
@@ -125,7 +125,7 @@ for (const mode of [
},
undefined,
controller.signal,
- mode.startsWith("archive-"),
+ { registrationHandshake: mode.startsWith("archive-") },
);
} finally {
observer.mockRestore();
diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.ts
index 1a2b66263..d69e6ad17 100644
--- a/sdk/typescript/tests-ts/runtime.test.ts
+++ b/sdk/typescript/tests-ts/runtime.test.ts
@@ -907,6 +907,25 @@ describe("plugin runtime preparation", () => {
).toBeDefined();
});
+ test("installs a local marketplace when the Codex home contains a literal hash", async () => {
+ const root = await temporaryDirectory();
+ const home = join(root, "codex #team");
+ const source = await bundledPluginRoot();
+ const installed = await bootstrapPlugin(home, source, {
+ environment: {
+ HOME: root,
+ USERPROFILE: root,
+ PATH: process.env["PATH"],
+ SystemRoot: process.env["SystemRoot"],
+ },
+ });
+
+ const manifest = join(".codex-plugin", "plugin.json");
+ expect(
+ await readFile(join(installed.installedRoot, manifest), "utf8"),
+ ).toBe(await readFile(join(source, manifest), "utf8"));
+ });
+
test("keeps local marketplace failures separate from installer failures", async () => {
const root = await temporaryDirectory();
const selected = await plugin(root);