Skip to content

Nightshift scheduling: quick launch, manual schedule, recurring #1

@kofort9

Description

@kofort9

Summary

Add scheduling capabilities to nightshift so runs can be triggered easily without manual tmux setup.

Three Tiers

Tier 1: Quick Launch (enhance existing zsh alias)

Add --at and --in flags to the nightshift start alias:

nightshift start                  # Start immediately (existing)
nightshift start --at 2:00        # Start at 2:00 AM tonight
nightshift start --in 1h          # Start in 1 hour
nightshift start --at 2:00 --dry-run  # Preview what would run at 2 AM

Implementation: Shell arithmetic → sleep N in a named tmux session. Same as what we do manually today, just wrapped in the alias.

Pros: Zero dependencies, works now
Cons: Dies if laptop sleeps or terminal closes

Tier 2: Manual Schedule (survives terminal close)

nightshift schedule 2:00          # One-shot: run at 2 AM tonight
nightshift schedule --cancel       # Cancel scheduled run
nightshift schedule --status       # Show next scheduled run

Implementation: Write a launchd one-shot plist to ~/Library/LaunchAgents/com.autodev.nightshift-oneshot.plist with StartCalendarInterval. Load with launchctl.

Pros: Survives terminal close, proper macOS integration
Cons: Slightly more complex, plist XML

Tier 3: Recurring Schedule

nightshift cron 2:00              # Run every night at 2 AM
nightshift cron --weekdays 2:00   # Mon-Fri only
nightshift cron --disable          # Pause recurring runs
nightshift cron --enable           # Resume
nightshift cron --status           # Show schedule + last run

Implementation: Persistent launchd plist at ~/Library/LaunchAgents/com.autodev.nightshift.plist. Runs a wrapper script that:

  1. Checks if nightshift is already running (lock file)
  2. Checks if there are nightshift-labeled issues to process
  3. If yes, runs npx tsx nightshift/src/index.ts run
  4. Logs to ~/.auto-dev/runs/

Pros: Fully autonomous, survives reboots
Cons: Need to handle edge cases (laptop sleep, network down, no issues)

Design Decisions

  • launchd over cron: macOS-native, handles sleep/wake properly, can set env vars
  • All three tiers coexist: Quick launch for "run this now", schedule for "run tonight", cron for "run every night"
  • Single tmux session name: All tiers use nightshift session — prevents parallel runs
  • Lock file: ~/.auto-dev/nightshift.lock prevents overlapping runs across tiers

Files

File Purpose
nightshift/nightshift.zsh Add --at, --in to start; add schedule and cron subcommands
nightshift/scripts/nightshift-launcher.sh Wrapper for launchd (env setup, lock check, logging)
nightshift/templates/com.autodev.nightshift.plist Template for launchd recurring plist

Verification

  1. nightshift start --at 2:00 → tmux session created with correct sleep
  2. nightshift schedule 2:00 → plist loaded, launchctl list | grep autodev
  3. nightshift cron 2:00 → plist loaded, persists after reboot
  4. Parallel run prevention: start nightshift, try starting again → blocked by lock

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions