fix(plugins): validate Codex companion launch metadata
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
/** Exact host argv for a pinned registry package's MCP entry point. */
|
||||
export function packageRunnerCommand(
|
||||
runner: "npx" | "bunx",
|
||||
packageSpecifier: string,
|
||||
platform: NodeJS.Platform,
|
||||
): readonly string[];
|
||||
@@ -1,16 +0,0 @@
|
||||
/** Host argv shared by setup registrations and the source-only plugin launcher. */
|
||||
export const packageRunnerCommand = (runner, packageSpecifier, platform) => {
|
||||
if (runner !== "npx" && runner !== "bunx")
|
||||
throw new Error("Unsupported package runner");
|
||||
// Windows cmd.exe consumes these tokens itself. Package registrations use
|
||||
// exact registry references, never shell expressions or arbitrary operands.
|
||||
if (!/^[@A-Za-z0-9_./+-]+$/u.test(packageSpecifier))
|
||||
throw new Error("Package runner requires a shell-safe registry reference");
|
||||
const command =
|
||||
runner === "npx"
|
||||
? ["npx", "-y", packageSpecifier, "mcp"]
|
||||
: ["bunx", packageSpecifier, "mcp"];
|
||||
// npm's .cmd shim is not a native executable. Disable cmd AutoRun, matching
|
||||
// the setup registration policy, and keep all dynamic values out of syntax.
|
||||
return platform === "win32" ? ["cmd.exe", "/d", "/c", ...command] : command;
|
||||
};
|
||||
@@ -8,10 +8,31 @@ const PLUGIN_MANIFEST_PATHS = [
|
||||
".claude-plugin/plugin.json",
|
||||
".codex-plugin/plugin.json",
|
||||
];
|
||||
const PLUGIN_PACKAGE_NAME = "rea-agents";
|
||||
const pluginManifestSchema = versionSchema.extend({
|
||||
const inlinePluginManifestSchema = versionSchema.extend({
|
||||
mcpServers: z.object({
|
||||
rea: z.object({ args: z.array(z.string()) }),
|
||||
rea: z.object({
|
||||
command: z.literal("node"),
|
||||
args: z.tuple([
|
||||
z.literal("${CLAUDE_PLUGIN_ROOT}/scripts/plugin-mcp-launcher.mjs"),
|
||||
z.string(),
|
||||
]),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
const codexPluginManifestSchema = versionSchema.extend({
|
||||
mcpServers: z.literal("./.mcp.json"),
|
||||
});
|
||||
const codexServerConfigSchema = z.object({
|
||||
mcpServers: z.object({
|
||||
rea: z.object({
|
||||
command: z.literal("node"),
|
||||
args: z.tuple([
|
||||
z.literal("./scripts/plugin-mcp-launcher.mjs"),
|
||||
z.string(),
|
||||
]),
|
||||
cwd: z.literal("."),
|
||||
startup_timeout_sec: z.number().int().positive(),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
const sectionsSchema = z.object({
|
||||
@@ -203,9 +224,16 @@ async function validateCandidate(git, sha, version, commits) {
|
||||
// previous server, so both are version authority like server.json.
|
||||
const launches = [];
|
||||
for (const path of PLUGIN_MANIFEST_PATHS) {
|
||||
const manifest = await readJson(git, sha, path, pluginManifestSchema);
|
||||
const manifest =
|
||||
path === ".codex-plugin/plugin.json"
|
||||
? await readJson(git, sha, path, codexPluginManifestSchema)
|
||||
: await readJson(git, sha, path, inlinePluginManifestSchema);
|
||||
versions.push([path, manifest.version]);
|
||||
launches.push([path, manifest.mcpServers.rea.args[1]]);
|
||||
const server =
|
||||
path === ".codex-plugin/plugin.json"
|
||||
? await readJson(git, sha, ".mcp.json", codexServerConfigSchema)
|
||||
: manifest;
|
||||
launches.push([path, server.mcpServers.rea.args[1]]);
|
||||
}
|
||||
// Catalogs are generated and checked from this candidate by the release job;
|
||||
// they are not version authority stored in the immutable source tree.
|
||||
@@ -228,13 +256,13 @@ async function validateCandidate(git, sha, version, commits) {
|
||||
);
|
||||
}
|
||||
}
|
||||
// Compare the whole specifier: a bare version would make npx fetch a
|
||||
// package named after the release number.
|
||||
const requiredLaunch = `${PLUGIN_PACKAGE_NAME}@${version}`;
|
||||
// Plugin JSON stores only a scalar version. The launcher owns the fixed
|
||||
// package name and constructs the complete registry specifier at runtime.
|
||||
const requiredLaunch = version;
|
||||
for (const [location, launched] of launches) {
|
||||
if (launched !== requiredLaunch) {
|
||||
throw new Error(
|
||||
`${location}@${sha} launches ${launched ?? "no package"}; release branch requires ${requiredLaunch}.`,
|
||||
`${location}@${sha} launches version ${launched ?? "no version"}; release branch requires ${requiredLaunch}.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,6 +368,7 @@ export function verifyReleaseNotes(raw, text, body) {
|
||||
const VERSION_ONLY_PLUGIN_METADATA = new Set([
|
||||
".claude-plugin/plugin.json",
|
||||
".codex-plugin/plugin.json",
|
||||
".mcp.json",
|
||||
".claude-plugin/marketplace.json",
|
||||
".agents/plugins/marketplace.json",
|
||||
]);
|
||||
@@ -390,10 +391,9 @@ function pluginMetadataWithoutVersions(path, text) {
|
||||
}
|
||||
if ("version" in manifest) manifest.version = "";
|
||||
const launch = manifest.mcpServers?.rea?.args;
|
||||
// Only the version after the last "@" is release-owned; a different package
|
||||
// name changes what the plugin runs.
|
||||
if (Array.isArray(launch) && typeof launch[1] === "string")
|
||||
launch[1] = launch[1].replace(/@[^@/]*$/u, "@");
|
||||
// Only the scalar pinned version is release-owned; the launcher owns the
|
||||
// fixed package name and the executable/path remain product behavior.
|
||||
if (Array.isArray(launch) && typeof launch[1] === "string") launch[1] = "";
|
||||
return JSON.stringify(manifest);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user