Skip to content

Phase 2-3: native menu-bar app (sidepulse-bar) - #2

Merged
ckorhonen merged 8 commits into
mainfrom
phase-2
Nov 7, 2026
Merged

ckorhonen merged 8 commits into
mainfrom
phase-2

Conversation

@ckorhonen

Copy link
Copy Markdown
Owner

What changed

  • Workspace split: sidepulse-core (shared logic), sidepulse-hook, new sidepulse-bar (AppKit menu-bar app).
  • monitor.rs: port of LiveAgentMonitor with bounded state (6 h / 256 statuses) and debounced compact latest.json writes.
  • devices/battery/lid/power: native IOKit/IOPM; no ioreg, caffeinate or touch child processes.
  • sidepulse-bar: status item, Agents/Devices/Keep-awake menu, LED worker thread, event socket, shared settings.json.
  • scripts/install-bar.sh swaps the LaunchAgent from the Python app (with --revert).

Why

Python app measured at 509 MB footprint, 3–21% CPU and ~22k idle wakeups per sample; Rust app: 29 MB, ~0% CPU.

Validation

  • cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace (85 tests)
  • Live side-by-side run against temp state and a fake device: startup replay of 412 real hook records, working/ask/error LED programs byte-identical to Python, compact latest.json (6.9 KB), menu structure verified through Accessibility, clean SIGTERM shutdown
  • Found and fixed: macOS returns EINVAL from setsockopt on a peer-closed socket, which would have dropped every hook event
  • Switch-over on a real machine (scripts/install-bar.sh)

Risks or follow-up

Not ported: Setup/Settings windows, Screen Bar, composited session icons, brightness slider (25/50/75/100% submenu instead). Next: replace the remaining polling timers with notifications.

🤖 Generated with Claude Code

ckorhonen and others added 8 commits November 7, 2026 09:41
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… native IOKit/IOPM

Adds the LiveMonitor port (bounded latest.json, debounced compact writes),
native LED/battery/lid/power modules (no ioreg/caffeinate/touch children),
and the AppKit status item, menu, LED worker and event socket server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…evert)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er on newer toolchains)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… timers

- Lid: IOPMrootDomain general-interest notification
  (kIOPMMessageClamshellStateChange = 0xE0034100) instead of a 1 s poll;
  5 s fallback poll only if registration fails on a machine with a lid.
- Battery: IOPSNotificationCreateRunLoopSource refreshes on power-source
  changes instead of the 15 s refresh.
- Volumes: NSWorkspace mount/unmount/rename observers trigger a rescan
  (plus one 2 s follow-up) instead of a 2 s poll; SIDEPULSE_VOLUMES keeps
  a 5 s rescan since fake mounts post no notifications.
- Time-based transitions: one one-shot NSTimer armed for the next
  deadline (LiveMonitor::next_transition_at, KeepAwake::grace_deadline),
  with a 300 s safety refresh (60 s tolerance).
- latest.json: debounced one-shot flush 2 s after the first dirty event,
  plus on shutdown.
- SIGTERM/SIGINT: dispatch signal sources on the main queue instead of a
  1 s flag check.
- LED worker sleeps exactly until the next keepalive (KeepaliveToucher::
  next_due) or charging-pulse rewrite instead of a fixed 20 s tick.
- Menu is a single NSMenu refilled in place; menuNeedsUpdate: refreshes
  it so session ages stay current without a timer.
- SIDEPULSE_DRY_RUN=1 logs LED writes and keepalive touches instead of
  doing them.

Idle interrupt wakeups: 1.08/s -> 0.27/s (SIDEPULSE_VOLUMES) and 0.13/s
(real /Volumes, dry run); CPU 21 -> 2.5-5.7 ms/min; footprint unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dline timers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hd EIO race)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ckorhonen
ckorhonen merged commit 0bb2770 into main Nov 7, 2026
2 of 3 checks passed
@ckorhonen
ckorhonen deleted the phase-2 branch November 7, 2026 16:12
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