From d5948b1554c31971a39dc8edc49979ed7634fb26 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 11 Oct 2026 10:04:35 +0200 Subject: [PATCH] Tell agents to react to events instead of polling Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 4 ++++ agents/skills/shell-dev.md | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index 72aa975fe9d3..9ebefa7b9c12 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -113,6 +113,10 @@ Commands installed by Omarchy's default package set are runtime invariants. Invo Exceptions are allowed for migration and package-helper scripts where the helper may not be available yet, where the helper itself is being implemented, or where direct package-manager behavior is required. +# Background Work + +- Long-running code (the shell, daemons, watchers) reacts to events instead of polling with a timer. Polling is the last resort, for state with no change signal; [`agents/skills/shell-dev.md`](agents/skills/shell-dev.md) lists the event sources and the push-refresh pattern. + # Menu - The menu definition lives in `default/omarchy/omarchy-menu.jsonc`; diff --git a/agents/skills/shell-dev.md b/agents/skills/shell-dev.md index a1ee0da3aeb1..05faab5ea4c8 100644 --- a/agents/skills/shell-dev.md +++ b/agents/skills/shell-dev.md @@ -38,6 +38,17 @@ Run `omarchy-restart-shell` after making changes to QML files. bar widgets register one target each — `omarchy.indicators`, `omarchy.system-update`, `omarchy.clock`. There is no `bar` target. +## Keeping state current without polling + +The shell runs all day on battery, and a widget is built once per monitor, so a `Timer` that starts a `Process` costs that process times the number of monitors, every tick, forever. Don't poll for state that only changes through known events. Pick the first of these that fits: + +- A native Quickshell service that signals on change: `UPower` and `PowerProfiles` (`Quickshell.Services.UPower`), `Hyprland` and each workspace's `lastIpcObject`, `Pipewire`, `Mpris`, `SystemTray`, `Notifications`. +- An event stream the shell already runs, such as the Hyprland IPC events or the long-running `pactl subscribe` in `Commons/UntypedInput.qml`. Extend it rather than starting a second one. +- A file watch: `FileView` with `watchChanges`, or the directory watch in `plugins/bar/Bar.qml`, when the state lives in a file the user can read. +- A push from the command that changes the state. If only Omarchy commands change it, have them call `omarchy-shell -q refresh` after the change, the way `omarchy-reminder` and `omarchy-sudo-passwordless` do. When the change happens later, without a command running (an expiry, say), schedule the refresh with a transient `systemd-run --user --on-active=…` timer. A root-owned timer cannot reach the user's shell. + +Polling is the last resort, kept for state with no change signal at all (a remote API, say). Then gate the timer on the panel being open where you can, pick the longest interval the UI can tolerate, and put the poll in one shared service rather than in a per-monitor widget. Never poll a privileged probe: every `sudo -n` can write to the auth log. + ## Editing widget files with glyphs Widget files in `shell/plugins/bar/widgets/` contain Nerd Font glyphs as raw