Skip to content

Commit d0d1735

Browse files
committed
fix(codex): support packaged lazycodex installs
1 parent 247bba3 commit d0d1735

15 files changed

Lines changed: 335 additions & 19 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"typecheck:packages": "tsgo --noEmit -p packages/rules-engine/tsconfig.json && tsgo --noEmit -p packages/ast-grep-core/tsconfig.json && tsgo --noEmit -p packages/ast-grep-mcp/tsconfig.json && tsgo --noEmit -p packages/git-bash-mcp/tsconfig.json && tsgo --noEmit -p packages/utils/tsconfig.json && tsgo --noEmit -p packages/model-core/tsconfig.json && tsgo --noEmit -p packages/prompts-core/tsconfig.json && tsgo --noEmit -p packages/comment-checker-core/tsconfig.json && tsgo --noEmit -p packages/hashline-core/tsconfig.json && tsgo --noEmit -p packages/boulder-state/tsconfig.json && tsgo --noEmit -p packages/agents-md-core/tsconfig.json && tsgo --noEmit -p packages/omo-codex/tsconfig.json",
7171
"typecheck:script": "tsgo --noEmit -p script/tsconfig.json",
7272
"test": "bun test",
73-
"test:codex": "bun run build:ast-grep-mcp && bun run build:lsp-tools-mcp && npm --prefix packages/omo-codex/plugin ci && bun run --cwd packages/omo-codex/plugin build && bun test src/cli/cli-installer.platform.test.ts src/cli/install-codex/codex-cache.test.ts src/cli/install-codex/codex-config-agent-cleanup.test.ts src/cli/install-codex/codex-config-toml.test.ts src/cli/install-codex/install-codex.test.ts src/cli/install-codex/link-cached-plugin-agents.test.ts packages/omo-codex/src/**/*.test.ts packages/utils/src/jsonc-parser.test.ts packages/utils/src/frontmatter.test.ts packages/hashline-core/src/hash-computation.test.ts packages/hashline-core/src/smoke-untested-modules.test.ts packages/rules-engine/src/index.test.ts packages/rules-engine/src/security-boundary.test.ts packages/agents-md-core/src/injector.test.ts packages/omo-codex/plugin/components/lsp/test/package-smoke.test.ts && node --test packages/omo-codex/plugin/test/*.test.mjs packages/omo-codex/scripts/install-cache-copy.test.mjs packages/omo-codex/scripts/install-config.test.mjs packages/omo-codex/scripts/install-local.test.mjs packages/omo-codex/scripts/install-mcp-runtime.test.mjs packages/omo-codex/scripts/install-agent-links.test.mjs packages/omo-codex/scripts/install-bin-links.test.mjs packages/omo-codex/scripts/sync-telemetry-component.test.mjs",
73+
"test:codex": "bun run build:ast-grep-mcp && bun run build:lsp-tools-mcp && npm --prefix packages/omo-codex/plugin ci && bun run --cwd packages/omo-codex/plugin build && bun test src/cli/cli-installer.platform.test.ts src/cli/install-codex/codex-cache.test.ts src/cli/install-codex/codex-config-agent-cleanup.test.ts src/cli/install-codex/codex-config-toml.test.ts src/cli/install-codex/install-codex.test.ts src/cli/install-codex/install-codex-packaged.test.ts src/cli/install-codex/link-cached-plugin-agents.test.ts packages/omo-codex/src/**/*.test.ts packages/utils/src/jsonc-parser.test.ts packages/utils/src/frontmatter.test.ts packages/hashline-core/src/hash-computation.test.ts packages/hashline-core/src/smoke-untested-modules.test.ts packages/rules-engine/src/index.test.ts packages/rules-engine/src/security-boundary.test.ts packages/agents-md-core/src/injector.test.ts packages/omo-codex/plugin/components/lsp/test/package-smoke.test.ts && node --test packages/omo-codex/plugin/test/*.test.mjs packages/omo-codex/scripts/install-cache-copy.test.mjs packages/omo-codex/scripts/install-config.test.mjs packages/omo-codex/scripts/install-local.test.mjs packages/omo-codex/scripts/install-mcp-runtime.test.mjs packages/omo-codex/scripts/install-packaged-local.test.mjs packages/omo-codex/scripts/install-agent-links.test.mjs packages/omo-codex/scripts/install-bin-links.test.mjs packages/omo-codex/scripts/sync-telemetry-component.test.mjs",
7474
"test:windows-codex": "bun run test:codex",
7575
"build:ast-grep-mcp": "bun run --cwd packages/ast-grep-mcp build",
7676
"build:git-bash-mcp": "bun run --cwd packages/git-bash-mcp build"

