Files
buzz/desktop/scripts/package-macos-dmg.sh
Logan Johnson 4a9de1a3a1 feat(desktop): add isolated named demo builds (#6407)
🤖 I’m Larry, updating this description on Logan’s behalf.

## Summary

Build named macOS demo apps without Finder automation or collisions with
installed Buzz. `just desktop-demo-build "PR 6407 Demo"` produces a
matching app and DMG, with a fresh build identity even when the same
display name is reused.

- The headless DMG packager uses `hdiutil`; optional Finder styling is
bounded. The existing production release recipe is unchanged.
- Each demo has independent app data, keychain, nest, CLI name,
voice-model storage, repository discovery, and agent OAuth/config
storage. Reset preserves production and sibling-demo state, and retains
retry intent when credential removal or root resolution fails.
- Native links accept only the active build’s registered scheme, then
translate validated entity links into the frontend’s canonical `buzz:`
format.
- The recipe builds all six executable sidecars. Display names are
capped at 31 ASCII characters so the generated identity fits Rust’s
build-time limit.

**Open delivery requirement:** downloaded demos must run without a
Gatekeeper security override. The current recipe is ad-hoc signed and
unnotarized; it does **not** satisfy this requirement. Trusted
branch-demo signing/distribution remains blocked on establishing an
approved signing path. This PR is not being presented as complete
download-and-run delivery.

### Related issue

N/A — reported in the Buzz DMG-packaging workstream.

### Testing

At `11ce21ff97cb387ad676e7caa65b00964097d0bb`, macOS Blox passed the
Tauri workspace suite and compiled-flags gate (including the full
named-demo state; each library pass: 2,992 passed, 19 ignored), Tauri
all-target clippy, the full `buzz-agent` package suite, and frontend
lint/typecheck plus 5,733 tests. Regression coverage includes
cold-start/running entity-link handling, wrong-build rejection, OAuth
deletion failure and retry, unresolved credential roots, and
production/sibling preservation.

At the same head, an extra full named-demo/mesh-enabled run had 3,092
passing tests and one failure: a pre-existing shared-compute `auto`
versus `mesh` expectation, also reproduced on the old published head
`a77b25eca`. The ordinary and demo-state matrix above passes; this is
not an all-features-green claim. Live macOS Launch Services delivery
remains unverified.

GitHub CI completed with 30 successful checks and 9 skipped. The
exact-range security review has not run; its authorization notice
remains open. CI success does not establish trusted signing or
downloaded-app launch.

Earlier demo artifacts established matching app/DMG names, side-by-side
launch, and six non-empty executable arm64 sidecars. These screenshots
show an earlier artifact, not a new build of the final repair commit.
Signature-integrity checks are not Gatekeeper/notarization evidence.

<img width="1032" height="548" alt="Buzz PR 6407 Demo disk image
containing the matching app"
src="https://github.com/user-attachments/assets/bca0277e-db03-4308-b280-fcad55e6d601"
/>

<img width="1186" height="821" alt="Buzz PR 6407 Demo running alongside
other Buzz installations"
src="https://github.com/user-attachments/assets/b4bf4ae5-c341-4e15-8090-9d2ea7c623b6"
/>

---------

Signed-off-by: Logan Johnson <loganj@squareup.com>
Signed-off-by: Larry <8cf5a83f590ec0955b11647d1c88f796a98e088c30a492c58e0e46c3026ae7a4@buzz.block.builderlab.xyz>
Co-authored-by: Other Brother Darryl <cee32d92756729ee0c097c5661b879c6199931cd25315c8cf398dcbf0f155cf1@buzz.block.builderlab.xyz>
Co-authored-by: Larry <loganj+sandbox-larry@squareup.com>
Co-authored-by: Larry <8cf5a83f590ec0955b11647d1c88f796a98e088c30a492c58e0e46c3026ae7a4@buzz.block.builderlab.xyz>
2026-08-31 21:14:19 -04:00

129 lines
3.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build a drag-to-Applications DMG without requiring a GUI login session.
# Finder styling is optional; the disk image itself is always authoritative.
set -euo pipefail
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <Buzz.app> <output.dmg>" >&2
exit 2
fi
app_path="$1"
out_dmg="$2"
app_name="$(basename "$app_path")"
volume_name="${VOL_NAME:-Buzz}"
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
background="$script_dir/../src-tauri/icons/dmg-background.png"
work_dir="$(mktemp -d "${TMPDIR:-/tmp}/buzz-dmg.XXXXXX")"
source_dir="$work_dir/source"
rw_dmg="$work_dir/read-write.dmg"
mount_point="$work_dir/mount"
applescript="$work_dir/style.applescript"
device=""
finish() {
local status="$?"
trap - EXIT
if [[ -n "$device" ]]; then
hdiutil detach "$device" >/dev/null 2>&1 || true
hdiutil detach -force "$device" >/dev/null 2>&1 || true
fi
rm -rf "$work_dir"
exit "$status"
}
trap finish EXIT
[[ -d "$app_path" ]] || { echo "App bundle not found: $app_path" >&2; exit 1; }
[[ -f "$background" ]] || { echo "DMG background not found: $background" >&2; exit 1; }
mkdir -p "$(dirname "$out_dmg")" "$source_dir/.background" "$mount_point"
ditto "$app_path" "$source_dir/$app_name"
ln -s /Applications "$source_dir/Applications"
cp "$background" "$source_dir/.background/background.png"
rm -f "$rw_dmg" "$out_dmg"
hdiutil create -volname "$volume_name" -srcfolder "$source_dir" \
-format UDRW -ov "$rw_dmg" >/dev/null
attach_output="$(hdiutil attach -readwrite -noverify -noautoopen -nobrowse \
-mountpoint "$mount_point" "$rw_dmg")"
device="$(printf '%s\n' "$attach_output" | awk '/^\/dev\// { print $1; exit }')"
[[ -n "$device" ]] || { echo "Failed to attach writable DMG" >&2; exit 1; }
detach() {
local attempt
for attempt in 1 2 3 4 5; do
if hdiutil detach "$device" >/dev/null 2>&1; then
device=""
return 0
fi
sleep 1
done
hdiutil detach -force "$device" >/dev/null
device=""
}
if command -v SetFile >/dev/null 2>&1; then
SetFile -a V "$mount_point/.background" || true
icon="$mount_point/$app_name/Contents/Resources/icon.icns"
if [[ -f "$icon" ]]; then
cp "$icon" "$mount_point/.VolumeIcon.icns" || true
SetFile -c icnC "$mount_point/.VolumeIcon.icns" || true
SetFile -a C "$mount_point" || true
fi
fi
cat >"$applescript" <<'APPLESCRIPT'
on run argv
set mountPath to item 1 of argv
set appName to item 2 of argv
tell application "Finder"
set rootFolder to POSIX file mountPath as alias
open rootFolder
set imageWindow to container window of rootFolder
set current view of imageWindow to icon view
set toolbar visible of imageWindow to false
set statusbar visible of imageWindow to false
set bounds of imageWindow to {200, 120, 860, 652}
set viewOptions to icon view options of imageWindow
set arrangement of viewOptions to not arranged
set icon size of viewOptions to 128
set text size of viewOptions to 14
set background picture of viewOptions to file ".background:background.png" of rootFolder
set position of item appName of rootFolder to {191, 330}
set position of item "Applications" of rootFolder to {469, 330}
set extension hidden of item appName of rootFolder to true
delay 1
close imageWindow
end tell
end run
APPLESCRIPT
style_with_finder() {
local child elapsed=0
/usr/bin/osascript "$applescript" "$mount_point" "$app_name" &
child=$!
while kill -0 "$child" 2>/dev/null; do
if (( elapsed >= 100 )); then
echo "Finder styling timed out; continuing without it" >&2
kill "$child" 2>/dev/null || true
wait "$child" 2>/dev/null || true
return 124
fi
sleep 0.1
elapsed=$((elapsed + 1))
done
wait "$child"
}
if ! style_with_finder; then
echo "Finder styling unavailable; continuing without it" >&2
fi
sync
detach
hdiutil convert "$rw_dmg" -format UDZO -imagekey zlib-level=9 \
-o "$out_dmg" >/dev/null
printf 'DMG ready: %s\n' "$out_dmg"