← Files Flows by plugin.spaceARCHIVED FILE
lib/codex-handoff.mjs
1.33 KB · Nov 30, 2026 · 00:17 UTC
import { readFile } from 'node:fs/promises';
import { basename, dirname, resolve } from 'node:path';
export async function codexPluginId(pluginRoot) {
let name = 'flows';
try {
const manifest = JSON.parse(await readFile(resolve(pluginRoot, 'plugin.json'), 'utf8'));
if (typeof manifest.name === 'string' && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(manifest.name)) name = manifest.name;
} catch { /* Legacy/development layouts without a portable manifest use flows. */ }
// Installed Codex plugins live at cache/<marketplace>/<plugin>/<version>.
const pluginFolder = dirname(pluginRoot);
const marketplaceFolder = dirname(pluginFolder);
if (basename(pluginFolder) === name && basename(dirname(marketplaceFolder)) === 'cache') {
return `${name}@${basename(marketplaceFolder)}`;
}
// Development checkouts and extracted marketplace packages have a catalog.
const root = resolve(pluginRoot, '../..');
try {
const catalog = JSON.parse(await readFile(resolve(root, '.agents/plugins/marketplace.json'), 'utf8'));
if (typeof catalog.name === 'string' && catalog.plugins?.some(plugin => plugin.name === name && plugin.source?.source === 'local' && resolve(root, plugin.source.path) === pluginRoot)) return `${name}@${catalog.name}`;
} catch { /* Standalone packages use the release marketplace. */ }
return `${name}@plugin-space`;
}
SHA-256: f20ce3e924dce563a9821442a89d8be4752e7c895fa77c4bf40a662b5087ba0d