fix(cli): protect existing Windows Codex shims

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-26 11:40:50 +09:00
parent b664b413d4
commit f87eceadae
5 changed files with 71 additions and 7 deletions
+7 -2
View File
@@ -3,6 +3,8 @@ import { cp, lstat, mkdir, readFile, readdir, readlink, rename, rm, symlink, wri
import { exists, isRecord } from "./utils.mjs";
const COMMAND_SHIM_MARKER = ":: generated by oh-my-openagent Codex installer";
export async function installCachedPlugin({ codexHome, marketplaceName, name, runCommand, sourcePath, version }) {
await maybeRunNpmInstall(sourcePath, runCommand);
await maybeRunNpmBuild(sourcePath, runCommand);
@@ -120,13 +122,16 @@ async function replaceCommandShim(linkPath, targetPath) {
if (await existingNonShim(linkPath)) {
throw new Error(`${linkPath} already exists and is not a command shim`);
}
await writeFile(linkPath, `@echo off\r\nnode "${targetPath}" %*\r\n`);
await writeFile(linkPath, `@echo off\r\n${COMMAND_SHIM_MARKER}\r\nnode "${targetPath}" %*\r\n`);
}
async function existingNonShim(path) {
try {
const stat = await lstat(path);
return !stat.isFile();
if (!stat.isFile()) return true;
const content = await readFile(path, "utf8");
if (content.includes(COMMAND_SHIM_MARKER)) return false;
throw new Error(`${path} already exists and is not a generated command shim`);
} catch (error) {
if (error instanceof Error && "code" in error && error.code === "ENOENT") return false;
throw error;