#!/usr/bin/env node
import{a as i,b as u}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var m={name:"ag-cron",summary:"manage scheduled cron jobs",usage:"ag-cron <create|delete|list> [args]",options:["  create  <cron-expr> <prompt> [--one-shot] [--durable]","  delete  <job-id>","  list","","  Cron expression: standard 5-field format (minute hour dom month dow)","  Supports: *, ranges (1-5), steps (*/5), lists (1,3,5)","","  --one-shot   fire once then auto-delete (default: recurring)","  --durable    persist job to VFS (default: session-only)","  --help       display this help and exit"],examples:['ag-cron create "*/5 * * * *" "echo health check"','ag-cron create "0 9 * * 1-5" "run daily report" --durable','ag-cron create "30 2 * * *" "backup db" --one-shot',"ag-cron delete cron_1","ag-cron list"]},g={name:"ag-cron",async execute(o,l){if(u(o))return i(m);let s=l.bash?.services?.cronScheduler;if(!s)return{stdout:"",stderr:`ag-cron: cron scheduler not available
`,exitCode:1};let a=o[0]||"list";switch(a){case"create":{let t=o[1];if(!t)return{stdout:"",stderr:`ag-cron: missing cron expression
Usage: ag-cron create <cron-expr> <prompt> [--one-shot] [--durable]
`,exitCode:1};let n=o.includes("--one-shot"),r=o.includes("--durable"),d=[];for(let e=2;e<o.length;e++)o[e]==="--one-shot"||o[e]==="--durable"||d.push(o[e]);let c=d.join(" ");if(!c)return{stdout:"",stderr:`ag-cron: missing prompt
Usage: ag-cron create <cron-expr> <prompt> [--one-shot] [--durable]
`,exitCode:1};try{let e=s.createJob({cron:t,prompt:c,recurring:!n,durable:r});return{stdout:`Created ${e.recurring?"recurring":"one-shot"} job ${e.id}: ${e.cron} -> ${e.prompt}
`,stderr:"",exitCode:0}}catch(e){return{stdout:"",stderr:`ag-cron: ${e instanceof Error?e.message:String(e)}
`,exitCode:1}}}case"delete":{let t=o[1];return t?s.deleteJob(t)?{stdout:`Deleted job ${t}
`,stderr:"",exitCode:0}:{stdout:"",stderr:`ag-cron: job ${t} not found
`,exitCode:1}:{stdout:"",stderr:`Usage: ag-cron delete <job-id>
`,exitCode:1}}case"list":{let t=s.listJobs();if(t.length===0)return{stdout:`No cron jobs found.
`,stderr:"",exitCode:0};let n=`Cron jobs:
`;for(let r of t){let d=r.recurring?"recurring":"one-shot",c=r.durable?"durable":"session",e=r.fireCount>0?` (fired ${r.fireCount}x)`:"";n+=`  ${r.id.padEnd(10)} [${d}] [${c}] ${r.cron}  ->  ${r.prompt}${e}
`}return{stdout:n,stderr:"",exitCode:0}}default:return{stdout:"",stderr:`ag-cron: unknown subcommand: ${a}
`,exitCode:1}}}};export{g as agCronCommand};
