#!/usr/bin/env node
import{a as f,b as p}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var m={name:"ag-task",summary:"manage background tasks with lifecycle tracking",usage:"ag-task <create|list|get|update|stop> [args]",options:["  create  <subject> [--desc <description>] [--active-form <text>] [--owner <id>]","  list    [--status <status>] [--owner <id>]","  get     <task-id>","  update  <task-id> --status <status> [--subject <text>] [--desc <text>]","  stop    <task-id>","","  Status: pending, in_progress, completed, failed, blocked","  --help  display this help and exit"]};function a(t,u){let i=t.indexOf(u);if(i!==-1&&i+1<t.length)return t[i+1]}var x={name:"ag-task",async execute(t,u){if(p(t))return f(m);let i=u.bash?.services?.taskManager;if(!i)return{stdout:"",stderr:`ag-task: task manager not available
`,exitCode:1};let k=t[0]||"list";switch(k){case"create":{let o=t.slice(1).filter(s=>s!=="--desc"&&s!=="--active-form"&&s!=="--owner"&&!t[t.indexOf("--desc")+1]?.includes(s)&&!t[t.indexOf("--active-form")+1]?.includes(s)&&!t[t.indexOf("--owner")+1]?.includes(s)).join(" "),e=[];for(let s=1;s<t.length;s++){if(t[s].startsWith("--")){s++;continue}e.push(t[s])}let n=e.join(" ");if(!n)return{stdout:"",stderr:`ag-task: missing task subject
`,exitCode:1};let c=a(t,"--desc")||n,r=a(t,"--active-form"),d=a(t,"--owner");try{let s=i.create({subject:n,description:c,owner:d,activeForm:r});return{stdout:`Created task ${s.id}: ${s.subject}
`,stderr:"",exitCode:0}}catch(s){return{stdout:"",stderr:`ag-task: ${s instanceof Error?s.message:String(s)}
`,exitCode:1}}}case"list":{let o=a(t,"--status"),e=a(t,"--owner"),n=i.list({status:o,owner:e});if(n.length===0)return{stdout:`No tasks found.
`,stderr:"",exitCode:0};let c=Object.assign(Object.create(null),{pending:"[ ]",in_progress:"[~]",completed:"[x]",failed:"[!]",blocked:"[#]"}),r=`Tasks:
`;for(let d of n){let s=c[d.status]||"[?]",l=d.owner?` (${d.owner})`:"";r+=`  ${d.id.padEnd(10)} ${s} ${d.subject}${l}
`}return{stdout:r,stderr:"",exitCode:0}}case"get":{let o=t[1];if(!o)return{stdout:"",stderr:`Usage: ag-task get <task-id>
`,exitCode:1};let e=i.get(o);if(!e)return{stdout:"",stderr:`ag-task: task ${o} not found
`,exitCode:1};let n=`Task: ${e.id}
`;return n+=`  Subject:     ${e.subject}
`,n+=`  Description: ${e.description}
`,n+=`  Status:      ${e.status}
`,e.owner&&(n+=`  Owner:       ${e.owner}
`),e.activeForm&&(n+=`  Active Form: ${e.activeForm}
`),e.blockedBy.length>0&&(n+=`  Blocked By:  ${e.blockedBy.join(", ")}
`),e.blocks.length>0&&(n+=`  Blocks:      ${e.blocks.join(", ")}
`),{stdout:n,stderr:"",exitCode:0}}case"update":{let o=t[1];if(!o)return{stdout:"",stderr:`Usage: ag-task update <task-id> --status <status>
`,exitCode:1};let e=a(t,"--status"),n=a(t,"--subject"),c=a(t,"--desc");try{let r=i.update(o,{status:e,subject:n,description:c});return{stdout:`Updated task ${r.id}: ${r.status}
`,stderr:"",exitCode:0}}catch(r){return{stdout:"",stderr:`ag-task: ${r instanceof Error?r.message:String(r)}
`,exitCode:1}}}case"stop":{let o=t[1];if(!o)return{stdout:"",stderr:`Usage: ag-task stop <task-id>
`,exitCode:1};try{return i.update(o,{status:"failed"}),{stdout:`Stopped task ${o}
`,stderr:"",exitCode:0}}catch(e){return{stdout:"",stderr:`ag-task: ${e instanceof Error?e.message:String(e)}
`,exitCode:1}}}default:return{stdout:"",stderr:`ag-task: unknown subcommand: ${k}
`,exitCode:1}}}};export{x as agTaskCommand};
