---
description: Create, list, or delete scheduled recurring jobs
allowed-tools: Bash, Read, CronCreate, CronDelete
argument-hint: "<time> <description>" | list | delete <id>
---

Manage time-based recurring jobs. Schedules persist in the DB and are re-registered on boot.

## Parse $ARGUMENTS

Determine the action:

- `list` → show all active schedules
- `delete <id>` → remove a schedule
- `run <id>` → execute a schedule's prompt immediately
- `"<time>" "<description>"` → create a new schedule

---

## Action: list

```bash
node -e "
  const {initStore}=require(require('path').join(require('child_process').execSync('npm root -g',{encoding:'utf8'}).trim(),'@askexenow/exe-os/dist/lib/store.js'));
  const {listSchedules}=require(require('path').join(require('child_process').execSync('npm root -g',{encoding:'utf8'}).trim(),'@askexenow/exe-os/dist/lib/schedules.js'));
  (async()=>{
    await initStore();
    const schedules=await listSchedules();
    if(schedules.length===0){console.log('No active schedules.');return;}
    console.log('ID       | Cron             | Type    | Description');
    console.log('---------|------------------|---------|------------------');
    for(const s of schedules){
      console.log(s.id.padEnd(9)+'| '+s.cron.padEnd(17)+'| '+s.jobType.padEnd(8)+'| '+s.description);
    }
  })().catch(e=>console.error(e.message))
" 2>/dev/null
```

Print the output as-is.

---

## Action: delete <id>

```bash
ID="<extracted-id>"
node -e "
  const {initStore}=require(require('path').join(require('child_process').execSync('npm root -g',{encoding:'utf8'}).trim(),'@askexenow/exe-os/dist/lib/store.js'));
  const {deleteSchedule}=require(require('path').join(require('child_process').execSync('npm root -g',{encoding:'utf8'}).trim(),'@askexenow/exe-os/dist/lib/schedules.js'));
  (async()=>{
    await initStore();
    const ok=await deleteSchedule('${ID}');
    console.log(ok?'Schedule ${ID} deleted.':'Schedule ${ID} not found.');
  })().catch(e=>console.error(e.message))
" 2>/dev/null
```

---

## Action: create

1. Parse the time expression from $ARGUMENTS. The first quoted string or recognizable time expression is the schedule, the rest is the description.

2. Convert to cron using the built-in parser:

```bash
TIME_EXPR="<extracted-time>"
node -e "
  const {parseHumanCron}=require(require('path').join(require('child_process').execSync('npm root -g',{encoding:'utf8'}).trim(),'@askexenow/exe-os/dist/lib/schedules.js'));
  console.log(parseHumanCron('${TIME_EXPR}'))
" 2>/dev/null
```

3. Determine job type:
   - If description mentions "test", "build", "deploy" → type: "work", assigned_to: configured CTO or principal engineer
   - If description mentions "report", "summary", "status" → type: "report"
   - If description mentions "sync", "backfill", "clean" → type: "maintenance"
   - Default: "report"

4. Ask the user: "Should this job survive session restarts? (Uses system crontab)"
   - If yes: `use_crontab = true`
   - If no: `use_crontab = false` (re-registered on boot via CronCreate)

5. Create the schedule:

```bash
CRON="<cron-expression>"
DESC="<description>"
TYPE="<job-type>"
CRONTAB="<0-or-1>"
node -e "
  const {initStore}=require(require('path').join(require('child_process').execSync('npm root -g',{encoding:'utf8'}).trim(),'@askexenow/exe-os/dist/lib/store.js'));
  const {createSchedule}=require(require('path').join(require('child_process').execSync('npm root -g',{encoding:'utf8'}).trim(),'@askexenow/exe-os/dist/lib/schedules.js'));
  (async()=>{
    await initStore();
    const s=await createSchedule({cron:'${CRON}',description:'${DESC}',jobType:'${TYPE}',useCrontab:${CRONTAB}===1});
    console.log('Schedule created: '+s.id);
    console.log('Cron: '+s.cron);
    console.log('Type: '+s.jobType);
    console.log('Crontab: '+(s.useCrontab?'yes (survives restarts)':'no (session-scoped, re-registered on boot)'));
  })().catch(e=>console.error(e.message))
" 2>/dev/null
```

6. If not using crontab, register with CronCreate now:
   - Use CronCreate with the cron expression and the description as the prompt

Report the result to the user.
