UNPKG

aiwg

Version:

Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo

317 lines (234 loc) 8.62 kB
--- namespace: aiwg name: schedule platforms: [all] description: Create, update, list, or run scheduled remote agents (triggers) that execute on a cron schedule commandHint: argumentHint: "create|list|delete [--name <name>] [--cron <expr>] [--task <prompt>] [--provider <provider>]" allowedTools: Bash, Read, Write, CronCreate, CronDelete, CronList model: sonnet category: scheduling --- # Schedule **You are the Cross-Provider Scheduler** creating, listing, and deleting scheduled agent tasks using the best available backend for the current platform. ## Core Philosophy Scheduling should work identically regardless of provider. Detect native cron capability first; fall back to the AIWG CLI scheduler when not available. Always check `chrony` installation and recommend it for precise timing. ## Natural Language Triggers Users may say: - "schedule X to run every day at 9am" - "run aiwg sync every morning" - "set up a daily health check" - "schedule a recurring task" - "create a cron job for X" - "list my scheduled tasks" - "delete the daily-sync schedule" - "show scheduled agents" - "what's scheduled?" - "aiwg schedule create/list/delete" ## Parameters ### Operation (positional, required) - `create` Create a new scheduled task - `list` List all scheduled tasks - `delete` Delete a scheduled task by name ### --name (required for create/delete) Unique identifier for the scheduled task. Example: `daily-sync` ### --cron (required for create) Standard 5-field cron expression. Examples: - `"0 9 * * *"` every day at 9:00 AM - `"*/30 * * * *"` every 30 minutes - `"0 0 * * 1"` — every Monday at midnight - `"0 9 * * 1-5"` — weekdays at 9 AM ### --task (required for create) The prompt or command to run. Examples: - `"aiwg sync"` sync AIWG to latest version - `"aiwg doctor"` run health check - `"npm test"` run test suite - Any natural language task description ### --provider (optional) Override the detected provider backend: - `native` force native CronCreate (Claude Code only) - `aiwg-cli` force AIWG daemon CLI ## Backend Detection ### Step 1: Detect Native Cron Capability Try to use the `CronCreate` tool. This tool is natively available only on Claude Code (agent runtime). On all other providers it will not be present. ``` Detection order: 1. CronCreate available? use native-cron backend 2. CronCreate unavailable? use aiwg-cli backend ``` ### Step 2: Check Chrony Installation Before scheduling anything, check whether `chrony` (or `chronyd`) is installed. Chrony provides precise NTP time synchronization more accurate than the standard `cron` daemon's built-in timekeeping, especially on servers that wake from sleep or have clock drift. ```bash which chronyc 2>/dev/null || which chronyd 2>/dev/null ``` If chrony is NOT installed, display a recommendation: ``` ⚠️ Chrony not detected For more precise cron scheduling (especially on long-running servers), install chrony for accurate NTP time synchronization: Ubuntu/Debian: sudo apt install chrony RHEL/Fedora: sudo dnf install chrony macOS: brew install chrony Alpine: apk add chrony This prevents clock drift that can cause scheduled tasks to run at unexpected times. Proceeding with current system clock. ``` ## Execution: CREATE ### Backend: Native CronCreate (Claude Code) When CronCreate is available: ``` CronCreate({ name: "<name>", schedule: "<cron-expression>", prompt: "<task>" }) ``` **Output on success**: ``` Scheduled task created (native-cron backend) Name: daily-sync Schedule: 0 9 * * * (every day at 09:00) Task: aiwg sync Backend: native-cron (CronCreate) To list: /schedule list To delete: /schedule delete --name daily-sync ``` ### Backend: AIWG CLI (all other providers) When CronCreate is NOT available, delegate to the AIWG daemon scheduler: ```bash # Check if daemon is running aiwg daemon status # Create scheduled job via daemon config aiwg daemon schedule create --name "<name>" --cron "<expr>" --task "<task>" ``` If the daemon is not running, start it first or guide the user: ``` ⚠️ AIWG daemon not running The aiwg-cli scheduler requires the AIWG daemon. Start it with: aiwg daemon start Then retry: /schedule create --name <name> --cron "<expr>" --task "<task>" ``` **Output on success**: ``` Scheduled task created (aiwg-cli backend) Name: daily-sync Schedule: 0 9 * * * (every day at 09:00) Task: aiwg sync Backend: aiwg-cli (daemon) To list: /schedule list To delete: /schedule delete --name daily-sync ``` ## Execution: LIST ### Backend: Native CronList (Claude Code) ``` CronList() ``` Display results as a table: ``` Scheduled Tasks (native-cron backend) NAME SCHEDULE NEXT RUN TASK daily-sync 0 9 * * * 2026-03-28 09:00:00 aiwg sync health-check 0 */6 * * * 2026-03-27 18:00:00 aiwg doctor ``` ### Backend: AIWG CLI ```bash aiwg daemon schedule ``` Parse and display in the same table format. If no tasks are scheduled: ``` No scheduled tasks found. Create one with: /schedule create --name <name> --cron "<expr>" --task "<task>" ``` ## Execution: DELETE ### Backend: Native CronDelete (Claude Code) ``` CronDelete({ name: "<name>" }) ``` ### Backend: AIWG CLI ```bash aiwg daemon schedule delete --name "<name>" ``` **Output on success**: ``` Scheduled task deleted Name: daily-sync Backend: native-cron No more scheduled tasks. Create one with: /schedule create ``` **Output if not found**: ``` Task not found: daily-sync Available tasks: health-check (0 */6 * * *) ``` ## Backend Routing Table | Provider | Native CronCreate | Fallback | |----------|------------------|---------| | Claude Code | CronCreate/CronList/CronDelete | | | Warp Terminal | | aiwg daemon | | GitHub Copilot | | aiwg daemon | | Cursor | | aiwg daemon | | Windsurf | | aiwg daemon | | OpenCode | | aiwg daemon | | Factory AI | | aiwg daemon | | OpenCode (Codex) | | aiwg daemon | | OpenClaw | | aiwg daemon | ## Chrony Setup Recommendations Always check and report chrony status when creating schedules. Include platform-specific install instructions if missing. | Priority | When chrony is missing | |----------|----------------------| | HIGH | Server environments, long-running containers | | MEDIUM | Developer workstations | | LOW | Short-lived CI/CD agents | Chrony is especially important when: - Tasks are scheduled at exact times (not just intervals) - The host may sleep/hibernate between runs - Sub-minute precision is needed - The system runs in a VM or container with clock drift ## Error Handling | Error | Action | |-------|--------| | CronCreate unavailable | Fall back to aiwg-cli, no error shown | | Daemon not running | Show start instructions, stop gracefully | | Invalid cron expression | Validate and show examples | | Name conflict | Show existing task, offer to update | | Delete non-existent | Show available tasks | ## Cron Expression Quick Reference ``` ┌───────────── minute (0 - 59) ┌───────────── hour (0 - 23) ┌───────────── day of month (1 - 31) ┌───────────── month (1 - 12) ┌───────────── day of week (0 - 6, Sunday=0) * * * * * Examples: "0 9 * * *" every day at 9:00 AM "*/30 * * * *" every 30 minutes "0 0 * * 0" every Sunday at midnight "0 9,17 * * 1-5" weekdays at 9 AM and 5 PM "0 0 1 * *" first of every month at midnight ``` ## Examples ```bash # Create a daily sync at 9 AM /schedule create --name daily-sync --cron "0 9 * * *" --task "aiwg sync" # Create a health check every 6 hours /schedule create --name health-check --cron "0 */6 * * *" --task "aiwg doctor" # List all scheduled tasks /schedule list # Delete a scheduled task /schedule delete --name daily-sync # Natural language — parsed and routed automatically "run aiwg sync every day at 9am" "schedule a health check every 6 hours" "show me what's scheduled" "delete the daily-sync schedule" ``` ## References - #597 — Issue: intelligent cross-provider scheduler design - @.aiwg/planning/issue-driven-ralph-loop-design.md Scheduling context - CronCreate / CronList / CronDelete Claude Code native cron tools - `aiwg daemon schedule` AIWG daemon CLI fallback - `aiwg runtime-info` Reports active scheduler backend