From c06adec7d8fd39b0d4b0c78c4191c5ebf4c749bf Mon Sep 17 00:00:00 2001 From: John Ogle Date: Fri, 16 Jan 2026 09:23:25 -0800 Subject: [PATCH] feat(dev): add systemd timer for beads gate check Add periodic timer (every 5 min) that runs `bd gate check --type=timer` across all beads workspaces with running daemons. This enables self-scheduling molecules - workflows that can set timer gates to schedule their own future execution (e.g., watchers that scan Slack every 8 hours). The timer: - Only runs on Linux (uses systemd user services) - Discovers workspaces via `bd daemon list` - Silently skips if no beads daemons are running Related: nixos-configs-1rk.2 (Time beads scheduling mechanism) Co-Authored-By: Claude Opus 4.5 --- home/roles/development/default.nix | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/home/roles/development/default.nix b/home/roles/development/default.nix index bdfa682..dc7cb1f 100644 --- a/home/roles/development/default.nix +++ b/home/roles/development/default.nix @@ -146,6 +146,46 @@ in $DRY_RUN_CMD echo "Claude Code beads integration configured (hooks installed)" ''; + # Beads timer gate checker (Linux only - uses systemd) + # Runs every 5 minutes to auto-resolve expired timer gates across all beads projects + # This enables self-scheduling molecules (watchers, patrols, etc.) + systemd.user.services.beads-gate-check = lib.mkIf pkgs.stdenv.isLinux { + Unit = { + Description = "Check and resolve expired beads timer gates"; + }; + Service = { + Type = "oneshot"; + # Check gates in all workspaces that have running daemons + ExecStart = pkgs.writeShellScript "beads-gate-check-all" '' + # Get list of workspaces from daemon registry + workspaces=$(${beadsPackage}/bin/bd daemon list --json 2>/dev/null | ${pkgs.jq}/bin/jq -r '.[].workspace // empty' 2>/dev/null) + + if [ -z "$workspaces" ]; then + exit 0 # No beads workspaces, nothing to do + fi + + for ws in $workspaces; do + if [ -d "$ws" ]; then + cd "$ws" && ${beadsPackage}/bin/bd gate check --type=timer --quiet 2>/dev/null || true + fi + done + ''; + }; + }; + + systemd.user.timers.beads-gate-check = lib.mkIf pkgs.stdenv.isLinux { + Unit = { + Description = "Periodic beads timer gate check"; + }; + Timer = { + OnBootSec = "5min"; + OnUnitActiveSec = "5min"; + }; + Install = { + WantedBy = [ "timers.target" ]; + }; + }; + # Note: modules must be imported at top-level home config }; }