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 }; }