Skip to content

Add a DaemonProfile for the app's daemon binary and service env (no behavior change) #3346

Closed

Description

@mstomar125

Summary

Add DaemonProfile, the value ADR-082 §3.6 (proposed) defines, and route every edition-dependent choice of which daemon binary the desktop app runs and what extra environment its service registration carries through the process's active profile. Its fields:

  • binary_name: the daemon the app installs, registers, starts, and kills by image name;
  • service_env: extra environment variables in the service registration;
  • product: the product the app expects the daemon to belong to.

The Pro values are built in exactly one function, which the existing NODESPACE_PRO_* build switch selects. Community and Pro builds therefore behave exactly as they do today.

Identity stays out of the profile. The launchd label, socket, UI pid file and incompatible-database marker are not part of it: under ADR-084 decision 2(a) (proposed), both products use core's identity. Those selections stay as they are today, behind is_pro_build(), until #3354 deletes their Pro arms.

Arguments stay out too. ADR-084 §4.2 makes accepting core's launcher arguments the daemon's job, and #3352 exports the argument list.

This is the seam the Pro app fills through AppExtensions::daemon_profile (#3347).

Context

Line numbers are at main af8ddb6. Locate code by symbol, because #3322's library split may move the src-tauri/src modules.

  • The switch. daemon_setup::is_pro_build() (84) returns PRO_SUPABASE_URL.is_some(), where PRO_SUPABASE_URL = option_env!("NODESPACE_PRO_SUPABASE_URL") (78). Only sync's Pro build sets that variable.

  • What moves into the profile here:

    Choice Code today After this issue
    Daemon binary daemon_binary_name_for (88-100), daemon_binary_name (102-105) daemon_profile::active().binary_name
    Windows taskkill image daemon_image_name_for (670-691), used by Windows signal_daemon_to_stop (313-323) and Windows kill_running_daemon (700-720) daemon_profile::active().image_name()
    launchd env write_plist's pro_env block (1173-1188, used at 1208 and 1228) profile.service_env, rendered generically
  • What does not move here:

  • Pro builds must not change. The Pro GUI still builds from core HEAD.

  • Windows code is not compiled on macOS by any PR check. Keep each Windows change to a one-line swap. The reviewer reads every #[cfg(windows)] hunk.

Scope

New file packages/desktop-app/src-tauri/src/daemon_profile.rs

Register it as pub mod daemon_profile; in the module list of src/lib.rs.

/// Which daemon this app installs, registers and starts, and what it expects of it.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DaemonProfile {
    /// Sidecar the launcher installs, registers and starts; no `.exe`.
    pub binary_name: &'static str,
    /// Extra environment in the service registration, after core's own
    /// NODESPACED_SOCKET and NODESPACE_UI_BINARY. Rendered into the macOS
    /// launchd plist only, as today; the systemd unit and the Windows spawn
    /// do not carry it.
    pub service_env: Vec<(String, String)>,
    /// The product the app expects the running daemon to belong to.
    pub product: &'static str,
}
  • pub fn community() -> Self:
    • binary_name: DAEMON_BINARY_NAME (nodespaced);
    • service_env: empty;
    • product: community.
  • #[cfg(any(windows, test))] pub(crate) fn image_name(&self) -> String: returns <binary_name>.exe. Move the real-Windows .exe rationale from daemon_image_name_for's doc onto it, without the issue reference.
  • pub(crate) fn active() -> &'static DaemonProfile: backed by static ACTIVE: OnceLock<DaemonProfile>, and initialised on first read by crate::daemon_setup::profile_for_this_build. Let an app built on core supply its DaemonProfile via AppExtensions::daemon_profile #3347 adds the install path.
  • Docs use generic words only. Core's Pro-boundary ratchet counts the word Pro.

src/daemon_setup.rs

  • Keep the edition block (66 and 72-86): PRO_DAEMON_BINARY_NAME, PRO_SUPABASE_URL, PRO_ANON_KEY and is_pro_build(). The identity functions and update_check still read is_pro_build().
  • Add fn profile_for_build_env(supabase_url: Option<&'static str>, anon_key: Option<&'static str>) -> DaemonProfile to that block:
    • A None URL returns DaemonProfile::community().
    • Some(url) returns today's Pro values:
      • binary_name: PRO_DAEMON_BINARY_NAME;
      • service_env: NODESPACED_PRO_SUPABASE_URL set to url, then NODESPACED_PRO_ANON_KEY set to anon_key.unwrap_or_default(), in that order;
      • product: pro.
    • The URL alone decides, and the key defaults to empty, exactly as today.
    • Move the pro_env comment (1173-1178) onto this function.
  • Add pub(crate) fn profile_for_this_build() -> DaemonProfile, which calls profile_for_build_env(PRO_SUPABASE_URL, PRO_ANON_KEY). These two functions are the only code that picks binary, env or product by edition. Don't give new names a pro_ prefix: Guardrail: stop new Pro code from landing in core #3302's proCommands marker counts pro_* identifiers.
  • Delete daemon_binary_name_for (88-100). daemon_binary_name() now returns daemon_profile::active().binary_name. Its callers (170, 291, 394, 503, 519, 646, 1789) stay unchanged.
  • Delete daemon_image_name_for (670-691). The Windows signal_daemon_to_stop and the Windows kill_running_daemon use daemon_profile::active().image_name() instead.
  • Fix the docs that name the deleted functions:
    • the Windows kill_running_daemon doc (692-699);
    • sidecar_install_path (1054-1060);
    • should_restart_for_log_rotation (1739-1740), which should now say "the same reason DaemonProfile::image_name is a pure method".
  • write_plist (1153-1233):
    • Add a profile: &DaemonProfile parameter.
    • Delete the pro_env block.
    • Render profile.service_env as <key>/<string> pairs after NODESPACE_UI_BINARY, in the same indentation. Pass keys and values through xml_escape.
    • The call site (591-592) passes daemon_profile::active().
  • Kickstart comment (1332-1334): replace "and the Pro pair" with "and whatever the profile's service_env adds".
  • Leave these alone:

Out of scope

Steps

  1. Run the CLAUDE.md startup sequence:
    • git pull on main, then EnterWorktree;
    • bun install, then bun run test for the baseline;
    • bun run gh:comment;
    • bun run gh:assign <N> "@me" (assign at pickup, never at filing);
    • bun run gh:status <N> "In Progress".
  2. Add daemon_profile.rs and its unit tests.
  3. Add profile_for_build_env and profile_for_this_build, then delete the two _for functions.
  4. Switch the readers over, and pass the profile into write_plist.
  5. Update the docs and tests listed here. Code comments must not cite GitHub issue numbers.
  6. Run bun run scripts/check-pro-boundary.ts and paste the printed BASELINES.
  7. Run bun run test:changed and bun run quality:fix, then commit.
  8. Push with git push origin HEAD:<branch> (the push only lints), then run gh pr create --head <branch>.

Acceptance criteria

  • daemon_binary_name_for, daemon_image_name_for and the pro_env block are gone.
  • git grep -nw is_pro_build packages/desktop-app/src-tauri/src lists only these: the definition, launch_agent_label, daemon_socket_relative, ui_pid_relative, grpc_client::resolve_socket_path, incompatible_database::marker_path_in and update_check.
  • A community build writes a byte-identical plist. A test asserts that EnvironmentVariables holds exactly NODESPACED_SOCKET and NODESPACE_UI_BINARY.
  • A test pins every field of profile_for_build_env(Some(..), Some(..)) to today's Pro values. Delete the in-core Pro daemon profile, NODESPACE_PRO_* switch and tauri.pro.conf.json #3354 deletes that test.
  • A service_env value containing <, & and > renders escaped, and the result passes plutil -lint.
  • NODESPACE_PRO_SUPABASE_URL=https://example.invalid NODESPACE_PRO_ANON_KEY=test cargo check -p nodespace-app still compiles.
  • bun run scripts/check-pro-boundary.ts passes, with BASELINES updated in this PR to the printed counts:
    • proCommands falls (the pro_env lines);
    • editionBranching falls (the is_pro parameters);
    • if a marker rises only because Pro values or their pinning test moved, that is a planned relocation: name it in the PR description.

Tests and verification

  • Add daemon_profile unit tests:
    • the values of community();
    • image_name() for community(), and for a profile whose binary_name is custom-daemon.
  • Add profile_for_build_env tests:
    • (None, None) equals community();
    • (Some(url), Some(key)) returns the Pro values;
    • (Some(url), None) gives an empty key.
  • Update existing tests:
    • macos_plist_keepalive_tests (from 2356): pass &DaemonProfile::community(), and add the env-dict and escaping cases.
    • windows_taskkill_image_name_tests (2663-2688): switch to profiles, and delete pro_edition_image_name_matches_pro_binary.
    • sidecar_path_tests::sidecar_install_path_covers_pro_daemon_and_cli_names (2787-2802): rename to ..._covers_any_daemon_and_cli_names, and use custom-daemon.
  • Mutation-test each new test: break the value it pins, and confirm it fails.
  • Commands:
    • bun run test:changed. It takes the machine slot for Rust.
    • For iteration: cargo clippy -p nodespace-app --all-targets -- -D warnings -D clippy::unused-async and cargo test -p nodespace-app --lib -- daemon_. If the build asks for staged resources, run bun run rust:test:app-units once.
    • The Pro-env cargo check from the acceptance criteria.
  • Optional manual check: run bun run tauri dev on a dev Mac before and after the change. ~/Library/LaunchAgents/app.nodespace.daemon.dev.plist must be byte-identical.

Dependencies

Risks and rollback


Plan key: C8.1 (pro-boundary DAG).

🤖 Generated with Claude Code

Activity

  1. self-assigned this
    on Sep 30, 2026
  2. added
    pro-boundary
    on Sep 30, 2026
  3. mstomar125 commented on Sep 30, 2026

    @mstomar125
    ContributorAuthor

    Completed in #3391 (merged). Auto-close did not fire; closing manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

pro-boundary

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions