Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ All notable changes to this project will be documented in this file.

### Changed

* Monolith de-layering (Step 11a): three concerns moved verbatim out of
* Monolith de-layering (Step 11a): four 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, plus the system check, 6 functions →
`mqlaunch/lib/diagnostics.sh`). No behavior change; the launcher drops ~530
lines and each concern now has a named owner. Guarded by
`mqlaunch/lib/fzf-pickers.sh`), diagnostics (version reporting, self-check,
debug bundle, release notes, plus the system check, 6 functions →
`mqlaunch/lib/diagnostics.sh`), and the git & release menu launchers
(2 functions → `mqlaunch/lib/git-menus.sh`). No behavior change; the launcher
drops ~600 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
Expand Down
1 change: 1 addition & 0 deletions docs/AUTHORITY_MAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Reached through other live paths:
| `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/system-check de-layered out of the monolith (Step 11a) |
| `mqlaunch/lib/git-menus.sh` | `terminal/launchers/mqlaunch.sh` (sourced) — git & release menu launchers de-layered out of the monolith (Step 11a) |

## Bridges

Expand Down
91 changes: 91 additions & 0 deletions mqlaunch/lib/git-menus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env bash
# mqlaunch git & release menu launchers.
#
# Extracted from terminal/launchers/mqlaunch.sh as part of Step 11a (monolith
# de-layering, audit P4). Both functions launch an external menu script
# (gitlaunch.sh / mq-release-menu.sh) and invalidate the cached dashboard header
# on return, since a commit/stash/tag makes the cached Git status stale. 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, and on
# mq_dashboard_cache_invalidate / release_menu_loop when present (both guarded
# with command -v). No behavior change — the functions are verbatim moves. Pure
# bash, so it carries a bash shebang and is covered by shellcheck.

# Opens git menu.
open_git_menu() {
local repo_arg="${1:-}"
local git_script="$BASE_DIR/terminal/launchers/gitlaunch.sh"
local git_path="" back_marker restart_count

if [[ -n "$repo_arg" ]]; then
git_path="$repo_arg"
else
git_path="$(pwd)"
fi

if [[ ! -x "$git_script" && ! -f "$git_script" ]]; then
print_header
row "GIT MENU"
empty_row
row "Git menu not found:"
row " $git_script"
print_footer
pause_enter
return
fi

back_marker="/tmp/mq-gitlaunch-back.$$"
restart_count=0

while true; do
rm -f "$back_marker" 2>/dev/null || true

if [[ -x "$git_script" ]]; then
MQ_GIT_REPO="$git_path" MQ_GITLAUNCH_BACK_MARKER="$back_marker" "$git_script"
else
MQ_GIT_REPO="$git_path" MQ_GITLAUNCH_BACK_MARKER="$back_marker" zsh "$git_script"
fi

[[ -f "$back_marker" ]] && break

restart_count=$(( restart_count + 1 ))
if [[ "$restart_count" -ge 5 ]]; then
printf "Gitlaunch exited unexpectedly %d times; returning to mqlaunch.\n" "$restart_count"
sleep 1
break
fi
done

rm -f "$back_marker" 2>/dev/null || true

# The git menu can commit/stash, so the cached dashboard header is now stale.
# Drop it so the main loop re-renders fresh Git status instead of waiting out
# the cache TTL.
command -v mq_dashboard_cache_invalidate >/dev/null 2>&1 && mq_dashboard_cache_invalidate
}

# Opens release menu.
open_release_menu() {
local release_menu="$BASE_DIR/terminal/menus/mq-release-menu.sh"

if command -v release_menu_loop >/dev/null 2>&1; then
MQ_USE_DASHBOARD_HEADER=1 release_menu_loop
elif [[ -x "$release_menu" ]]; then
MQ_USE_DASHBOARD_HEADER=1 "$release_menu" menu
elif [[ -f "$release_menu" ]]; then
chmod +x "$release_menu" 2>/dev/null || true
MQ_USE_DASHBOARD_HEADER=1 bash "$release_menu" menu
else
print_header
row "RELEASE MENU"
empty_row
row "Release menu not found:"
row " $release_menu"
print_footer
pause_enter
fi

# The release flow can commit/tag, so invalidate the cached dashboard header
# before returning to the main loop.
command -v mq_dashboard_cache_invalidate >/dev/null 2>&1 && mq_dashboard_cache_invalidate
}
87 changes: 9 additions & 78 deletions terminal/launchers/mqlaunch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -886,84 +886,15 @@ theme_source_state() {
fi
}

# Opens git menu.
open_git_menu() {
local repo_arg="${1:-}"
local git_script="$BASE_DIR/terminal/launchers/gitlaunch.sh"
local git_path="" back_marker restart_count

if [[ -n "$repo_arg" ]]; then
git_path="$repo_arg"
else
git_path="$(pwd)"
fi

if [[ ! -x "$git_script" && ! -f "$git_script" ]]; then
print_header
row "GIT MENU"
empty_row
row "Git menu not found:"
row " $git_script"
print_footer
pause_enter
return
fi

back_marker="/tmp/mq-gitlaunch-back.$$"
restart_count=0

while true; do
rm -f "$back_marker" 2>/dev/null || true

if [[ -x "$git_script" ]]; then
MQ_GIT_REPO="$git_path" MQ_GITLAUNCH_BACK_MARKER="$back_marker" "$git_script"
else
MQ_GIT_REPO="$git_path" MQ_GITLAUNCH_BACK_MARKER="$back_marker" zsh "$git_script"
fi

[[ -f "$back_marker" ]] && break

restart_count=$(( restart_count + 1 ))
if [[ "$restart_count" -ge 5 ]]; then
printf "Gitlaunch exited unexpectedly %d times; returning to mqlaunch.\n" "$restart_count"
sleep 1
break
fi
done

rm -f "$back_marker" 2>/dev/null || true

# The git menu can commit/stash, so the cached dashboard header is now stale.
# Drop it so the main loop re-renders fresh Git status instead of waiting out
# the cache TTL.
command -v mq_dashboard_cache_invalidate >/dev/null 2>&1 && mq_dashboard_cache_invalidate
}

# Opens release menu.
open_release_menu() {
local release_menu="$BASE_DIR/terminal/menus/mq-release-menu.sh"

if command -v release_menu_loop >/dev/null 2>&1; then
MQ_USE_DASHBOARD_HEADER=1 release_menu_loop
elif [[ -x "$release_menu" ]]; then
MQ_USE_DASHBOARD_HEADER=1 "$release_menu" menu
elif [[ -f "$release_menu" ]]; then
chmod +x "$release_menu" 2>/dev/null || true
MQ_USE_DASHBOARD_HEADER=1 bash "$release_menu" menu
else
print_header
row "RELEASE MENU"
empty_row
row "Release menu not found:"
row " $release_menu"
print_footer
pause_enter
fi

# The release flow can commit/tag, so invalidate the cached dashboard header
# before returning to the main loop.
command -v mq_dashboard_cache_invalidate >/dev/null 2>&1 && mq_dashboard_cache_invalidate
}
# Git & release menu launchers 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/git-menus.sh" ]]; then
source "$BASE_DIR/mqlaunch/lib/git-menus.sh"
else
mq_debug "mqlaunch: git menus lib missing: mqlaunch/lib/git-menus.sh"
fi

# Runs mqworkflows.
run_mqworkflows() {
Expand Down
8 changes: 5 additions & 3 deletions tests/dashboard-header-cache-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ pass "MQ_DASHBOARD_CACHE_TTL=0 disables caching"

# 5. The mutating sub-menus invalidate the cache on the way back to the main
# loop, so a commit/stash/tag is reflected immediately rather than after the TTL.
LAUNCHER="$ROOT/terminal/launchers/mqlaunch.sh"
awk '/^open_git_menu\(\)/{f=1} f&&/mq_dashboard_cache_invalidate/{print; exit}' "$LAUNCHER" \
# open_git_menu / open_release_menu were de-layered into mqlaunch/lib/git-menus.sh
# (Step 11a); the contract is unchanged, only the file that owns it.
GIT_MENUS="$ROOT/mqlaunch/lib/git-menus.sh"
awk '/^open_git_menu\(\)/{f=1} f&&/mq_dashboard_cache_invalidate/{print; exit}' "$GIT_MENUS" \
| grep -q mq_dashboard_cache_invalidate || fail "open_git_menu does not invalidate the cache on Back"
awk '/^open_release_menu\(\)/{f=1} f&&/mq_dashboard_cache_invalidate/{print; exit}' "$LAUNCHER" \
awk '/^open_release_menu\(\)/{f=1} f&&/mq_dashboard_cache_invalidate/{print; exit}' "$GIT_MENUS" \
| grep -q mq_dashboard_cache_invalidate || fail "open_release_menu does not invalidate the cache on Back"
pass "git and release menus invalidate the cache on return"

Expand Down
1 change: 1 addition & 0 deletions tests/monolith-delayer-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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 system_check"
"mqlaunch/lib/git-menus.sh : open_git_menu open_release_menu"
)

total=0
Expand Down
2 changes: 1 addition & 1 deletion tools/scripts/test-mqlaunch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ assert_grep 'dev\).*open_dev_menu' "$LEGACY" "Dev route exists in launcher"
assert_grep 'tools\) open_tools_menu' "$LEGACY" "Tools route exists in launcher"
assert_grep 'restart\|reload\|relaunch\).*restart_mqlaunch' "$LEGACY" "mqlaunch restart route exists"
assert_grep 'tools-menu\|toolsmenu\|menu-tools\|tools-v1\|menu-tools-v1\)' "$LEGACY" "Legacy Tools aliases still exist"
assert_grep 'terminal/launchers/gitlaunch\.sh' "$LEGACY" "Git route uses gitlaunch"
assert_grep 'terminal/launchers/gitlaunch\.sh' "$PROJECT_ROOT/mqlaunch/lib/git-menus.sh" "Git route uses gitlaunch"
assert_grep 'RELEASE_SCRIPT="\$RELEASE_REPO/release\.sh"' "$RELEASE_MENU" "Release menu points at root release script"

assert_grep 'render_main_menu_panel' "$PROJECT_ROOT/terminal/menus/mq-main-menu.sh" "Main menu panel exists"
Expand Down
Loading