packages/omo-codex/plugin/.mcp.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
"args": ["../../ast-grep-mcp/dist/cli.js", "mcp"],
66
"cwd": "."
77
},
8+
"grep_app": {
9+
"url": "https://mcp.grep.app"
10+
},
11+
"context7": {
12+
"url": "https://mcp.context7.com/mcp"
13+
},
814
"git_bash": {
915
"command": "node",
1016
"args": ["../../git-bash-mcp/dist/cli.js", "mcp"],

packages/omo-codex/plugin/components/ultrawork/agents/librarian.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ If the user names a version ("React 18", "Next.js 14", "v2.x"):
5555
5656
## Step 4 - targeted investigation
5757
- `webfetch(<specific-doc-page-from-sitemap>)`.
58-
- If a docs-indexer / library-index tool is available, query it for the specific topic. Otherwise rely on the sitemap-driven webfetch pages.
58+
- If `context7` is available, query it for the specific topic. Otherwise rely on the sitemap-driven webfetch pages.
5959
6060
## Skip Phase 0.5 when
6161
- TYPE B (implementation) - you're cloning the repo anyway.
@@ -70,7 +70,7 @@ If the user names a version ("React 18", "Next.js 14", "v2.x"):
7070
Run Phase 0.5 first, then in parallel:
7171
- `web_search` for current-year usage examples + best practices.
7272
- `webfetch` for the targeted doc pages identified by the sitemap.
73-
- `gh search code "<usage pattern>" --language <lang>` for real-world code samples.
73+
- `grep_app` for broad GitHub code search; fall back to `gh search code "<usage pattern>" --language <lang>`.
7474
7575
## TYPE B - IMPLEMENTATION REFERENCE
7676
Execute in sequence:
@@ -81,9 +81,9 @@ Execute in sequence:
8181
8282
Parallel acceleration (4+ calls in one batch when independent):
8383
- Shallow clone.
84-
- `gh search code "<function-name>" --repo <owner>/<repo>`.
84+
- `grep_app` broad code search or `gh search code "<function-name>" --repo <owner>/<repo>`.
8585
- `gh api repos/<owner>/<repo>/commits/HEAD --jq '.sha'`.
86-
- Sitemap-targeted `webfetch` of the relevant docs page for the same API surface.
86+
- `context7` or sitemap-targeted `webfetch` of the relevant docs page for the same API surface.
8787
8888
## TYPE C - CONTEXT & HISTORY
8989
Execute in parallel (4+ calls):
@@ -100,7 +100,7 @@ For a specific issue / PR:
100100
## TYPE D - COMPREHENSIVE
101101
Run Phase 0.5 first, then execute 6+ parallel calls:
102102
- 2 docs calls: `webfetch` targeted doc pages + (if available) a docs-indexer query.
103-
- 2 code-search calls: `gh search code` with varied queries (different angles).
103+
- 2 code-search calls: `grep_app` or `gh search code` with varied queries (different angles).
104104
- 1 source clone for deep inspection.
105105
- 1 issues/PRs query for context.
106106
@@ -147,8 +147,9 @@ Never link to a branch name (`/blob/main/...`) - always pin to a SHA so the line
147147
- Sitemap -> `webfetch(<base>/sitemap.xml)` (fallbacks: `/sitemap-0.xml`, `/sitemap_index.xml`).
148148
- Read a specific page -> `webfetch(<page-url>)`.
149149
- Latest info -> `web_search("<query> <CURRENT_YEAR>")`.
150-
- Code search (fast, broad) -> `gh search code "<query>" --language <lang>` (org-wide or repo-scoped).
151-
- Code search (deep, repo-scoped) -> after cloning, `rg` / `ast_grep_search` over the clone.
150+
- Docs index -> `context7` when available; use sitemap-driven pages when it is not.
151+
- Code search (fast, broad) -> `grep_app` for web-scale GitHub search; `gh search code "<query>" --language <lang>` when you need GitHub CLI filters.
152+
- Code search (deep, repo-scoped) -> after cloning, `rg` / `ast_grep` over the clone.
152153
- Clone -> `gh repo clone <o>/<r> "${TMPDIR:-/tmp}/<name>" -- --depth 1`.
153154
- Issues / PRs -> `gh search issues|prs`, `gh issue|pr view <n> --comments`.
154155
- Release info -> `gh api repos/<o>/<r>/releases/latest`.

packages/omo-codex/plugin/components/ultrawork/test/package-smoke.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@ describe("codex ultrawork package metadata", () => {
3434
expect(hookCommands).toContain(`node "${pluginRoot}/dist/cli.js" hook user-prompt-submit`);
3535
expect(hookCommands).not.toContainEqual(expect.stringMatching(/\bpython3?\b|ultrawork-detector\.py/));
3636
});
37+
38+
it("#given explorer guidance #when inspected #then names the packaged code-search MCP surface", () => {
39+
// given
40+
const explorer = readFileSync("agents/explorer.toml", "utf8");
41+
42+
// when
43+
const guidance = explorer.toLowerCase();
44+
45+
// then
46+
expect(guidance).toContain("ast_grep");
47+
expect(guidance).toContain("structural");
48+
});
49+
50+
it("#given librarian guidance #when inspected #then names the packaged research MCP surfaces", () => {
51+
// given
52+
const librarian = readFileSync("agents/librarian.toml", "utf8");
53+
54+
// when
55+
const guidance = librarian.toLowerCase();
56+
57+
// then
58+
expect(guidance).toContain("grep_app");
59+
expect(guidance).toContain("context7");
60+
expect(guidance).toContain("ast_grep");
61+
});
3762
});
3863

