Skip to content

Conversation

@ethanndickson
Copy link
Member

@ethanndickson ethanndickson commented Dec 15, 2025

Summary

Fix CLI subcommands (server, api, run) not working when invoked from packaged AppImage.

Problem

When running ./mux.AppImage server or ./mux.AppImage --help, the commands weren't recognized and the app would either launch the desktop GUI or fail.

Root cause: Incorrect argv offset detection across different execution contexts:

Environment isElectron process.defaultApp First arg index
bun mux false undefined 2
electron . true true 2
./mux.AppImage true undefined 1

The original code used process.argv[2] unconditionally, which broke packaged apps.

Solution

Created src/cli/argv.ts with testable pure functions:

  • detectCliEnvironment() - Returns { isElectron, isPackagedElectron, firstArgIndex }
  • getParseOptions() - Returns Commander parse options ({ from: "electron" | "node" })
  • getSubcommand() - Gets subcommand at correct argv index
  • getArgsAfterSplice() - Gets remaining args for subcommand handlers
  • isCommandAvailable() - Checks if a command is available in current environment

Key insight: Use isPackagedElectron = isElectron && !process.defaultApp to correctly identify packaged apps.

Manual Test Results

Bun/Node CLI

Command Result
bun src/cli/index.ts --help ✅ Shows help WITH "run" command
bun src/cli/index.ts server --help ✅ Shows server options
bun src/cli/index.ts run --help ✅ Shows run options
bun dist/cli/index.js api --help ✅ Shows api commands

Electron Dev Mode

Command Result
bunx electron . server --help ✅ Shows server options
bunx electron . api --help ✅ Shows api commands
bunx electron . run ✅ Friendly error (not crash)
bunx electron . ✅ Launches desktop

Packaged AppImage

Command Result
./release/mux-*-x86_64.AppImage --help ✅ Shows help WITHOUT "run"
./release/mux-*-x86_64.AppImage server --help ✅ Shows server options
./release/mux-*-x86_64.AppImage api --help ✅ Shows api commands
./release/mux-*-x86_64.AppImage run ✅ Friendly error
./release/mux-*-x86_64.AppImage ✅ Launches desktop

Generated with mux • Model: anthropic:claude-sonnet-4-20250514 • Thinking: low

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@ethanndickson ethanndickson added this pull request to the merge queue Dec 16, 2025
@ethanndickson ethanndickson removed this pull request from the merge queue due to a manual request Dec 16, 2025
@ethanndickson
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Fix CLI subcommands (server, api, run) not working when invoked from
packaged AppImage. The issue was incorrect argv offset detection.

Problem:
- In packaged Electron apps, argv = [app, ...args] (first arg at index 1)
- In dev mode (electron .), argv = [electron, ".", ...args] (index 2)
- In bun/node, argv = [node, script, ...args] (index 2)

The original code used process.argv[2] unconditionally, which broke
packaged apps. The initial fix used process.defaultApp which is undefined
in both packaged Electron AND bun/node, breaking non-Electron CLI.

Solution:
- Use isPackagedElectron = isElectron && !process.defaultApp
- Only packaged Electron uses index 1; all others use index 2
- Update Commander parse mode in server.ts and run.ts

Additional improvements:
- Hide 'run' command from packaged app help (not bundled)
- Friendly error when trying to run 'mux run' from AppImage
- Remove '(requires Electron)' suffix in Electron context

---
_Generated with `mux` • Model: `anthropic:claude-opus-4-5` • Thinking: `high`_
@ethanndickson
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- Extract isCommandAvailable() to argv.ts for testable command availability
- Fix run command check: use isElectron (not isPackagedElectron)
- Add 5 unit tests for isCommandAvailable()
- bunx electron . run now shows friendly error instead of crash
@ethanndickson
Copy link
Member Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Hooray!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ethanndickson ethanndickson added this pull request to the merge queue Dec 16, 2025
Merged via the queue into main with commit e389455 Dec 16, 2025
20 checks passed
@ethanndickson ethanndickson deleted the appimage-7hpn branch December 16, 2025 02:33
github-merge-queue bot pushed a commit that referenced this pull request Dec 16, 2025
)

## Summary

Fix `./mux.AppImage --no-sandbox` and other Electron flags not working -
they were incorrectly falling through to CLI help instead of launching
the desktop app.

## Problem

After the previous CLI argv fix (#1161), Electron flags like
`--no-sandbox` in packaged AppImage were treated as unknown CLI
arguments:

```
./mux.AppImage --no-sandbox  # showed CLI help instead of launching desktop
```

## Root Cause

`isElectronLaunchArg()` immediately returned `false` for all packaged
Electron flags, not distinguishing between:
- **CLI flags** (`--help`, `--version`) → should show CLI help
- **Electron flags** (`--no-sandbox`, `--disable-gpu`) → should launch
desktop

## Solution

- Add `CLI_GLOBAL_FLAGS` constant listing flags that should show CLI
help
- Update `isElectronLaunchArg()` to return `true` for non-CLI flags in
packaged mode
- Add runtime sanity check (dev mode only) to warn if flags get out of
sync
- Add tests for the new behavior

## Manual Test Results

| Command | Result |
|---------|--------|
| `./mux.AppImage --no-sandbox` | ✅ Launches desktop |
| `./mux.AppImage --disable-gpu` | ✅ Launches desktop |
| `./mux.AppImage --help` | ✅ Shows CLI help |
| `./mux.AppImage --version` | ✅ Shows version |
| `./mux.AppImage server --help` | ✅ Shows server options |
| `bunx electron . --no-sandbox` | ✅ Launches desktop (dev mode) |

---
_Generated with `mux` • Model: `anthropic:claude-sonnet-4-20250514` •
Thinking: `low`_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant