Skip to content

feat(install): schema install --daemon templates (ADR-0027 post-refactor)#11

Merged
farchanjo merged 1 commit intomainfrom
feat/adr-0027-daemon-templates
Apr 27, 2026
Merged

feat(install): schema install --daemon templates (ADR-0027 post-refactor)#11
farchanjo merged 1 commit intomainfrom
feat/adr-0027-daemon-templates

Conversation

@farchanjo
Copy link
Copy Markdown
Owner

Summary

Closes the ADR-0027 cutover step 5 gap. New launchd / systemd templates that invoke schema daemon directly, plus matching schema install --daemon / schema uninstall --daemon verbs.

  • src/cli/templates/launchd-daemon.plist.template — macOS LaunchAgent with Label = com.farchanjo.schema.daemon, SoftResourceLimits.NumberOfFiles = 10240 (the knob the ADR-0026-era per-project daemons needed for fd exhaustion).
  • src/cli/templates/systemd-daemon.service.template — Linux user unit with LimitNOFILE = 10240.
  • DaemonInstallInputs + render_macos_daemon_plist / render_linux_daemon_unit + DAEMON_LAUNCHD_LABEL / DAEMON_SYSTEMD_UNIT_NAME.
  • --service / --daemon mutually exclusive on install / uninstall via clap conflicts_with.
  • Operator cutover step 5 becomes mechanical: schema install --daemon + launchctl bootstrap.

Test plan

  • cargo clippy --all-features --all-targets --workspace -- -D warnings exits 0
  • cargo fmt --all -- --check clean
  • cargo test --all-features — 97 passed (92 unit + 5 integration; +3 daemon-template render tests)
  • schema install --help shows both --service and --daemon; conflicting flags rejected
  • Per-project ADR-0020 path (--service --config <path>) untouched in observable behaviour
  • No new dependency, no unsafe
  • ADR-0027 Evidence appended (post-refactor templates entry)
  • CI lint job green
  • Operator runs canary + cutover when ready (runbook "Migration to ADR-0027" 8-step sequence)

🤖 Generated with Claude Code

…stemd templates (ADR-0027 post-refactor)

ADR-0027's runbook cutover step 5 left the workstation-level unit as
"author by hand" until templates landed. This commit closes that gap with
two new templates and the matching `schema install --daemon` /
`schema uninstall --daemon` verbs. Per-project `--service` / `--config`
flow (ADR-0020) is preserved; the two flags are mutually exclusive via
clap `conflicts_with`.

Templates:

* `src/cli/templates/launchd-daemon.plist.template` — macOS LaunchAgent.
  `Label = com.farchanjo.schema.daemon`,
  `ProgramArguments = [{binary_path}, "daemon"]`, no `--config` flag, no
  `{project_id}` slot. Carries `SoftResourceLimits.NumberOfFiles = 10240`
  — the knob the four ADR-0026-era per-project daemons needed to dodge
  kqueue fd exhaustion across N projects.
* `src/cli/templates/systemd-daemon.service.template` — Linux user unit.
  `ExecStart = {binary_path} daemon`, `LimitNOFILE = 10240` for the same
  reason.

Code:

* `src/cli/install.rs` — new `DaemonInstallInputs` (no config_path /
  project_id fields), `render_macos_daemon_plist` /
  `render_linux_daemon_unit` helpers, public constants
  `DAEMON_LAUNCHD_LABEL` / `DAEMON_SYSTEMD_UNIT_NAME`. Three new unit
  tests cover slot substitution + label constants + absence of `--config`
  in the daemon variant.
* `src/main.rs` — `--daemon` flag added to `install` / `uninstall`
  subcommands; new `--nice <N>` option (default 5, only consumed by the
  daemon variant — per-project mode reads `[embedding].nice` from
  schema.toml). Helpers `daemon_unit_path`, `write_daemon_unit_file`,
  `daemon_unit_label`, `print_load_hint`, `print_unload_hint`,
  `run_install_dispatch`, `run_uninstall_dispatch`,
  `run_forget_dispatch` keep each `run_*` fn under the 30-line cognitive
  budget after the install/uninstall flag matrix grew.

After this commit, ADR-0027 cutover step 5 is mechanical:

    schema install --daemon
    launchctl bootstrap gui/$(id -u) \
      ~/Library/LaunchAgents/com.farchanjo.schema.daemon.plist

ADR-0027 Evidence appended for the post-refactor templates entry.

Strict-lint gate: cargo clippy --all-features --all-targets --workspace
-- -D warnings exits 0. cargo fmt --all -- --check clean. cargo test
--all-features 97 passed (92 unit + 5 integration; +3 from the new
daemon-template render tests).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@farchanjo farchanjo merged commit e53d5b7 into main Apr 27, 2026
1 check passed
@farchanjo farchanjo deleted the feat/adr-0027-daemon-templates branch April 27, 2026 03:45
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.

1 participant