Skip to content

Unified installer: bundle GUI, CLI, and daemon into a single install - #1455

Merged
malibio merged 3 commits into
mainfrom
worktree-issue-1448-unified-installer
Jun 24, 2026
Merged

malibio merged 3 commits into
mainfrom
worktree-issue-1448-unified-installer

Conversation

@malibio

@malibio malibio commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Closes #1448

…ll, CI job

## Completed in This Session
- [x] nodespaced --edition flag (returns "community" or "pro")
- [x] nodespaced --version flag (early-exit, same pattern)
- [x] [features] pro = [] in daemon Cargo.toml for cfg!(feature = "pro")
- [x] scripts/build-pkg.sh — signs binaries, pkgbuild + productbuild, notarytool
- [x] scripts/pkg-resources/postinstall — Pro guard, /usr/local/bin install, launchd bootstrap
- [x] scripts/pkg-resources/com.nodespace.daemon.plist — LaunchAgent, KeepAlive, /tmp logs
- [x] build:pkg:macos script registered in root package.json
- [x] build-pkg-macos matrix job in release.yml (ARM + Intel, needs Tauri jobs)
- [x] Workflow dispatch options: macos-pkg-arm, macos-pkg-intel added
- [x] notify-failure now includes build-pkg-macos in needs
- [x] Pre-existing lint fixes: HTMLInputElement global + unused log var

## Remaining Work
- [ ] Wait for test:all to complete (running in background)
- [ ] Create PR

## Current State
- Files modified: see above
- Tests status: running (140 frontend + skill + rust)
- Known issues: none; stub binaries created locally for lint pass (not committed)
- Dependencies: Apple Developer credentials in CI secrets (already present)

## Context for Next Session
Full macOS pkg installer pipeline. build-pkg.sh calls pkgbuild+productbuild, signs with
Developer ID Application + Installer certs, notarizes via notarytool. CI job runs after
Tauri builds the .app. Postinstall detects Pro edition before overwriting. The
APPLE_INSTALLER_IDENTITY env var ("Developer ID Installer: Michael Libio (F4M5J7YNLS)")
needs to be added as a GitHub secret (separate from the Application cert).

## Acceptance Criteria Status
From issue #1448:
- [x] nodespaced --edition flag implemented (returns community or pro)
- [x] macOS .pkg build script with signing + notarization
- [x] Community .pkg postinstall script detects existing Pro binary
- [x] Daemon launchd service plist
- [x] release.yml updated to build and upload .pkg artifacts
- [ ] Gatekeeper verification (needs real CI run with certs)
- [ ] Tauri sidecar removal (separate cleanup, after pkg is canonical)
- [ ] Windows .msi (separate issue)
- [ ] Homebrew cask (separate issue)

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

This PR implements the macOS .pkg unified installer, covering the full pipeline: Rust daemon CLI flags, shell-based pkg builder, launchd plist, postinstall script, and CI matrix job. It directly addresses the acceptance criteria for macOS from issue #1448. The implementation is well-structured, includes a sensible postinstall Pro-edition guard, and the signing/notarization flow follows Apple best practice. This is a net improvement and unblocks the macOS release path.

Several issues warrant attention before merge, ranging from a correctness blocker in the CI job to security hygiene and behavioral edge cases.


Findings

Critical Issues

[Critical/Blocker] build-pkg-macos rebuilds everything from scratch instead of consuming upstream artifacts

.github/workflows/release.yml, build-pkg-macos job (lines ~296–422).

The job declares needs: [build-tauri-macos-arm, build-tauri] to enforce ordering, but it does not download the .app bundle artifact produced by those upstream jobs. Instead, it re-runs cargo build, re-runs bunx tauri build, re-downloads the embedding model, and repeats the full certificate import — duplicating roughly 20-30 minutes of compile time per matrix leg. The matrix.tauri_job field is declared but never referenced in any actions/download-artifact step; it is unused dead configuration.

This means: (a) the needs guard is a timing dependency only, not a real data dependency; (b) any signing or build inconsistency between the upstream .app and the freshly-rebuilt one in this job will produce a .pkg whose .app was never uploaded to the release; (c) on a real release run the notarized DMG/dmg artifact and the notarized .pkg contain independently-compiled .app bundles — subtle divergence risk.

Fix: upload the .app bundle in build-tauri-macos-arm / build-tauri, download it in build-pkg-macos, and remove the redundant Tauri build step. At minimum, remove the unused tauri_job matrix variable so it does not mislead future readers.


[Critical/Blocker] set -euo pipefail + || true on the Pro-guard osascript block creates a silent logic hole

scripts/pkg-resources/postinstall, lines 31–47.

/usr/bin/osascript - <<'APPLESCRIPT' || true
...
APPLESCRIPT
        if [[ $? -ne 0 ]]; then

The || true on line 31 suppresses the non-zero exit from osascript (which the AppleScript raises with error number -128 when the user clicks Abort), making $? always 0 at the if check. The abort path is therefore unreachable: the guard never actually blocks the install. This is the primary safety mechanism for the Pro-edition downgrade protection and it is silently broken.

Fix: remove || true, let the non-zero exit propagate naturally under set -e, and wrap the entire osascript block in a subshell if you want to capture the exit code explicitly:

if ! /usr/bin/osascript - <<'APPLESCRIPT'; then
    echo "Installation aborted — Pro installation preserved." >&2
    exit 1
fi

Suggested Improvements

[Improvement] Hardcoded personal Team ID and signing identity in CI YAML

.github/workflows/release.yml, lines 389, 401–402.

APPLE_SIGNING_IDENTITY: "Developer ID Application: Michael Libio (F4M5J7YNLS)"
APPLE_INSTALLER_IDENTITY: "Developer ID Installer: Michael Libio (F4M5J7YNLS)"

The team ID F4M5J7YNLS and the developer's full name appear verbatim in the CI YAML. The existing Tauri jobs in this same file (e.g., lines 104, 262) already follow this pattern, so this PR is consistent with the current approach — but it compounds technical debt. If the signing identity ever rotates (e.g., org account, renewed cert), both places need manual updates. Recommend moving to a GitHub secret (secrets.APPLE_SIGNING_IDENTITY, secrets.APPLE_INSTALLER_IDENTITY) so the value is managed in one place and the YAML is scrubbed of PII. The build-pkg.sh script itself already documents the env vars as user-supplied, which is the right model.


[Improvement] --deep re-signing may invalidate Tauri's existing notarization-ready signature

scripts/build-pkg.sh, lines 96–98.

codesign --force --deep --options runtime --timestamp \
    --sign "${APP_IDENTITY}" \
    "${TAURI_APP_PATH}"

Apple's guidance explicitly discourages --deep for re-signing app bundles because it re-signs nested executables and frameworks out of their designated order, which can produce an invalid signature. The recommended approach is to re-sign inner components first (frameworks, helper tools, dylibs), then the outer .app. In the CI flow here the .app was just built and signed by Tauri, so --deep would clobber that work. Consider either (a) trusting the Tauri-signed bundle as-is (it was already signed with the same Developer ID), or (b) iterating over nested components manually if an additional entitlement is genuinely needed.


[Improvement] Logs routed to /tmp/nodespaced.log — unencrypted, world-readable, and ephemeral

scripts/pkg-resources/com.nodespace.daemon.plist, lines 23–26.

<key>StandardOutPath</key>
<string>/tmp/nodespaced.log</string>
<key>StandardErrorPath</key>
<string>/tmp/nodespaced.log</string>

/tmp is cleared on reboot and is world-readable (1777). For a daemon that handles local AI/knowledge-graph operations, any sensitive diagnostic output (paths, node content excerpts) ends up visible to all local users. Standard practice for LaunchAgent daemons is ~/Library/Logs/<BundleID>/ or /Library/Logs/<BundleID>/ with appropriate ownership. Consider using ~/Library/Logs/com.nodespace/nodespaced.log and creating the directory in the postinstall script with install -d -m 700 -o "${INSTALLING_USER}".


[Improvement] Pro-guard executes the existing binary at its installed path before overwriting — TOCTOU exposure

scripts/pkg-resources/postinstall, line 28.

EXISTING_EDITION="$("${NODESPACED}" --edition 2>/dev/null || echo "unknown")"

The postinstall script runs as root after the payload has already been extracted by the installer. At the point this check runs, the installer has not yet overwritten /usr/local/bin/nodespaced (the payload is staged, not committed), so the existing binary is still in place — this is the intended design. However, executing an arbitrary binary that already exists at that path as root is a mild privilege-escalation vector if that binary has been tampered with. This is low-severity for a local install, but worth noting: the check should be paired with at least a basic signature verification (codesign --verify) before executing, rather than trusting any executable at that path to self-report its edition honestly.


[Improvement] PKG_VERSION extraction is fragile

scripts/build-pkg.sh, line 41.

PKG_VERSION=$(grep '^version' "${REPO_ROOT}/packages/daemon/Cargo.toml" | head -1 | sed 's/.*"\(.*\)".*/\1/')

This grep will also match version = "..." in [dependencies] blocks if any dependency entry appears before [package].version, and the sed pattern silently produces an empty string if the format varies. Using cargo metadata or dasel/tomlq is more robust: cargo metadata --no-deps --manifest-path packages/daemon/Cargo.toml --format-version 1 | jq -r '.packages[0].version'. At minimum, assert that PKG_VERSION is non-empty after extraction and matches a semver pattern before proceeding.


[Improvement] --version flag conflicts with standard Rust crate conventions

packages/daemon/src/main.rs, lines 72–75.

The --version early-exit is implemented with raw std::env::args() string matching. Most CLI tooling that links against clap (if this ever gains it) or produces --help output automatically handles --version. More importantly, this implementation does not handle --version=something or positional cases. This is minor right now since nodespaced is not a user-facing CLI, but for consistency with the --edition flag and future proofing, consider consolidating both flags under a tiny clap parser or at minimum sharing a common arg-check helper function to avoid the duplicated args.iter().any(...) pattern.


Nitpicks

  • Nit: scripts/build-pkg.sh, line 411 — ls target/pkg-output/*.pkg | head -1 inside the CI YAML upload step should use a glob directly: PKG=$(ls -1 target/pkg-output/*.pkg | head -1) is fine but find target/pkg-output -name '*.pkg' -maxdepth 1 | head -1 avoids an ls parse-of-filenames antipattern. In practice there will only be one .pkg so this is cosmetic.

  • Nit: scripts/pkg-resources/postinstall, line 63 — USER is not reliably set inside a macOS pkg postinstall context (it depends on installer invocation method). The logname fallback is correct, but the comment should note that this is intentional because USER may be unset when the package is installed via MDM or installer -pkg.

  • Nit: scripts/build-pkg.sh, lines 143–159 — the distribution XML embeds ${PKG_VERSION} directly in a heredoc. If PKG_VERSION ever contains characters that are significant in XML (e.g., <, &), the XML will be malformed. Version strings from Cargo should be safe semver, but an assertion that the version matches [0-9]+\.[0-9]+\.[0-9]+ before writing XML would close the gap.

  • Nit: packages/daemon/Cargo.toml — the [features] block adds pro = [] but the feature is never gated on any actual code paths except the cfg!(feature = "pro") in edition(). That's intentional for now, but a comment explaining this is the seed for future feature gating would help orient contributors.


Acceptance Criteria Coverage

Criterion Status
macOS .pkg installs app + CLI + daemon Implemented
All binaries signed with Developer ID Application Implemented (build-pkg.sh)
.pkg signed with Developer ID Installer + notarized Implemented (productbuild + notarytool)
Gatekeeper passes (spctl verify step) Implemented
Daemon installed as launchd service, survives GUI quit Implemented (plist + postinstall)
nodespaced --edition flag Implemented
Community .pkg detects existing Pro and warns Implemented but broken (see Critical #2)
release.yml updated to build and upload .pkg Implemented
Windows .msi Out of scope for this PR (deferred, consistent with issue)
Tauri sidecar removed Not done — marked deferred in issue, acceptable
Homebrew cask updated Not done — marked deferred in issue, acceptable

Two blockers prevent merge: the CI job rebuilding unnecessarily instead of consuming upstream artifacts, and the silent Pro-guard logic hole. Both are straightforward fixes.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two blockers identified in the review comment above: (1) build-pkg-macos duplicates the full Tauri build instead of consuming upstream artifacts; (2) the Pro-guard || true makes the abort path unreachable. Both are straightforward fixes — see full findings.

- postinstall: remove `|| true` from osascript call so Abort button
  actually propagates non-zero exit and halts installation
- postinstall: verify nodespaced code signature before executing as root;
  skip Pro guard if signature check fails
- postinstall: create ~/Library/Logs/com.nodespace/ log directory
  before launchctl bootstrap so daemon can write logs on first start
- plist: move StandardOut/ErrorPath from world-readable /tmp to
  ~/Library/Logs/com.nodespace/nodespaced.log (standard macOS location)
- release.yml: upload .app bundle artifact from build-tauri-macos-arm
  and build-tauri (macOS Intel) unconditionally; build-pkg-macos now
  downloads the artifact instead of re-running a full tauri build,
  saving 20-30 min per matrix leg
- release.yml: remove dead `tauri_job` field from build-pkg-macos matrix
- release.yml: move signing identities to job-level env block in
  build-pkg-macos for consistency
- Cargo.toml: expand comment on `pro` feature explaining its effect

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Review feedback addressed (commit a01dd20)

Blockers fixed

BLOCKER 1 — || true silencing the Abort button (scripts/pkg-resources/postinstall)
Removed || true from the osascript heredoc call. The non-zero exit from AppleScript error -128 now propagates naturally to the $? -ne 0 check that follows. Added an explicit comment explaining why || true must not be used here.

BLOCKER 2 — build-pkg-macos rebuilding from scratch (.github/workflows/release.yml)

  • Added an unconditional Upload .app bundle for pkg job step to build-tauri-macos-arm, uploading target/aarch64-apple-darwin/release/bundle/macos/ as artifact app-bundle-aarch64-apple-darwin.
  • Added a conditional (macOS Intel only) Upload .app bundle for pkg job step to build-tauri, uploading target/x86_64-apple-darwin/release/bundle/macos/ as artifact app-bundle-x86_64-apple-darwin.
  • In build-pkg-macos: removed the full Tauri build step, Bun install, SvelteKit sync, model download, and sidecar copy. Replaced with actions/download-artifact@v4 pulling app-bundle-${{ matrix.triple }} into the exact path build-pkg.sh expects (target/${{ matrix.triple }}/release/bundle/macos/). The binary build step remains (it builds the /usr/local/bin/ binaries, which are distinct from the .app-embedded sidecars).
  • Removed the dead tauri_job field from the matrix.

Improvements applied

IMPROVEMENT 1 — Signing identities in env block (.github/workflows/release.yml)
Moved APPLE_SIGNING_IDENTITY and APPLE_INSTALLER_IDENTITY to the job-level env: block in build-pkg-macos, keeping them consistent with the pattern used in the upstream Tauri jobs.

IMPROVEMENT 2 — LaunchAgent logs to user log directory (scripts/pkg-resources/com.nodespace.daemon.plist, postinstall)
Changed StandardOutPath and StandardErrorPath from /tmp/nodespaced.log to ~/Library/Logs/com.nodespace/nodespaced.log. Added mkdir -p "${INSTALLING_USER_HOME}/Library/Logs/com.nodespace" to postinstall (runs before launchctl bootstrap) with a guard on non-root user and a valid home directory.

IMPROVEMENT 3 — Codesign verification before executing as root (scripts/pkg-resources/postinstall)
Added codesign --verify --quiet check before executing the existing nodespaced binary with --edition. If verification fails, sets EXISTING_EDITION="unknown" and skips the Pro guard with a warning to stderr.

Nitpick — pro = [] feature comment (packages/daemon/Cargo.toml)
Expanded the comment to explain what the feature does and what behavior changes when it is absent.

Skipped (with rationale)

  • codesign --deep per-component signing — existing Tauri action already signs the .app; --deep is a belt-and-suspenders step; per-component enumeration is overkill without a confirmed Gatekeeper failure.
  • PKG_VERSION extraction via grep/sed — works reliably for this single-binary Cargo.toml; cargo metadata | jq adds a dep not guaranteed on CI runners.
  • Distribution XML version escaping — version comes from semver format, never contains XML-special characters.
  • ls ... | head -1 in upload — cosmetic, no functional impact.

@malibio

malibio commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Re-Review: commit a01dd20

Both blockers from the prior review are fixed. One new correctness issue was introduced by the fix.


Blocker Verification

BLOCKER 1 — || true silencing the Abort button: Fixed correctly. The || true is removed from the osascript call in scripts/pkg-resources/postinstall. An explanatory comment was added making the intent explicit. The $? -ne 0 check now has a reachable abort path.

BLOCKER 2 — build-pkg-macos rebuilding from scratch: Fixed correctly. build-tauri-macos-arm now uploads app-bundle-aarch64-apple-darwin unconditionally. build-tauri uploads app-bundle-x86_64-apple-darwin conditionally on macOS Intel. build-pkg-macos downloads the pre-built artifact instead of re-running Tauri, Bun setup, SvelteKit sync, and model download. The dead tauri_job matrix field is removed. The binary build step is correctly retained (those binaries go to /usr/local/bin/ and are distinct from the .app-embedded sidecar).


New Issue Introduced by This Commit

[Critical/Blocker] upload-artifact@v7 / download-artifact@v4 version mismatch

.github/workflows/release.yml, lines 123, 292 (upload) and line 363 (download).

All artifact upload steps in this file, including the two new ones added in this commit, use actions/upload-artifact@v7. The new download step introduced in build-pkg-macos uses actions/download-artifact@v4. GitHub's artifact storage backend changed in v4 — artifacts uploaded with v4+ are not compatible with v3 downloads, and the relationship between a hypothetical v7 upload and a v4 download is undefined. In practice, GitHub Actions requires the upload and download action major versions to match for artifact retrieval to succeed. If the CI environment interprets these as mismatched, build-pkg-macos will fail at the download step with an artifact-not-found error, producing no .pkg despite the upstream jobs completing successfully.

Fix: change actions/download-artifact@v4 to actions/download-artifact@v7 on line 363 to match the upload version used throughout this file.


Improvements Applied (confirmed)

  • codesign --verify guard before executing existing binary as root — correct approach, skips Pro guard safely on verification failure.
  • Log directory created in postinstall before launchctl bootstrap — ordering is correct; the ~ in the plist is valid for LaunchAgent (user domain) plists, and the comment added is accurate.
  • Signing identities moved to job-level env: block — consistent with upstream Tauri jobs.
  • pro = [] feature comment expanded — clear and useful.

Summary

The two original blockers are properly resolved. The artifact version mismatch (@v7 upload / @v4 download) is a new blocker that will cause build-pkg-macos to fail silently at the download step in CI. One-line fix: update actions/download-artifact@v4 to actions/download-artifact@v7 on the download step in build-pkg-macos.

…nly pkg job

- Remove macos-pkg-intel matrix leg — ARM-only .pkg (Intel Macs not supported)
- Remove Intel .app artifact upload from build-tauri matrix job
- Collapse build-pkg-macos from a matrix to a single ARM job
- Fix actions/download-artifact@v4 → @v7 (must match upload @v7 across workflow)
- TRIPLE is now a job-level env var (aarch64-apple-darwin), not a matrix param
- workflow_dispatch option renamed macos-pkg-arm + macos-pkg-intel → macos-pkg

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit e228605 into main Jun 24, 2026
@malibio
malibio deleted the worktree-issue-1448-unified-installer branch June 24, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unified installer: bundle GUI, CLI, and daemon into a single install

1 participant