Instruction file imported from aheckmann/m (
.github/instructions/m.instructions.md). Copyright stays with the author.
LLM Code Review Guidelines for m (Bash)
These instructions guide an automated reviewer to evaluate changes in this repository, with special focus on the Bash executable at bin/m. They codify the style, structure, and safety patterns used in the codebase.
Goals
- Preserve existing behavior and cross-platform support (Linux and macOS).
- Maintain consistent style, naming, and logging conventions.
- Ensure safe shell practices aligned with how the current code is written (do not introduce incompatible patterns by default).
- Keep downloads, version parsing, and filesystem operations robust and predictable.
Style and Formatting
- Bash options: extended globbing is enabled (
shopt -s extglob) and used; do not disable or break it. - Indentation: two spaces; no tabs.
- Function names: lower_snake_case, concise and action-oriented (e.g.,
install_bin,display_help). - Global constants/config: UPPER_SNAKE_CASE (e.g.,
M_PREFIX,VERSIONS_DIR,VERSION). - Locals/temporaries: lowercase, prefer
localwithin functions (local version=$1). - Blank lines: separate logical blocks and before/after function definitions.
- Comments:
- Use
#lines above functions to explain purpose and simple usage. - Use section headers like
### Setupor# Handle argumentsfor structure. - Keep comments short, action-focused, and in the same style as existing ones.
- Use
Logging, Errors, and Output
- Use the provided helpers consistently:
logfor normal progress messages (stdout).debugfor debug-only output (stderr).abortto print an error and exit nonzero; prefer it for fatal conditions.abort_not_installedfor version-not-installed cases.
- Prefer
printfoverechofor predictable formatting. - Keep JSON output valid (no trailing commas, correct brackets). Follow
display_versions/display_tools_versionspatterns.
CLI/Dispatch Conventions
- Main argument handling is via a
caseon$1with aliases (e.g.,ls|list|available|avail). Maintain existing alias patterns. - Help/version options:
-h|--help|help,-V|--versionare supported; preserve and update help text when adding user-facing commands. - For commands that act on versions, accept release series such as
X.Yas well as fullX.Y.Zand-entflavors where applicable.
Version and Regex Handling
- Use existing helpers for comparisons:
verlt,verlte,vergte(which rely onsort -V).numeric_versionforX.Y.Zto padded integer.
- When matching versions, prefer portable ERE classes like
[0-9]instead of\d(GNUgrep -Edoes not treat\das a digit). Ensure regexes are anchored or made specific to avoid accidental matches. - Keep the distinction between “latest” (may include RCs) and “stable” (no RCs) consistent with existing code paths.
Networking and Downloads
- Downloader abstraction:
$GETis set once to stream output (eithercurl -sSLforwget -q -O-).- Use
$GET URL | tar ...for streaming downloads (as done indownload).
- Use
- Preserve existing failure handling: check exit statuses, and on failure clean up and print actionable messages (see
download,install_tools_bin). - Respect
CACHE,CACHE_SRC, andCACHE_EXPIRYbehavior when touching version metadata caching. - When calling public APIs (e.g., GitHub), support optional
GH_TOKENfor authenticated requests as shown.
OS/Distro/Arch Detection
- Continue to use
get_distro_and_archto populateos,arch,sslbuild, anddistros. - Don’t duplicate distro-mapping logic; prefer centralizing changes in
get_distro_and_archif needed.
Filesystem, Symlinks, and Hooks
- Create directories with
mkdir -pand check for permissions; fail early withabortwhen needed. - Use
ln -fsto (re)point symlinks and binaries; preserve use of extglob to exclude tools when appropriate. - Clean temporary build directories with
cleanupon both success and failure paths. - Maintain hook semantics:
pre <event>andpost <event>scripts must be executable, absolute paths.- Use
pre/postinvocations around installation/activation per current code.
Safety and Portability Checks
When reviewing changes, verify:
- Quoting and word-splitting:
- Quote variables in tests and command invocations unless globs/word-splitting are explicitly intended (e.g., extglob list expansion).
- Quote URLs and file paths that may contain spaces.
- Exit codes and short-circuits:
- Check and handle non-zero exit codes; preserve
exit 0for success paths where used. - Do not introduce
set -euo pipefailglobally; the codebase manages errors manually and relies on controlled short-circuits.
- Check and handle non-zero exit codes; preserve
- No
eval, no untrusted command construction. - JSON/text output remains stable for consumers (e.g., scripts parsing
installed --json). - RC/stable selection logic still correct after changes (review regexes and sorts).
- Symlink targets always exist prior to linking;
M_BIN_DIRis created as needed. - Cleanup always runs on failures that create temp dirs or partial artifacts.
Reviews of Version Discovery Logic
- Prefer using
get_all_versions(andget_all_tools_versions) rather than re-fetching inside new code paths. - Ensure that sorting is stable and uses
sort -Vor numeric field sorts comparable to existing code. - If adding new series logic (e.g., handling future major versions), mirror stable/latest rules already present.
Messaging and UX
- Keep messages short and consistent (e.g., "Activating: MongoDB Server X, MongoDB Database Tools Y").
- Warn clearly when PATH doesn’t include
M_BIN_DIR. - For macOS, preserve helpful brew hints for
mongoshinstallation.
Quick Review Checklist
Use this as a fast pass before approving:
- Naming/structure
- Functions lower_snake_case; globals UPPER_SNAKE_CASE; locals
local. - Two-space indent; section headers/comments match existing tone.
- Functions lower_snake_case; globals UPPER_SNAKE_CASE; locals
- Safety
- Variables quoted unless intentional globbing/splitting.
- No
eval; exit codes checked; failures callabortand clean up.
- Networking
-
$GETonly used for streaming; file-writing uses explicit curl/wget handling. -
GH_TOKENrespected where relevant.
-
- Versions/regex
- Use
ver*helpers andnumeric_versionfor comparisons. - Regex uses
[0-9]classes, not\d; anchored/filtered to avoid false matches.
- Use
- OS/Distro/Arch
- Changes funnel through
get_distro_and_archif needed; Apple Silicon caveats preserved.
- Changes funnel through
- FS and hooks
-
mkdir -pbefore writes; symlinks vialn -fs; hooks executed around change/install.
-
- Output/UX
- JSON output well-formed; help text updated if new flags/commands added.
- Backward compatibility
- Aliases preserved; stable/latest semantics unchanged; existing users not broken.
Notes on Known Footguns to Flag
- Using
$GET ... -o fileis incorrect forwget -q -O-; prefer explicit curl/wget file-download handling or a small helper. grep -E "\\d"isn’t portable; use[0-9].- Unquoted path variables in
rm,mv, orlncan be dangerous; quote unless globbing intended. - Avoid introducing
set -eglobally; it can break flows relying on manual error checks.