3964
function readJson(path: string): unknown {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import assert from "node:assert/strict";
2+
import { readFile } from "node:fs/promises";
3+
import { dirname, join } from "node:path";
4+
import test from "node:test";
5+
import { fileURLToPath } from "node:url";
6+
7+
const root = dirname(dirname(fileURLToPath(import.meta.url)));
8+
9+
test("#given aggregate MCP config #when inspected #then registers research and structural-search MCPs", async () => {
10+
// given
11+
const mcp = JSON.parse(await readFile(join(root, ".mcp.json"), "utf8"));
12+
13+
// when
14+
const serverNames = Object.keys(mcp.mcpServers).sort();
15+
16+
// then
17+
assert.deepEqual(serverNames, ["ast_grep", "context7", "git_bash", "grep_app", "lsp"]);
18+
assert.equal(mcp.mcpServers.grep_app.url, "https://mcp.grep.app");
19+
assert.equal(mcp.mcpServers.context7.url, "https://mcp.context7.com/mcp");
20+
assert.deepEqual(mcp.mcpServers.ast_grep.args, ["../../ast-grep-mcp/dist/cli.js", "mcp"]);
21+
});

packages/omo-codex/scripts/install-local.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
2-
import { mkdir, writeFile } from "node:fs/promises";
2+
import { existsSync } from "node:fs";
3+
import { mkdir, readFile, writeFile } from "node:fs/promises";
34
import { homedir } from "node:os";
45
import { join, resolve } from "node:path";
56
import { fileURLToPath } from "node:url";
@@ -46,6 +47,7 @@ export async function installMarketplaceLocally(options = {}) {
4647
const platform = options.platform ?? process.platform;
4748
const runCommand = options.runCommand ?? defaultRunCommand;
4849
const log = options.log ?? console.log;
50+
const buildSource = await shouldBuildSourcePackages(repoRoot);
4951
const gitBashResolution = await prepareGitBashForInstall({
5052
platform,
5153
env,
@@ -79,6 +81,7 @@ export async function installMarketplaceLocally(options = {}) {
7981

8082
log(`Building ${entry.name}@${version}`);
8183
const plugin = await installCachedPlugin({
84+
buildSource,
8285
codexHome,
8386
marketplaceName: marketplace.name,
8487
name: entry.name,
@@ -191,6 +194,14 @@ function legacyCacheMarketplaces(marketplaceName) {
191194
return marketplaceName === "sisyphuslabs" ? SISYPHUS_LEGACY_CACHE_MARKETPLACES : [];
192195
}
193196

197+
async function shouldBuildSourcePackages(repoRoot) {
198+
if (existsSync(join(repoRoot, "src", "index.ts"))) return true;
199+
const packageJsonPath = join(repoRoot, "package.json");
200+
if (!existsSync(packageJsonPath)) return true;
201+
const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
202+
return !["@code-yeongyu/lazycodex", "lazycodex", "oh-my-opencode", "oh-my-openagent"].includes(packageJson?.name);
203+
}
204+
194205
async function main() {
195206
const repoRoot = process.argv[2] ? resolve(process.argv[2]) : process.cwd();
196207
const result = await installMarketplaceLocally({ repoRoot });

packages/omo-codex/scripts/install-mcp-runtime.test.mjs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,46 @@ test("#given structurally valid external MCP package without mcp suffix #when in
188188
assert.deepEqual(cachedMcp.mcpServers.language_tools.args, [copiedCli, "mcp", join(sourceRoot, "..", "local-config.json")]);
189189
assert.equal((await stat(copiedCli)).isFile(), true);
190190
});
191+
192+
test("#given packaged external MCP runtime has only dist files #when installing cached plugin #then runtime is copied into the plugin cache", async () => {
193+
// given
194+
const repoRoot = await makeTempDir();
195+
const codexHome = await makeTempDir();
196+
const sourceRoot = join(repoRoot, "packages", "omo-codex", "plugin");
197+
const lspPackageRoot = join(repoRoot, "packages", "lsp-tools-mcp");
198+
199+
await writeJson(join(sourceRoot, "package.json"), {
200+
name: "@example/omo",
201+
version: "0.1.0",
202+
});
203+
await writeJson(join(sourceRoot, ".mcp.json"), {
204+
mcpServers: {
205+
lsp: {
206+
command: "node",
207+
args: ["../../lsp-tools-mcp/dist/cli.js", "mcp"],
208+
cwd: ".",
209+
},
210+
},
211+
});
212+
await writeJson(join(lspPackageRoot, "dist", "cli.js"), { executable: true });
213+
await writeJson(join(lspPackageRoot, "dist", "lsp", "manager.js"), { copied: true });
214+
215+
// when
216+
const result = await installCachedPlugin({
217+
codexHome,
218+
marketplaceName: "sisyphuslabs",
219+
name: "omo",
220+
runCommand: async () => {},
221+
sourcePath: sourceRoot,
222+
version: "0.1.0",
223+
});
224+
225+
// then
226+
const cachedMcp = JSON.parse(await readFile(join(result.path, ".mcp.json"), "utf8"));
227+
const copiedCli = join(result.path, "mcp", "lsp", "dist", "cli.js");
228+
assert.deepEqual(cachedMcp.mcpServers.lsp.args, [copiedCli, "mcp"]);
229+
assert.equal(Object.hasOwn(cachedMcp.mcpServers.lsp, "cwd"), false);
230+
assert.equal((await stat(copiedCli)).isFile(), true);
231+
assert.equal((await stat(join(result.path, "mcp", "lsp", "dist", "lsp", "manager.js"))).isFile(), true);
232+
assert.notEqual(cachedMcp.mcpServers.lsp.args[0], join(lspPackageRoot, "dist", "cli.js"));
233+
});
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import assert from "node:assert/strict";
2+
import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
3+
import { join } from "node:path";
4+
import test from "node:test";
5+
6+
import { installMarketplaceLocally } from "./install-local.mjs";
7+
import { makeTempDir, writeJson, writePluginAt } from "./install-test-fixtures.mjs";
8+
9+
test("#given packaged lazycodex adapter #when installing locally #then uses bundled artifacts without source builds", async () => {
10+
// given
11+
const repoRoot = await makeTempDir();
12+
const codexHome = await makeTempDir();
13+
const binDir = await makeTempDir();
14+
const codexPackageRoot = join(repoRoot, "packages", "omo-codex");
15+
const pluginRoot = join(codexPackageRoot, "plugin");
16+
const lspRuntimeRoot = join(repoRoot, "packages", "lsp-tools-mcp");
17+
18+
await writeJson(join(repoRoot, "package.json"), {
19+
name: "@code-yeongyu/lazycodex",
20+
version: "0.1.2",
21+
});
22+
await writeJson(join(codexPackageRoot, "marketplace.json"), {
23+
name: "sisyphuslabs",
24+
plugins: [{ name: "omo", source: "./plugins/omo" }],
25+
});
26+
await writePluginAt(pluginRoot, "omo", "0.1.0");
27+
await writeJson(join(pluginRoot, ".mcp.json"), {
28+
mcpServers: {
29+
lsp: {
30+
command: "node",
31+
args: ["../../lsp-tools-mcp/dist/cli.js", "mcp"],
32+
cwd: ".",
33+
},
34+
},
35+
});
36+
await mkdir(join(pluginRoot, "dist"), { recursive: true });
37+
await writeFile(join(pluginRoot, "dist", "cli.js"), "#!/usr/bin/env node\nconsole.log('prebuilt')\n");
38+
await writeJson(join(lspRuntimeRoot, "dist", "cli.js"), { executable: true });
39+
40+
const commands = [];
41+
42+
// when
43+
const result = await installMarketplaceLocally({
44+
repoRoot,
45+
codexHome,
46+
binDir,
47+
platform: "linux",
48+
runCommand: async (command, args, options) => {
49+
commands.push([command, args.join(" "), options.cwd]);
50+
},
51+
log: () => {},
52+
});
53+
54+
// then
55+
const pluginCacheRoot = join(codexHome, "plugins", "cache", "sisyphuslabs", "omo", "0.1.0");
56+
const cachedMcp = JSON.parse(await readFile(join(pluginCacheRoot, ".mcp.json"), "utf8"));
57+
const cachedLspCli = join(pluginCacheRoot, "mcp", "lsp", "dist", "cli.js");
58+
59+
assert.deepEqual(result.installed.map((plugin) => `${plugin.name}@${plugin.version}`), ["omo@0.1.0"]);
60+
assert.deepEqual(
61+
commands.map(([command, args, cwd]) => [command, args, cwd]),
62+
[["npm", "install --omit=dev", pluginCacheRoot]],
63+
);
64+
assert.deepEqual(cachedMcp.mcpServers.lsp.args, [cachedLspCli, "mcp"]);
65+
assert.equal((await stat(cachedLspCli)).isFile(), true);
66+
assert.notEqual(cachedMcp.mcpServers.lsp.args[0], join(lspRuntimeRoot, "dist", "cli.js"));
67+
});

packages/omo-codex/scripts/install/cache.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import { exists, isRecord } from "./utils.mjs";
66
import { COMMAND_SHIM_MARKER } from "./command-shim.mjs";
77
import { removeLegacyCodexComponentBins } from "./legacy-bins.mjs";
88

9-
export async function installCachedPlugin({ codexHome, marketplaceName, name, runCommand, sourcePath, version }) {
10-
await maybeRunNpmInstall(sourcePath, runCommand);
11-
await maybeRunNpmBuild(sourcePath, runCommand);
9+
export async function installCachedPlugin({ buildSource = true, codexHome, marketplaceName, name, runCommand, sourcePath, version }) {
10+
if (buildSource) {
11+
await maybeRunNpmInstall(sourcePath, runCommand);
12+
await maybeRunNpmBuild(sourcePath, runCommand);
13+
}
1214

1315
const targetPath = join(codexHome, "plugins", "cache", marketplaceName, name, version);
1416
await replaceDirectory(sourcePath, targetPath, shouldCopyPluginPath);

packages/omo-codex/scripts/install/mcp-runtime-cache.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function resolveExternalMcpPackageRoot(runtimePath, sourceRoot) {
4040
if (!isPathInside(runtimePath, packagesRoot)) return undefined;
4141
let packageRoot = dirname(runtimePath);
4242
while (packageRoot !== packagesRoot) {
43-
if (existsSync(join(packageRoot, "package.json")) && isPathInside(runtimePath, join(packageRoot, "dist"))) {
43+
if (isPathInside(runtimePath, join(packageRoot, "dist")) && isRuntimePackageRoot(packageRoot)) {
4444
return packageRoot;
4545
}
4646
const parent = dirname(packageRoot);
@@ -50,6 +50,10 @@ function resolveExternalMcpPackageRoot(runtimePath, sourceRoot) {
5050
return undefined;
5151
}
5252

53+
function isRuntimePackageRoot(packageRoot) {
54+
return existsSync(join(packageRoot, "package.json")) || existsSync(join(packageRoot, "dist"));
55+
}
56+
5357
function findPackagesRoot(path) {
5458
let current = resolve(path);
5559
for (let index = 0; index < 8; index++) {

0 commit comments

Comments
 (0)