From b45897273000fd9bd444ee1bb7c0a4d1e8985b04 Mon Sep 17 00:00:00 2001 From: McAmner Date: Sun, 5 Jul 2026 19:29:02 +0300 Subject: [PATCH] refactor(mqlaunch): de-layer diagnostics into a lib (P4 / Step 11a) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Third Step 11a slice. Pull the diagnostics concern — version reporting (get_repo_version, show_version_info), self-check, debug bundle, and release notes — out of the mqlaunch.sh monolith into mqlaunch/lib/diagnostics.sh, sourced back into the launcher's scope. Verbatim move: the functions still rely on the launcher's ambient UI helpers and $BASE_DIR, and every caller (main dispatch + command-mode) resolves because the lib sources before dispatch. No behavior change. Pure bash, so the lib carries a bash shebang and is covered by shellcheck. Launcher: 1771 → 1654 lines (~430 out since 11a began). Add the diagnostics row to tests/monolith-delayer-smoke.sh (now 28 functions across 3 concern libs). AUTHORITY_MAP lists the new LIVE support lib; CHANGELOG updated. Note: system_check (an isolated diagnostics function elsewhere in the monolith) is a candidate for a follow-up slice into this same lib; left out here to keep this a single contiguous verbatim band. Co-Authored-By: Claude Opus 4.8 --- CHANGELOG.md | 16 ++-- docs/AUTHORITY_MAP.md | 1 + mqlaunch/lib/diagnostics.sh | 137 ++++++++++++++++++++++++++++++++ terminal/launchers/mqlaunch.sh | 135 +++---------------------------- tests/monolith-delayer-smoke.sh | 1 + 5 files changed, 157 insertions(+), 133 deletions(-) create mode 100755 mqlaunch/lib/diagnostics.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 91ebaff..d639484 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,13 +20,15 @@ All notable changes to this project will be documented in this file. ### Changed -* Monolith de-layering (Step 11a): the network concern (status, diagnostics, - and connectivity actions — 17 functions) and the fzf interactive pickers - (git log/branch, kill process/port, run snippet, recent files — 6 functions) - moved verbatim out of `terminal/launchers/mqlaunch.sh` into - `mqlaunch/lib/network.sh` and `mqlaunch/lib/fzf-pickers.sh`, sourced back into - the launcher's scope. No behavior change; the launcher drops ~310 lines and - each concern now has a named owner. Guarded by +* Monolith de-layering (Step 11a): three concerns moved verbatim out of + `terminal/launchers/mqlaunch.sh` into dedicated libraries sourced back into + the launcher's scope — the network concern (status/diagnostics/connectivity, + 17 functions → `mqlaunch/lib/network.sh`), the fzf interactive pickers + (git log/branch, kill process/port, run snippet, recent files, 6 functions → + `mqlaunch/lib/fzf-pickers.sh`), and diagnostics (version reporting, + self-check, debug bundle, release notes, 5 functions → + `mqlaunch/lib/diagnostics.sh`). No behavior change; the launcher drops ~430 + lines and each concern now has a named owner. Guarded by `tests/monolith-delayer-smoke.sh`, a table-driven check that fails if any extracted function is redefined in the monolith or a lib source is dropped. * `semantic-memory-maintainer` renamed to `vector-store-maintainer` to avoid diff --git a/docs/AUTHORITY_MAP.md b/docs/AUTHORITY_MAP.md index 2d6b850..e0afdc3 100644 --- a/docs/AUTHORITY_MAP.md +++ b/docs/AUTHORITY_MAP.md @@ -72,6 +72,7 @@ Reached through other live paths: | `mqlaunch/lib/mqobsidian/*` | `terminal/menus/mq-obsidian-menu.sh` | | `mqlaunch/lib/network.sh` | `terminal/launchers/mqlaunch.sh` (sourced) — network concern de-layered out of the monolith (Step 11a) | | `mqlaunch/lib/fzf-pickers.sh` | `terminal/launchers/mqlaunch.sh` (sourced) — fzf interactive pickers de-layered out of the monolith (Step 11a) | +| `mqlaunch/lib/diagnostics.sh` | `terminal/launchers/mqlaunch.sh` (sourced) — version/self-check/debug-bundle/release-notes de-layered out of the monolith (Step 11a) | ## Bridges diff --git a/mqlaunch/lib/diagnostics.sh b/mqlaunch/lib/diagnostics.sh new file mode 100755 index 0000000..c25dd1f --- /dev/null +++ b/mqlaunch/lib/diagnostics.sh @@ -0,0 +1,137 @@ +#!/usr/bin/env bash +# mqlaunch diagnostics — version reporting, self-check, debug bundle, and +# release notes. +# +# Extracted from terminal/launchers/mqlaunch.sh as part of Step 11a (monolith +# de-layering, audit P4). Sourced into the launcher's scope, so it relies on the +# launcher's ambient UI helpers (print_header/row/empty_row/print_footer/ +# pause_enter) and $BASE_DIR. It defines no state of its own and changes no +# behavior — the functions are verbatim moves. Pure bash (no zsh builtins), so +# it carries a bash shebang and is covered by shellcheck. + +# Gets repo version. +get_repo_version() { + local version_file="$BASE_DIR/VERSION" + + if [[ -f "$version_file" ]]; then + head -n 1 "$version_file" + else + echo "unknown" + fi +} + +# Shows version info. +show_version_info() { + print_header + row_bold "VERSION INFO" + empty_row + + local version + version="$(get_repo_version)" + local launcher="$BASE_DIR/terminal/launchers/mqlaunch.sh" + local main_menu="$BASE_DIR/terminal/menus/mq-main-menu.sh" + local help_menu="$BASE_DIR/terminal/menus/mq-help-menu.sh" + + row "Project: macos-scripts" + row "Version: $version" + row "Release stage: baseline" + row "Shell: zsh" + row "Project root: $BASE_DIR" + row "Launcher: $launcher" + row "Main menu: $main_menu" + row "Help module: $help_menu" + + print_footer + pause_enter +} + +# Runs self check. +run_self_check() { + print_header + row_bold "SELF-CHECK" + empty_row + + local check_script="$BASE_DIR/tools/scripts/test-all.sh" + + row "Running smoke checks..." + empty_row + + if [[ ! -x "$check_script" ]]; then + echo "${C_ERR}Missing or non-executable:${C_RESET} $check_script" + print_footer + pause_enter + return 1 + fi + + "$check_script" + local rc=$? + + echo + if [[ $rc -eq 0 ]]; then + echo "${C_OK}All smoke checks passed.${C_RESET}" + else + echo "${C_ERR}Smoke checks failed.${C_RESET}" + fi + + print_footer + pause_enter + return $rc +} + +# Runs debug bundle. +run_debug_bundle() { + print_header + row_bold "DEBUG BUNDLE" + empty_row + + local bundle_script="$BASE_DIR/tools/scripts/create-debug-bundle.sh" + + if [[ ! -x "$bundle_script" ]]; then + echo "${C_ERR}Missing or non-executable:${C_RESET} $bundle_script" + print_footer + pause_enter + return 1 + fi + + local outfile + outfile="$("$bundle_script")" + local rc=$? + + echo + if [[ $rc -eq 0 ]]; then + echo "${C_OK}Debug bundle created:${C_RESET}" + echo " $outfile" + [[ -f "$outfile" ]] && open -R "$outfile" 2>/dev/null || true + else + echo "${C_ERR}Debug bundle failed.${C_RESET}" + fi + + print_footer + pause_enter + return $rc +} + +# Shows release notes. +show_release_notes() { + print_header + row_bold "RELEASE NOTES" + empty_row + + local changelog="$BASE_DIR/CHANGELOG.md" + + if [[ ! -f "$changelog" ]]; then + echo "${C_ERR}Missing:${C_RESET} $changelog" + print_footer + pause_enter + return 1 + fi + + if command -v bat >/dev/null 2>&1; then + bat --style=plain --paging=never "$changelog" | head -n 80 + else + head -n 80 "$changelog" + fi + + print_footer + pause_enter +} diff --git a/terminal/launchers/mqlaunch.sh b/terminal/launchers/mqlaunch.sh index 75dacef..51d5076 100755 --- a/terminal/launchers/mqlaunch.sh +++ b/terminal/launchers/mqlaunch.sh @@ -1123,132 +1123,15 @@ open_tools_menu() { fi } -# Gets repo version. -get_repo_version() { - local version_file="$BASE_DIR/VERSION" - - if [[ -f "$version_file" ]]; then - head -n 1 "$version_file" - else - echo "unknown" - fi -} - -# Shows version info. -show_version_info() { - print_header - row_bold "VERSION INFO" - empty_row - - local version - version="$(get_repo_version)" - local launcher="$BASE_DIR/terminal/launchers/mqlaunch.sh" - local main_menu="$BASE_DIR/terminal/menus/mq-main-menu.sh" - local help_menu="$BASE_DIR/terminal/menus/mq-help-menu.sh" - - row "Project: macos-scripts" - row "Version: $version" - row "Release stage: baseline" - row "Shell: zsh" - row "Project root: $BASE_DIR" - row "Launcher: $launcher" - row "Main menu: $main_menu" - row "Help module: $help_menu" - - print_footer - pause_enter -} - -# Runs self check. -run_self_check() { - print_header - row_bold "SELF-CHECK" - empty_row - - local check_script="$BASE_DIR/tools/scripts/test-all.sh" - - row "Running smoke checks..." - empty_row - - if [[ ! -x "$check_script" ]]; then - echo "${C_ERR}Missing or non-executable:${C_RESET} $check_script" - print_footer - pause_enter - return 1 - fi - - "$check_script" - local rc=$? - - echo - if [[ $rc -eq 0 ]]; then - echo "${C_OK}All smoke checks passed.${C_RESET}" - else - echo "${C_ERR}Smoke checks failed.${C_RESET}" - fi - - print_footer - pause_enter - return $rc -} - -# Runs debug bundle. -run_debug_bundle() { - print_header - row_bold "DEBUG BUNDLE" - empty_row - - local bundle_script="$BASE_DIR/tools/scripts/create-debug-bundle.sh" - - if [[ ! -x "$bundle_script" ]]; then - echo "${C_ERR}Missing or non-executable:${C_RESET} $bundle_script" - print_footer - pause_enter - return 1 - fi - - local outfile - outfile="$("$bundle_script")" - local rc=$? - - echo - if [[ $rc -eq 0 ]]; then - echo "${C_OK}Debug bundle created:${C_RESET}" - echo " $outfile" - [[ -f "$outfile" ]] && open -R "$outfile" 2>/dev/null || true - else - echo "${C_ERR}Debug bundle failed.${C_RESET}" - fi - - print_footer - pause_enter - return $rc -} - -# Shows release notes. -show_release_notes() { - print_header - row_bold "RELEASE NOTES" - empty_row - - local changelog="$BASE_DIR/CHANGELOG.md" - - if [[ ! -f "$changelog" ]]; then - echo "${C_ERR}Missing:${C_RESET} $changelog" - print_footer - pause_enter - return 1 - fi - - if command -v bat >/dev/null 2>&1; then - bat --style=plain --paging=never "$changelog" | head -n 80 - else - head -n 80 "$changelog" - fi - - print_footer - pause_enter -} +# Diagnostics — version reporting, self-check, debug bundle, and release notes +# — live in a dedicated library (Step 11a monolith de-layering, audit P4). +# Sourced into this scope so they keep using the ambient UI helpers and +# $BASE_DIR; no behavior change — the functions are verbatim moves. +if [[ -f "$BASE_DIR/mqlaunch/lib/diagnostics.sh" ]]; then + source "$BASE_DIR/mqlaunch/lib/diagnostics.sh" +else + mq_debug "mqlaunch: diagnostics lib missing: mqlaunch/lib/diagnostics.sh" +fi # Runs mqlogin. run_mqlogin() { diff --git a/tests/monolith-delayer-smoke.sh b/tests/monolith-delayer-smoke.sh index 24d586b..d27802e 100755 --- a/tests/monolith-delayer-smoke.sh +++ b/tests/monolith-delayer-smoke.sh @@ -16,6 +16,7 @@ fail() { printf '[FAIL] %s\n' "$1" >&2; exit 1; } CONCERNS=( "mqlaunch/lib/network.sh : network_default_interface network_service_name network_interface_ip network_dns_server network_gateway network_ssid network_ping_ms network_value network_report copy_network_info open_network_settings ping_test show_dns_gateway run_network_pulse run_network_ghost run_network_quality show_network_info" "mqlaunch/lib/fzf-pickers.sh : fzf_git_log fzf_git_branch fzf_kill_process fzf_kill_port fzf_run_snippet fzf_recent_files" + "mqlaunch/lib/diagnostics.sh : get_repo_version show_version_info run_self_check run_debug_bundle show_release_notes" ) total=0