fix(cli): handled standalone profile aliases

Detected Bun-compiled entry points before preserving source invocations. Added a regression for the virtual bunfs argv shape and documented the fix.

Fixes #8233
This commit is contained in:
roboomp
2026-08-11 09:14:26 +00:00
parent 45e12e5bb7
commit 133e42e34b
3 changed files with 41 additions and 6 deletions
+4
View File
@@ -2,6 +2,10 @@
## [Unreleased]
### Fixed
- Fixed profile aliases generated by standalone binaries invoking Bun's embedded virtual script instead of the installed `omp` command ([#8233](https://github.com/can1357/oh-my-pi/issues/8233)).
## [17.2.12] - 2026-08-08
### Fixed
+15 -4
View File
@@ -19,6 +19,13 @@ export interface ProfileAliasCommand {
powerShell: string;
}
/** Process inputs used to select the installed command or preserve a source invocation. */
export interface ProfileAliasProcessOptions {
argv?: readonly string[];
cwd?: string;
compiled?: boolean;
}
const DEFAULT_ALIAS_COMMAND: ProfileAliasCommand = {
display: "omp",
posix: "omp",
@@ -189,10 +196,14 @@ function normalizeShellName(
throw new Error(`Unsupported shell${shell ? ` "${shell}"` : ""}. Supported shells: bash, zsh, fish, PowerShell.`);
}
export function resolveProfileAliasCommandFromProcess(
argv: readonly string[] = process.argv,
cwd: string = process.cwd(),
): ProfileAliasCommand {
/** Resolve the command a generated profile alias should invoke. */
export function resolveProfileAliasCommandFromProcess({
argv = process.argv,
cwd = process.cwd(),
compiled = process.env.PI_COMPILED === "true",
}: ProfileAliasProcessOptions = {}): ProfileAliasCommand {
if (compiled) return DEFAULT_ALIAS_COMMAND;
const runtime = argv[0];
const script = argv[1];
if (!runtime || !script || !/\.[cm]?[jt]s$/.test(script)) return DEFAULT_ALIAS_COMMAND;
@@ -29,7 +29,10 @@ describe("profile alias installer", () => {
});
it("resolves source invocations without forcing the source checkout as cwd", () => {
const command = resolveProfileAliasCommandFromProcess(["/bin/bun", "src/cli.ts"], "/repo/packages/coding-agent");
const command = resolveProfileAliasCommandFromProcess({
argv: ["/bin/bun", "src/cli.ts"],
cwd: "/repo/packages/coding-agent",
});
// path.resolve is platform-dependent (adds drive letter on Windows);
// the code normalizes to forward slashes for POSIX shell fields.
@@ -42,11 +45,28 @@ describe("profile alias installer", () => {
expect(command.powerShell).toBe(`'/bin/bun' '${expectedScriptPath}'`);
});
it("uses the installed command for a compiled standalone invocation", () => {
const command = resolveProfileAliasCommandFromProcess({
argv: ["bun", "/$bunfs/root/packages/coding-agent/src/cli.js"],
compiled: true,
});
expect(command).toEqual({
display: "omp",
posix: "omp",
fish: "omp",
powerShell: "omp",
});
});
it("normalizes a backslash runtime path for POSIX shell command fields", () => {
// On Windows argv[0] is typically a native path like C:\Users\me\.bun\bin\bun.exe;
// bash/zsh/fish fields must use forward slashes while PowerShell keeps the native path.
const runtime = "C:\\Users\\me\\.bun\\bin\\bun.exe";
const command = resolveProfileAliasCommandFromProcess([runtime, "src/cli.ts"], "/repo/packages/coding-agent");
const command = resolveProfileAliasCommandFromProcess({
argv: [runtime, "src/cli.ts"],
cwd: "/repo/packages/coding-agent",
});
const expectedScriptPath = path.resolve("/repo/packages/coding-agent", "src/cli.ts");
const expectedPosixPath = expectedScriptPath.replace(/\\/g, "/");