fix(codex): install lsp from local cache
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { homedir } from "node:os";
|
||||
import { join, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
@@ -99,10 +100,17 @@ export async function installMarketplaceLocally(options = {}) {
|
||||
for (const legacyMarketplaceName of legacyCacheMarketplaces(marketplace.name)) {
|
||||
await pruneMarketplacePluginCaches({ codexHome, marketplaceName: legacyMarketplaceName, pluginNames });
|
||||
}
|
||||
const marketplaceRoot = join(codexHome, "plugins", "cache", marketplace.name);
|
||||
await writeCachedMarketplaceManifest({
|
||||
marketplaceName: marketplace.name,
|
||||
marketplaceRoot,
|
||||
plugins: installed,
|
||||
});
|
||||
await updateCodexConfig({
|
||||
configPath: join(codexHome, "config.toml"),
|
||||
repoRoot: codexPackageRoot,
|
||||
marketplaceName: marketplace.name,
|
||||
marketplaceSource: { sourceType: "local", source: marketplaceRoot },
|
||||
pluginNames,
|
||||
trustedHookStates,
|
||||
agentConfigs: [...agentConfigs.values()].sort((left, right) => left.name.localeCompare(right.name)),
|
||||
@@ -119,6 +127,25 @@ function agentNameFromToml(fileName) {
|
||||
return fileName.endsWith(".toml") ? fileName.slice(0, -".toml".length) : fileName;
|
||||
}
|
||||
|
||||
async function writeCachedMarketplaceManifest({ marketplaceName, marketplaceRoot, plugins }) {
|
||||
const marketplaceDir = join(marketplaceRoot, ".agents", "plugins");
|
||||
await mkdir(marketplaceDir, { recursive: true });
|
||||
await writeFile(
|
||||
join(marketplaceDir, "marketplace.json"),
|
||||
`${JSON.stringify(
|
||||
{
|
||||
name: marketplaceName,
|
||||
plugins: plugins.map((plugin) => ({
|
||||
name: plugin.name,
|
||||
source: { source: "local", path: `./${plugin.name}/${plugin.version}` },
|
||||
})),
|
||||
},
|
||||
null,
|
||||
"\t",
|
||||
)}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
function nonEmptyEnvValue(env, key) {
|
||||
const value = env[key];
|
||||
if (typeof value !== "string") return undefined;
|
||||
|
||||
@@ -206,7 +206,7 @@ test("#given local marketplace #when installing #then copies versioned plugins a
|
||||
assert.doesNotMatch(config, /stale@debug-marketplace/);
|
||||
});
|
||||
|
||||
test("#given sisyphuslabs marketplace #when installing #then registers sisyphuslabs omo git source", async () => {
|
||||
test("#given sisyphuslabs marketplace #when installing #then registers the local built marketplace cache", async () => {
|
||||
const repoRoot = await makeTempDir();
|
||||
const codexHome = await makeTempDir();
|
||||
const codexPackageRoot = join(repoRoot, "packages", "omo-codex");
|
||||
@@ -216,6 +216,17 @@ test("#given sisyphuslabs marketplace #when installing #then registers sisyphusl
|
||||
plugins: [{ name: "omo", source: "./plugins/omo" }],
|
||||
});
|
||||
await writePluginAt(join(codexPackageRoot, "plugin"), "omo", "0.1.0");
|
||||
await mkdir(join(codexPackageRoot, "plugin", "components", "lsp", "dist"), { recursive: true });
|
||||
await writeFile(join(codexPackageRoot, "plugin", "components", "lsp", "dist", "cli.js"), "#!/usr/bin/env node\n");
|
||||
await writeJson(join(codexPackageRoot, "plugin", ".mcp.json"), {
|
||||
mcpServers: {
|
||||
lsp: {
|
||||
command: "node",
|
||||
args: ["./components/lsp/dist/cli.js", "mcp"],
|
||||
cwd: ".",
|
||||
},
|
||||
},
|
||||
});
|
||||
await mkdir(join(codexHome, "plugins", "cache", legacyCodexPluginMarketplace, "omo", "0.1.0"), {
|
||||
recursive: true,
|
||||
});
|
||||
@@ -257,14 +268,25 @@ test("#given sisyphuslabs marketplace #when installing #then registers sisyphusl
|
||||
|
||||
const config = await readFile(join(codexHome, "config.toml"), "utf8");
|
||||
assert.match(config, /\[marketplaces\.sisyphuslabs\]/);
|
||||
assert.match(config, /source_type = "git"/);
|
||||
assert.match(config, /source = "https:\/\/github\.com\/sisyphuslabs\/omo\.git"/);
|
||||
assert.match(config, /ref = "main"/);
|
||||
assert.match(config, /source_type = "local"/);
|
||||
assert.match(config, new RegExp(`source = ${JSON.stringify(join(codexHome, "plugins", "cache", "sisyphuslabs")).replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
|
||||
assert.doesNotMatch(config, /ref = "main"/);
|
||||
assert.match(config, /\[plugins\."omo@sisyphuslabs"\]\nenabled = true/);
|
||||
assert.doesNotMatch(config, /\[marketplaces\.lazycodex\]/);
|
||||
assert.doesNotMatch(config, new RegExp(legacyCodexPluginMarketplace));
|
||||
assert.doesNotMatch(config, /lazycodex\.git/);
|
||||
assert.doesNotMatch(config, /source_type = "local"/);
|
||||
const marketplace = JSON.parse(
|
||||
await readFile(join(codexHome, "plugins", "cache", "sisyphuslabs", ".agents", "plugins", "marketplace.json"), "utf8"),
|
||||
);
|
||||
assert.deepEqual(marketplace.plugins, [{ name: "omo", source: { source: "local", path: "./omo/0.1.0" } }]);
|
||||
const cachedMcp = JSON.parse(
|
||||
await readFile(join(codexHome, "plugins", "cache", "sisyphuslabs", "omo", "0.1.0", ".mcp.json"), "utf8"),
|
||||
);
|
||||
assert.equal(
|
||||
cachedMcp.mcpServers.lsp.args[0],
|
||||
join(codexHome, "plugins", "cache", "sisyphuslabs", "omo", "0.1.0", "components", "lsp", "dist", "cli.js"),
|
||||
);
|
||||
assert.equal((await stat(cachedMcp.mcpServers.lsp.args[0])).isFile(), true);
|
||||
await assert.rejects(
|
||||
stat(join(codexHome, "plugins", "cache", legacyCodexPluginMarketplace, "omo")),
|
||||
/code: 'ENOENT'|ENOENT/,
|
||||
|
||||
Reference in New Issue
Block a user