From 64db15a6ac7e2ca1248799ebf1e9f17f1d4d70cd Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sun, 31 May 2026 00:01:34 +0900 Subject: [PATCH] fix: locate codex plugin from platform binary --- src/cli/install-codex/install-codex.test.ts | 18 +++++++++++++++++- src/cli/install-codex/install-codex.ts | 8 ++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/cli/install-codex/install-codex.test.ts b/src/cli/install-codex/install-codex.test.ts index 4da7f3f78..4b4afb193 100644 --- a/src/cli/install-codex/install-codex.test.ts +++ b/src/cli/install-codex/install-codex.test.ts @@ -5,7 +5,7 @@ import { describe, expect, test } from "bun:test" import { mkdir, mkdtemp, readdir, readFile, readlink, rm, stat, writeFile } from "node:fs/promises" import { tmpdir } from "node:os" import { join } from "node:path" -import { resolveCodexInstallerBinDir, runCodexInstaller } from "./install-codex" +import { findRepoRootFromImporter, resolveCodexInstallerBinDir, runCodexInstaller } from "./install-codex" const EXPECTED_OMO_COMPONENT_BINS = [ { name: "omo", target: join("components", "ulw-loop", "dist", "cli.js") }, @@ -26,6 +26,22 @@ const STALE_CODEX_COMPONENT_BINS = [ ] as const describe("install-codex", () => { + test("#given npm platform binary package #when resolving vendored repo root #then finds sibling wrapper package", async () => { + // given + const nodeModules = await mkdtemp(join(tmpdir(), "omo-codex-node-modules-")) + const importerDir = join(nodeModules, "oh-my-openagent-darwin-arm64", "bin") + const wrapperRoot = join(nodeModules, "oh-my-openagent") + await mkdir(join(importerDir), { recursive: true }) + await mkdir(join(wrapperRoot, "packages", "omo-codex", "plugin", ".codex-plugin"), { recursive: true }) + await writeFile(join(wrapperRoot, "packages", "omo-codex", "plugin", ".codex-plugin", "plugin.json"), "{}") + + // when + const repoRoot = findRepoRootFromImporter(importerDir) + + // then + expect(repoRoot).toBe(wrapperRoot) + }) + test("#given default CODEX_HOME #when resolving installer bin dir without override #then preserves user local bin precedence", () => { // given const homeDir = join(tmpdir(), "omo-codex-home-default") diff --git a/src/cli/install-codex/install-codex.ts b/src/cli/install-codex/install-codex.ts index 715d3be1b..9833c1fae 100644 --- a/src/cli/install-codex/install-codex.ts +++ b/src/cli/install-codex/install-codex.ts @@ -196,15 +196,19 @@ function codexMarketplaceSource(marketplaceRoot: string): CodexMarketplaceSource return { sourceType: "local", source: marketplaceRoot } } -function findRepoRootFromImporter(importerDir: string): string { +export function findRepoRootFromImporter(importerDir: string): string { let current = importerDir for (let depth = 0; depth <= 5; depth += 1) { const pluginManifestPath = join(current, "packages", "omo-codex", "plugin", ".codex-plugin", "plugin.json") if (existsSyncLike(pluginManifestPath)) return current + for (const wrapperPackageRoot of [join(current, "node_modules", "oh-my-openagent"), join(current, "oh-my-openagent")]) { + const wrapperPluginManifestPath = join(wrapperPackageRoot, "packages", "omo-codex", "plugin", ".codex-plugin", "plugin.json") + if (existsSyncLike(wrapperPluginManifestPath)) return wrapperPackageRoot + } current = resolve(current, "..") } throw new Error( - "Unable to locate vendored Codex plugin: expected packages/omo-codex/plugin/.codex-plugin/plugin.json within 5 parent levels", + "Unable to locate vendored Codex plugin: expected packages/omo-codex/plugin/.codex-plugin/plugin.json in this package or sibling oh-my-openagent package within 5 parent levels", ) }