diff --git a/components/hoxay/README.md b/components/hoxay/README.md index e006ae12..bef02ca9 100644 --- a/components/hoxay/README.md +++ b/components/hoxay/README.md @@ -35,7 +35,7 @@ of scope — the herdr TUI keeps its existing operation there. | Action | macOS/POSIX | Windows 11 | | --- | --- | --- | -| install | `install.sh [ref]` | `install.ps1 [-Ref ]` | +| install | `install.sh [--flavor electron\|native] [ref]` | `install.ps1 [-Ref ]` | | update | `update.sh [ref]` | `update.ps1 [-Ref ]` | | launch | `launch.sh` | `launch.ps1` | | verify | `verify.sh [--live]` | `verify.ps1 [-Live]` | @@ -64,6 +64,27 @@ leaves `current` (and the installed app / shortcut) untouched; `rollback` flips the pointer back to the previous release dir, which is kept on disk, and re-stages it. +### Build flavor (macOS) + +`install.sh` builds one of two backends, recorded in `$STATE_DIR/flavor`: + +- `electron` (default): `desktop:pack` bundle — the web/terminal fallback + path. This is what every existing install already is. +- `native`: `native:pack` bundle — the GPUI shell (`herdr-ui`) staged as + `hoxay.app` by hoxay's `scripts/build-native.ts`. Requires the Rust + toolchain the repo `mise.toml` pins (rebuildup/hoxay#734); ad-hoc + signed, local distribution only. + +Selection order: `--flavor`/`--native`/`--electron` flag, `HOXAY_FLAVOR` +env, the recorded flavor, then `electron`. `update.sh` forwards its +arguments to `install.sh`, so it keeps whichever flavor is recorded — +passing `--flavor`/`--native`/`--electron` to `update.sh` switches +backend deliberately. Both flavors produce the same bundle id +(`com.github.rebuildup.herdr-t3`), so a flavor switch upgrades the same +app identity in place; `verify` reports the recorded flavor and warns +when the release checkout only carries the other flavor's build output. +Windows stays Electron-only until GPUI packaging exists there. + `verify --live` additionally checks that the app process is running, the herdr endpoint is reachable (macOS: `~/.config/herdr/herdr.sock`; Windows: the named-pipe endpoint `\\.\pipe\`), and — on macOS — diff --git a/components/hoxay/common.sh b/components/hoxay/common.sh index aece94c3..d150269e 100755 --- a/components/hoxay/common.sh +++ b/components/hoxay/common.sh @@ -97,10 +97,39 @@ app_executable_path() { # $1 = .app path printf '%s/Contents/MacOS/%s' "$1" "$exe" } +# Product flavor: `electron` (default, web fallback) or `native` (the GPUI +# shell bundled by hoxay's scripts/build-native.ts). The flavor is recorded +# in $STATE_DIR/flavor at install time so update/verify follow the installed +# backend instead of silently switching. Both flavors stage the same +# `hoxay.app` bundle id — they are the same app identity, not two products. +current_flavor() { # $1 = state dir + local f="$1/flavor" + if [[ -f "$f" ]]; then + cat "$f" + else + printf 'electron' + fi +} + # Print the built app of a release checkout (empty when the release has no -# build output). electron-builder writes `release//.app`. -built_app_of() { # $1 = release checkout dir - find "$1/release" -maxdepth 2 -name '*.app' -type d 2>/dev/null | head -1 +# build output). electron-builder writes `release//.app`; +# the native bundle lands in `native-dist/hoxay.app`. An optional flavor +# argument restricts the lookup so a checkout carrying both outputs cannot +# pick the wrong artifact. +built_app_of() { # $1 = release checkout dir, $2 = flavor (optional) + local app="" + case "${2:-}" in + electron) + app="$(find "$1/release" -maxdepth 2 -name '*.app' -type d 2>/dev/null | head -1)" ;; + native) + app="$(find "$1/native-dist" -maxdepth 1 -name '*.app' -type d 2>/dev/null | head -1)" ;; + *) + app="$(find "$1/release" -maxdepth 2 -name '*.app' -type d 2>/dev/null | head -1)" + if [[ -z "$app" ]]; then + app="$(find "$1/native-dist" -maxdepth 1 -name '*.app' -type d 2>/dev/null | head -1)" + fi ;; + esac + printf '%s' "$app" } # Print every app in the apps dir that carries the managed bundle id. diff --git a/components/hoxay/install.sh b/components/hoxay/install.sh index 6affda06..f5fa6db1 100755 --- a/components/hoxay/install.sh +++ b/components/hoxay/install.sh @@ -13,8 +13,11 @@ # exist side by side; the `current_app` pointer selects the active one and # only the active one stays registered with Launch Services. # -# Usage: install.sh [ref] +# Usage: install.sh [--flavor electron|native|--native|--electron] [ref] # ref: a v* tag or a full commit SHA (default: newest v* tag on origin). +# flavor: electron builds the desktop:pack bundle (default/web fallback); +# native builds the GPUI shell via native:pack. Defaults to the +# recorded install flavor so update.sh keeps the same backend. set -euo pipefail HERE="$(cd "$(dirname "$0")" && pwd)" @@ -33,6 +36,29 @@ INSTALLED_FILE="$STATE_DIR/installed" LOG_DIR="$STATE_DIR/logs" mkdir -p "$RELEASES_DIR" "$LOG_DIR" "$APPS_DIR" +# Product flavor: electron (default, web fallback) or native (GPUI shell). +# Resolution order: --flavor/--native/--electron flag, HOXAY_FLAVOR env, +# the recorded install flavor, then electron. The chosen flavor is written +# back to $STATE_DIR/flavor so update.sh keeps the same backend. +flavor="${HOXAY_FLAVOR:-$(current_flavor "$STATE_DIR")}" +ref_arg="" +while [[ $# -gt 0 ]]; do + case "$1" in + --flavor) + [[ $# -ge 2 ]] || die "--flavor needs electron or native" + flavor="$2"; shift 2 ;; + --flavor=*) + flavor="${1#--flavor=}"; shift ;; + --native) flavor="native"; shift ;; + --electron) flavor="electron"; shift ;; + *) + [[ -z "$ref_arg" ]] || die "unexpected argument: $1" + ref_arg="$1"; shift ;; + esac +done +[[ "$flavor" == "electron" || "$flavor" == "native" ]] \ + || die "unknown flavor: $flavor (expected electron or native)" + resolve_ref() { local ref="${1:-}" if [[ -z "$ref" ]]; then @@ -51,7 +77,7 @@ resolve_ref() { printf '%s' "$ref" } -ref="$(resolve_ref "${1:-}")" +ref="$(resolve_ref "$ref_arg")" name="$(printf '%s' "$ref" | tr '/:' '__')" target="$RELEASES_DIR/$name" @@ -101,14 +127,25 @@ MISE_ISOLATED_ENV=( "MISE_IGNORED_CONFIG_PATHS=$MISE_IGNORED_CONFIG_PATHS_VALUE" ) -(cd "$target" \ - && env "${MISE_ISOLATED_ENV[@]}" mise install --locked >/dev/null \ - && bun install --frozen-lockfile \ - && CSC_IDENTITY_AUTO_DISCOVERY=false bun run desktop:pack) \ - || die "build failed for $name; installed app left untouched" +if [[ "$flavor" == "native" ]]; then + # GPUI shell: scripts/build-native.ts builds herdr-ui and stages + # native-dist/hoxay.app (ad-hoc signed). Requires the Rust toolchain the + # repo mise.toml pins (hoxay #734). + (cd "$target" \ + && env "${MISE_ISOLATED_ENV[@]}" mise install --locked >/dev/null \ + && bun install --frozen-lockfile \ + && bun run native:pack) \ + || die "native build failed for $name; installed app left untouched" +else + (cd "$target" \ + && env "${MISE_ISOLATED_ENV[@]}" mise install --locked >/dev/null \ + && bun install --frozen-lockfile \ + && CSC_IDENTITY_AUTO_DISCOVERY=false bun run desktop:pack) \ + || die "build failed for $name; installed app left untouched" +fi -built="$(built_app_of "$target")" -[[ -n "$built" ]] || die "no .app built under $target/release" +built="$(built_app_of "$target" "$flavor")" +[[ -n "$built" ]] || die "no $flavor .app built under $target" [[ "$(bundle_id_of "$built")" == "$BUNDLE_ID" ]] \ || die "built app has unexpected bundle id: $(bundle_id_of "$built")" @@ -120,4 +157,5 @@ register_active_app "$dst" printf '%s\n' "$name" > "$CURRENT_FILE" printf '%s\n' "$dst" > "$APP_FILE" printf '%s\n%s\n' "$name" "$commit" > "$INSTALLED_FILE" -log "installed $name ($commit) -> $dst" +printf '%s\n' "$flavor" > "$STATE_DIR/flavor" +log "installed $name ($commit, $flavor) -> $dst" diff --git a/components/hoxay/launch.sh b/components/hoxay/launch.sh index 336f4d5d..85600650 100755 --- a/components/hoxay/launch.sh +++ b/components/hoxay/launch.sh @@ -30,7 +30,7 @@ if [[ -f "$APP_FILE" ]]; then fi if [[ -z "$app" ]]; then # Fall back to the app this release staged. - built="$(built_app_of "$release")" + built="$(built_app_of "$release" "$(current_flavor "$STATE_DIR")")" if [[ -n "$built" ]]; then candidate="$APPS_DIR/$(basename "$built")" if [[ -d "$candidate" ]]; then diff --git a/components/hoxay/rollback.sh b/components/hoxay/rollback.sh index 548f875f..021a92dc 100755 --- a/components/hoxay/rollback.sh +++ b/components/hoxay/rollback.sh @@ -22,7 +22,12 @@ INSTALLED_FILE="$STATE_DIR/installed" [[ -f "$PREV_FILE" ]] || die "no previous release recorded" prev="$(cat "$PREV_FILE")" -built="$(built_app_of "$STATE_DIR/releases/$prev")" +# The superseded release may predate a flavor switch; prefer the recorded +# flavor but fall back to whichever artifact the checkout actually has. +built="$(built_app_of "$STATE_DIR/releases/$prev" "$(current_flavor "$STATE_DIR")")" +if [[ -z "$built" ]]; then + built="$(built_app_of "$STATE_DIR/releases/$prev")" +fi [[ -n "$built" ]] || die "previous release $prev has no built .app" dst="$APPS_DIR/$(basename "$built")" diff --git a/components/hoxay/update.sh b/components/hoxay/update.sh index 38fe94a6..15564ae1 100755 --- a/components/hoxay/update.sh +++ b/components/hoxay/update.sh @@ -23,7 +23,9 @@ else prev=""; prev_commit="" fi -"$HERE/install.sh" "${1:-}" +# All arguments forward to install.sh: a ref, or a flavor switch such as +# `update.sh --flavor native` (the recorded flavor is kept otherwise). +"$HERE/install.sh" "$@" # Record the superseded release for rollback (only after a successful switch). if [[ -n "$prev" && -f "$CURRENT_FILE" ]]; then diff --git a/components/hoxay/verify.sh b/components/hoxay/verify.sh index bbed5cac..f3ff2015 100755 --- a/components/hoxay/verify.sh +++ b/components/hoxay/verify.sh @@ -56,7 +56,14 @@ if [[ -f "$INSTALLED_FILE" ]]; then recorded_commit="$(sed -n 2p "$INSTALLED_FILE")" [[ "$recorded_commit" == "$commit" ]] || fail "installed commit $recorded_commit != release HEAD $commit" fi -echo "[hoxay] installed: $name @ ${commit:0:12} -> $app (v$version, $bid)" +flavor="$(current_flavor "$STATE_DIR")" +echo "[hoxay] installed: $name @ ${commit:0:12} -> $app (v$version, $bid, $flavor)" + +# The recorded flavor must match a build artifact in the release checkout; +# a mismatch means the release dir was built with the other backend. +if [[ -z "$(built_app_of "$release" "$flavor")" && -n "$(built_app_of "$release")" ]]; then + echo "[hoxay] WARN: flavor=$flavor but release $name only has the other flavor's build output" >&2 +fi # Other managed artifacts may still sit in the apps dir (a pre-rename # herdr-t3.app next to the current hoxay.app). They are the rollback