feat(coding-agent): implement install method detection and update instructions

Added functionality to detect the installation method (bun-binary, npm, pnpm, yarn, bun, unknown) and provide corresponding update instructions for the package. This enhances user experience by guiding them on how to update the package based on their environment.
This commit is contained in:
Daniel Fu 2026-02-02 15:33:01 -05:00
parent 1fbafd6cc7
commit 0d828f925e
2 changed files with 61 additions and 5 deletions

View file

@ -20,6 +20,65 @@ export const isBunBinary =
/** Detect if Bun is the runtime (compiled binary or bun run) */
export const isBunRuntime = !!process.versions.bun;
// =============================================================================
// Install Method Detection
// =============================================================================
export type InstallMethod = "bun-binary" | "npm" | "pnpm" | "yarn" | "bun" | "unknown";
let _cachedInstallMethod: InstallMethod | undefined;
export function detectInstallMethod(): InstallMethod {
if (_cachedInstallMethod) return _cachedInstallMethod;
if (isBunBinary) {
_cachedInstallMethod = "bun-binary";
return _cachedInstallMethod;
}
const resolvedPath = `${__dirname}\0${process.execPath || ""}`.toLowerCase();
if (resolvedPath.includes("/pnpm/") || resolvedPath.includes("/.pnpm/") || resolvedPath.includes("\\pnpm\\")) {
_cachedInstallMethod = "pnpm";
} else if (
resolvedPath.includes("/yarn/") ||
resolvedPath.includes("/.yarn/") ||
resolvedPath.includes("\\yarn\\")
) {
_cachedInstallMethod = "yarn";
} else if (isBunRuntime) {
_cachedInstallMethod = "bun";
} else if (
resolvedPath.includes("/npm/") ||
resolvedPath.includes("/node_modules/") ||
resolvedPath.includes("\\npm\\")
) {
_cachedInstallMethod = "npm";
} else {
_cachedInstallMethod = "unknown";
}
return _cachedInstallMethod;
}
export function getUpdateInstruction(packageName: string): string {
const method = detectInstallMethod();
switch (method) {
case "bun-binary":
return `Download from: https://github.com/badlogic/pi-mono/releases/latest`;
case "pnpm":
return `Run: pnpm install -g ${packageName}`;
case "yarn":
return `Run: yarn global add ${packageName}`;
case "bun":
return `Run: bun install -g ${packageName}`;
case "npm":
return `Run: npm install -g ${packageName}`;
default:
return `Run: npm install -g ${packageName}`;
}
}
// =============================================================================
// Package Asset Paths (shipped with executable)
// =============================================================================