epiq 1.3.4 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/gui/main.js +15030 -1881
  2. package/dist/index.js +1 -1
  3. package/package.json +4 -1
package/dist/index.js CHANGED
@@ -55,7 +55,7 @@ ${m}
55
55
 
56
56
  ${c}
57
57
  `,ai.writeFileSync(t,n,"utf8"),se.info(`Added ${s.join(", ")} to .gitignore (epiq local state)`),l("Local epiq paths ignored",!0)};var hg=async e=>{let t=await _({cwd:e,args:["status","--porcelain"]});return d(t)?t:l("Checked git diff",t.value.stdout.trim().length>0)},te=(e,t)=>a(`[${e}] ${t}`),Cc=async()=>{W("");let e=yn(),t=await dt(process.cwd());if(d(t))return te(1,t.message);let n=t.value,r=await Br(n);if(d(r))return te(2,r.message);if(r.value)return te(2,`Cannot initialize Epiq while a git operation is in progress: ${r.value}`);let o=await hg(n);if(d(o))return te(2.5,o.message);if(o.value)return te(3,"Cannot initialize Epiq with uncommitted changes. Commit or stash your changes first.");if(us(n))return te(4,"Epiq project already initialized");let s=_t();if(!s.isSetupDone||!s.userName)return te(5,"Missing Epiq user configuration (userId / userName). Run setup first.");let i=K(),c=i.userName,u=i.userId;if(!u||!c)return te(5,"Missing Epiq user id");let m=e.stateBranch,p=await Or({repoRoot:n,branch:m});if(d(p))return te(6,p.message);if(p.value)return te(6,`State branch already exists: ${m}`);let f=await Es({repoRoot:n,stateBranchName:m});if(d(f))return te(6,f.message);let b=Hr();if(d(b))return te(7,b.message);let C=Sc.join($r(),e.projectId),N=await tn({repoRoot:n,stateBranchRoot:C,stateBranchName:m});if(d(N))return te(8,N.message);let A=Sc.join(C,".epiq");yg.mkdirSync(A,{recursive:!0});let M=nd({userId:u,userName:c});if(d(M))return te(9,M.message);for(let ds of M.value){let ki=to({event:ds,rootDir:C});if(d(ki))return te(9,ki.message)}let U=await jr({stateBranchRoot:C,eventFileName:on({userId:u,userName:c})});if(d(U))return te(10,U.message);let j=await xn({cwd:C,message:"[epiq:init]"});if(d(j))return te(10,j.message);let D=await Ec(n);if(d(D))return te(11,D.message);let z=Oi({repoRoot:n,fileContents:e});if(d(z))return te(12,z.message);let $=await ce.stage({cwd:n,pathspec:[".epiq/project.json",".gitignore"]});if(d($))return te(13,$.message);let P=await ce.commit({cwd:n,message:"[epiq:init-project]"});if(d(P))return te(13,P.message);let O="Project initialized!",Ge=await _({cwd:n,args:["push","-u","origin","HEAD"]});d(Ge)&&(O+=` Warn: [init:14] ${Ge.message}`);let Ce=await Qn({repoRoot:n,stateBranchRoot:C});d(Ce)&&(O+=` Warn: [init:15] ${Ce.message}`);let me=Ot(M.value).filter(d);if(me.length>0)return te(16,me.map(ds=>ds.message).join(`
58
- `));let le=Je();if(d(le))return te(16,le.message);let{rootNodeId:$n,nodes:Hn}=le.value,Li=Hn[$n];return Li?(T.navigate({contextNode:Li,selectedIndex:0}),E({hasProjectDefinition:!0,mode:v.DEFAULT}),l(O,null)):te(16,"Unable to resolve initialized root node")};import{ulid as bg}from"ulid";import{ulid as xg}from"ulid";var Nc=null,Gt=()=>structuredClone(Nc),hr=e=>{Nc=e},Ac=()=>{let{contextNode:e,selectedIndex:t}=g(),r=q(e.id)[t];return r?l("Resolved selected child",r):a("Target node not found")},di=({id:e,parentId:t,position:n={at:"end"}})=>{let r=q(t).filter(o=>o.id!==e);return no(r,n)},Rc=({id:e,parentId:t,position:n={at:"end"}})=>{let r=ie();if(d(r))return a("Unable to resolve user ID");let o=di({parentId:t,id:e,position:n});return d(o)?o:l("Created pending move state",{id:xg(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},Tc=e=>{hr(e);let t=Ut(e,!0);return d(t)?t:l("Node moved successfully",t.value)};function ci(e){let t=Ac();if(d(t))return t;let{contextNode:n,nodes:r}=g();if(!n.parentNodeId)return a("Missing parent node id");let o=r[n.parentNodeId];if(!o)return a("Missing parent node");let s=q(o.id),i=s.findIndex(({id:m})=>m===n.id);if(i<0)return a("Current node not found among siblings");let c=s[i+e];if(!c)return a("Missing sibling node");let u=Rc({id:t.value.id,parentId:c.id,position:{at:"end"}});return d(u)?u:Tc(u.value)}function li(e){let t=Ac();if(d(t))return t;let{contextNode:n,selectedIndex:r}=g(),s=q(n.id)[r+e];if(!s)return a("Missing sibling node");let i=Rc({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:s.id}});return d(i)?i:Tc(i.value)}var wc=()=>{let e=Gt();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,r=g().nodes[n];if(!r)return a("Move parent not found");let o=q(n).findIndex(s=>s.id===t);return o===-1?a("Moved node not found among rendered children"):(T.navigate({contextNode:r,selectedIndex:o}),l("Synchronized navigation to moved node",null))},wo=(e,t="Moved preview")=>{if(d(e))return e;let n=wc();return d(n)?n:(E({mode:v.MOVE}),l(t,null))},Mc=async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=Y().commandMeta,{contextNode:n,selectedIndex:r}=g(),o=q(n.id)[r];if(!o)return E({mode:v.DEFAULT}),a("No move target");if(t==="start"){if(o.readonly)return a("Target node is read-only");if(r===-1)return a("No item selected");if(!o.parentNodeId)return a("Target has no parent");let s=q(o.parentNodeId),i=s.findIndex(({id:f})=>f===o.id);if(i===-1)return a("Target not found among siblings");let c=s[i-1],u=s[i+1],m=u!=null?{at:"before",sibling:u.id}:c!=null?{at:"after",sibling:c.id}:{at:"start"},p=di({parentId:o.parentNodeId,id:o.id,position:m});return d(p)?p:(hr({id:bg(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:p.value.rank},...e.value}),E({mode:v.MOVE}),l("Move initialized",null))}if(t==="next")return wo(li(1));if(t==="previous")return wo(li(-1));if(t==="to-next")return wo(ci(1));if(t==="to-previous")return wo(ci(-1));if(t==="confirm"){let s=Gt();if(!s)return a("No pending move to confirm");let i=await at();if(d(i))return i;let c=B([s],i.value);if(d(c))return c;let u=wc();return d(u)?u:(hr(null),E({mode:v.DEFAULT}),l("Moved item",null))}return t==="cancel"?(hr(null),E({mode:v.DEFAULT}),l("Cancelling move",null)):a("Invalid move modifier")};import{ulid as Po}from"ulid";import{monotonicFactory as Ig,ulid as Eg}from"ulid";var Sg=Ig(),Mo=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let s=Sg();return l("Created issue events",[{id:Eg(),userId:r,userName:o,action:"add.issue",payload:{id:s,parent:t,name:e,rank:n}}])};var Pc=async(e,t)=>{let n=ie();if(d(n))return a("Unable to resolve user ID");let r=await at();if(d(r))return r;let o=r.value;if(!t.inputString)return a(`provide a name for your ${t.modifier}`);let{breadCrumb:s,contextNode:i,selectedIndex:c}=g(),u=m=>{let p=B([m],o);if(d(p))return p;let f=I.getNode(p.value[0].result.id);if(!f)return a("Created node not found");if(!f.parentNodeId)return p;let b=I.getNode(f.parentNodeId);return b?(T.navigate({contextNode:b,selectedIndex:I.getSiblings(f.parentNodeId).findIndex(({id:C})=>C===f.id)}),p):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=g(),p=I.getNode(m);if(!p)return a("Workspace not found");let f=Nn(p.id,n.value,o);return d(f)?f:u({id:Po(),action:"add.board",payload:{id:Po(),name:t.inputString,parent:p.id,rank:f.value},...n.value})}if(t.modifier==="swimlane"){let m=Le(s,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let p=Nn(m.value.id,n.value,o);return d(p)?p:u({id:Po(),action:"add.swimlane",payload:{id:Po(),name:t.inputString,parent:m.value.id,rank:p.value},...n.value})}if(t.modifier==="issue"){let m=G(i.id)[c],p=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let j=Le(s,"SWIMLANE");return d(j)?null:j.value})();if(!p)return a("Unable to add issue in this context");let f=Nn(p.id,n.value,o);if(d(f))return f;let b=Mo({name:t.inputString,parent:p.id,rank:f.value,user:n.value});if(d(b))return b;let C=b.value,N=B([...C],o);if(d(N))return N;if(!N.value[0])return a("Issue creation failed");let U=C.find(j=>j.action==="add.issue")?.payload.id;return U?(T.navigate({contextNode:p,selectedIndex:I.getSiblings(p.id).findIndex(({id:j})=>j===U)}),l("Issue created",null)):a("Unable to determine ticket id")}return l("Success",null)};var Lo=({boardId:e,targetTime:t,stateBranchRoot:n,selectedIndex:r})=>{let o=g(),s=$a(n,t);if(d(s))return a(s.message);let{appliedEvents:i,unappliedEvents:c}=s.value,u=zt();if(d(u))return u;let p=Ot(i).filter(d);if(p.length>0)return zt(),E(o),a(p.map(b=>b.message).join(", "));let f=g().nodes[e];return f?(T.navigate({contextNode:f,selectedIndex:r}),l("",{unappliedEvents:c})):(zt(),E(o),a("Board did not exist at that date"))};var Cg=20,Ng=16,Ag=150,ko=null,Do=null;var fn=()=>{ko!==null&&(clearInterval(ko),ko=null),Do!==null&&(clearTimeout(Do),Do=null)},Lc=()=>{fn(),E({mode:v.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null,selectedIndex:0})},Rg=e=>{let t=[],n=0;for(let o=0;o<e.length;o++){let s=o===0?0:Math.max(0,e[o]-e[o-1]);n+=Math.sqrt(s),t[o]=n}let r=n;return t.map((o,s)=>r>0?o/r:(s+1)/e.length)},kc=({events:e,startTime:t,durationMs:n})=>{fn();let r=e.length,o=e.map(f=>Cn(f)??t),s=o[r-1]??Date.now(),i=Rg(o),c=Math.max(1,Math.round(n*Cg/1e3)),u=Math.max(Math.round(n/c),Ng),m=0,p=0;E({mode:v.DEFAULT,readOnly:!0,timeMode:"replay",unappliedEvents:e,replay:{progress:0,appliedCount:0,totalCount:r,currentTime:t,startTime:t,endTime:s,currentLabel:"",flashNodeIds:[]}}),ko=setInterval(()=>{m++;let f=m/c,b=[],C;for(;p<r&&i[p]<=f;){let A=e[p],M=Ut(A);if(d(M)){Lc();return}b.push(...Ms(A)),C=A,p++}if(p>=r||m>=c){for(;p<r;p++){let M=Ut(e[p]);if(d(M))break}let A=g().replay;E({unappliedEvents:[],replay:A&&{...A,progress:1,appliedCount:r}}),fn(),Do=setTimeout(Lc,Ag);return}let N=g().replay;E({unappliedEvents:e.slice(p),replay:{progress:Math.min(1,f),appliedCount:p,totalCount:r,startTime:t,endTime:s,currentTime:C?Cn(C)??N?.currentTime??t:N?.currentTime??t,currentLabel:C?ka(C):N?.currentLabel??"",flashNodeIds:C?[...new Set(b)]:N?.flashNodeIds??[]}})},u)};var Dc=async()=>{let e=Le(g().breadCrumb,"BOARD");if(d(e))return e;let t=await dt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Pe({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=Y().commandMeta;if(fn(),r==="now"){let c=Et(n.value);if(d(c))return a(c.message);let u=zt();if(d(u))return u;let p=Ot(c.value).filter(d);return p.length>0?a(p.map(f=>f.message).join(", ")):(E({mode:v.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),l("Peeking now",!0))}let s;if(r==="prev"){let c=g().eventLog.at(-1),u=Cn(c);if(u===null)return a("No previous event to peek");s=u}else if(r==="next"){let c=g().unappliedEvents.at(0),u=Cn(c);if(u===null)return a("No next event to peek");s=u+1}else{let c=cn(r||o.trim());if(!c)return a("Invalid peek date");s=c.getTime()}let i=Lo({boardId:e.value.id,targetTime:s,stateBranchRoot:n.value,selectedIndex:0});return d(i)?i:(E({mode:v.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:i.value.unappliedEvents,replay:null}),l("Peeking",!0))};var Fc=async()=>{let e=Le(g().breadCrumb,"BOARD");if(d(e))return e;let t=await dt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Pe({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=Y().commandMeta,{dateInput:s,durationInput:i}=mo(r,o);if(fn(),g().syncStatus.status==="syncing")return a("Cannot replay while syncing, try again in a moment");let c=cn(s);if(!c)return a("Invalid replay date");let u=i?uo(i):15e3;if(u===null)return a("Invalid replay duration (try e.g. 30s or 2m)");let m=c.getTime(),p=g(),f=Lo({boardId:e.value.id,targetTime:m,stateBranchRoot:n.value,selectedIndex:-1});if(d(f))return f;let{unappliedEvents:b}=f.value;return b.length===0?(zt(),E(p),l("Nothing to replay from that point",!0)):(kc({events:b,startTime:m,durationMs:u}),l("Replaying board history",!0))};import wg from"zod";var Bc=()=>{let e=Y().commandMeta.inputString,t=wg.coerce.number().int().min(3e3).safeParse(e);if(!t.success)return a("Auto sync duration must be a number of at least 3000 ms");let n=Ze({autoSyncDebounceMs:t.data});return d(n)?n:(Fe({autoSyncIntervalMs:t.data}),E({mode:v.DEFAULT}),l(`Auto sync interval set to ${t.data}ms`,null))};var Uc=()=>{let e=Y().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=cd(e),n=Ze({autoSync:t});return d(n)?n:(Fe({autoSync:t}),E({mode:v.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var Oc=()=>{let e=Y().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=Ze({logLevel:e});return d(n)?n:(Fe({logLevel:e}),E({mode:v.DEFAULT}),l(`Auto sync set to "${e}"`,null))};import{spawn as Mg}from"node:child_process";var Pg=()=>{switch(process.platform){case"darwin":return{command:"pbcopy",args:[]};case"win32":return{command:"clip",args:[]};default:return process.env.WAYLAND_DISPLAY?{command:"wl-copy",args:[]}:{command:"xclip",args:["-selection","clipboard"]}}},_c=async e=>new Promise(t=>{let{command:n,args:r}=Pg();try{let o=Mg(n,r,{stdio:["pipe","ignore","ignore"]});o.on("error",()=>t(a(`Clipboard tool not available (${n})`))),o.on("close",s=>t(s===0?l("Copied to clipboard",null):a(`Clipboard tool failed (${n})`))),o.stdin.on("error",()=>{}),o.stdin.write(e),o.stdin.end()}catch{t(a(`Clipboard tool not available (${n})`))}});var xr=async(e,t)=>{if(!e.trim())return a(`Nothing to copy: ${t} is empty`);let n=await _c(e);return d(n)?n:l(`Copied ${t} to clipboard`,null)},$c=async e=>{let{breadCrumb:t,selectedNode:n}=g(),r=ar({breadCrumb:t,selectedNode:n}),o=r??n;if(!o)return a("Nothing selected to copy from");switch(e.modifier){case fe.REF:return xr(Ue(o.id),"ref");case fe.TITLE:return xr(o.title,"title");case fe.DESCRIPTION:return r?xr(r.props?.description??"","description"):a("No issue in scope");case fe.TAGS:{if(!r)return a("No issue in scope");let s=$t(r).map(({name:i})=>i);return xr(s.join(", "),"tags")}case fe.ASSIGNEES:{if(!r)return a("No issue in scope");let s=Ht(r).map(({name:i})=>i);return xr(s.join(", "),"assignees")}default:return a("Yank one of: ref, title, description, tags, assignees")}};var Hc=async()=>{W(""),E({mode:v.DEFAULT});let e=Je();if(d(e))return a(e.message);if(e.value.syncStatus.status==="syncing")return a("Sync already in progress");E({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await so();return d(t)?(E({syncStatus:{msg:t.message,status:"failed"}}),t):(E({mode:v.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var Lg=e=>e.action==="add.issue.comment",Wc=e=>Object.values(g().tags).find(t=>t.name===e),jc=e=>Object.values(g().contributors).find(t=>t.name===e),wt=async()=>{let e=await at();return d(e)?e:l("Resolved persist root",e.value)},Fo=[{systemOnly:!0,intent:w.Move,description:"Internal move-state command",mode:v.COMMAND_LINE,action:Mc},{intent:w.Delete,description:"Delete the currently selected node",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to resolve child to delete");let o=await wt();if(d(o))return o;if(r.context==="COMMENT"){let s=r.id,i=R(t)?t.id:t.parentNodeId;if(!i)return a("Unable to resolve comment issue");let c=g().nodes[i];if(!c||!R(c))return a("Unable to resolve comment issue");let u=c.log?.filter(Lg).find(m=>m.payload.id===s);return u?u.payload.author!==e.value.userId?a("You can only delete your own comments"):B([{id:we(),action:"delete.issue.comment",payload:{id:s,issue:i},...e.value}],o.value):a("Unable to resolve comment")}return B([{id:we(),action:"delete.node",payload:{id:r.id},...e.value}],o.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:v.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=Y().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(i=>ae(x.FILTER).map(c=>c.split(n)[0]).includes(i))(r))return a("Invalid filter modifier");let s={target:r,operator:"=",value:t.trim()};return he(i=>({...i,filters:e==="clear"?[]:[...i.filters,s],mode:v.DEFAULT})),l("Filter updated",null)}},{intent:w.ViewHelp,description:"Open the help screen",mode:v.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=g();return Kt({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),E({mode:v.HELP}),l("Viewing help",null)}},{intent:w.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to close issue, no target found");if(!R(r))return a("Cannot close in this context");let o=g().nodes[pe];if(!o)return a("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return a("Issue is already closed");let s=await wt();if(d(s))return s;let i=s.value,c=sn(o.id,r.id,{at:"end"},e.value,i);if(d(c))return c;let u=B([{id:we(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:c.value},...e.value}],i);return d(u)?u:l("Issue closed",null)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to reopen issue, no target found");let o=r.context==="TICKET"?l("Resolved ticket",r):It(r.id,"TICKET");if(d(o))return a("Cannot reopen in this context");let s=o.value,i=g().nodes[pe];if(!i)return a("Unable to locate closed swimlane");if(s.parentNodeId!==i.id)return a("Issue is not closed");if(!R(s))return a("Target node is not issue");let c=Ro(s);if(!c)return a("Unable to resolve previous parent from issue history");if(c===i.id)return a("Previous parent resolves to closed swimlane");let u=g().nodes[c];if(!u)return a("Previous parent no longer exists");let m=await wt();if(d(m))return m;let p=m.value,f=sn(u.id,s.id,{at:"end"},e.value,p);if(d(f))return f;let b=B([{id:we(),action:"reopen.issue",payload:{id:s.id,parent:u.id,rank:f.value},...e.value}],p);return d(b)?b:l("Issue reopened",null)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Init,description:"Initialize Epiq in the current git repository",mode:v.COMMAND_LINE,action:Cc},{intent:w.NewItem,description:"Create a new board, swimlane, or issue",mode:v.COMMAND_LINE,action:Pc,onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Rename,description:"Rename the currently selected node",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Missing node");if(r.readonly)return a("Cannot rename readonly node");let o=qd();if(!o)return a("Provide a title");let s=await wt();return d(s)?s:B([{id:we(),action:"edit.title",payload:{id:r.id,name:o},...e.value}],s.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.UntagTicket,description:"Remove a tag from the selected issue",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let o=Wc(r);if(!o)return a(`Tag "${r}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid untag target");let i=It(s.id,"TICKET");if(d(i))return a("Unable to untag issue in this context");let c=i.value;if(!R(c))return a("Target node is not issue");if(!(c.props.tags??[]).includes(o.id))return a("Issue is not tagged with that tag");let m=await wt();return d(m)?m:B([{id:we(),action:"remove.issue.tag",payload:{id:c.id,tag:o.id},...e.value}],m.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.TagTicket,description:"Add or create a tag on the selected issue",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let{selectedNode:o}=g();if(!o)return a("Invalid tag target");let s=It(o.id,"TICKET");if(d(s))return a("Unable to tag issue in this context");let i=s.value;if(!R(i))return a("Target node is not issue");let c=await wt();if(d(c))return c;let u=Wc(r),m=u?.id??we();return(i.props.tags??[]).includes(m)?a("Already tagged with that tag"):B([...u?[]:[{id:we(),action:"create.tag",payload:{id:m,name:r},...e.value}],{id:we(),action:"add.issue.tag",payload:{id:i.id,tag:m},...e.value}],c.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.AssignUserToTicket,description:"Assign a user to the selected issue",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee");let{selectedIndex:o,contextNode:s}=g(),i=G(s.id)[o];if(!i)return a("Invalid assign target");let c=It(i.id,"TICKET");if(d(c))return a("Unable to assign issue in this context");let u=c.value;if(!R(u))return a("Target node is not issue");let m=await wt();if(d(m))return m;let p=jc(r),f=p?.id??we();return(u.props.assignees??[]).includes(f)?a("Assignee already assigned"):B([...p?[]:[{id:we(),action:"create.contributor",payload:{id:f,name:r},...e.value}],{id:we(),action:"add.issue.assignee",payload:{id:u.id,assignee:f},...e.value}],m.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee to remove");let o=jc(r);if(!o)return a(`Assignee "${r}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid unassign target");let i=It(s.id,"TICKET");if(d(i))return a("Unable to unassign in this context");let c=i.value;if(!R(c))return a("Target node is not issue");if(!(c.props.assignees??[]).includes(o.id))return a(`Issue is not assigned to "${r}"`);let m=await wt();return d(m)?m:B([{id:we(),action:"remove.issue.assignee",payload:{id:c.id,assignee:o.id},...e.value}],m.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Comment,description:"Add a comment to the selected issue",mode:v.COMMAND_LINE,action:async(e,t)=>{let n=t.inputString.trim();if(!n)return a("Provide a comment");if(n.length>Pn)return a(`Cannot exceed ${Pn} characters`);let r=ie();if(d(r))return a("Unable to resolve user ID");let{breadCrumb:o,selectedNode:s}=g(),i=Le([...o,s],"TICKET");if(d(i))return a("Edit target must be an issue");let c=i.value;if(!c)return a("Invalid comment target");let u=c.context==="TICKET"?l("Resolved ticket",c):It(c.id,"TICKET");if(d(u))return a("Unable to comment on issue in this context");let m=u.value;if(!R(m))return a("Target node is not issue");let p=await wt();return d(p)?p:B([{id:we(),action:"add.issue.comment",payload:{id:we(),issue:m.id,author:r.value.userId,md:n},...r.value}],p.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Sync,description:"Pull, commit, and push Epiq state",mode:v.COMMAND_LINE,action:Hc},{intent:w.Peek,description:"View board state at another point in time",mode:v.COMMAND_LINE,action:Dc},{intent:w.Replay,description:"Replay board history forward from a point in time",mode:v.COMMAND_LINE,action:Fc},{intent:w.Export,description:"Export the current board layout to markdown",mode:v.COMMAND_LINE,action:async()=>{let e=await vc();return d(e)?e:(E({mode:v.DEFAULT}),l("Export successful",!0))}},{intent:w.Exit,description:"Exit the application",mode:v.COMMAND_LINE,action:async()=>(T.exit(),l("Exit successful",!0))},{intent:w.Edit,description:"Edit title or description",mode:v.COMMAND_LINE,action:async(e,t)=>Ic(t),onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Yank,description:"Yank (copy) ref, title, description, tags, or assignees to the clipboard",mode:v.COMMAND_LINE,action:async(e,t)=>$c(t),onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:v.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case re.USERNAME:{let{userId:r,preferredEditor:o,userName:s}=K(),i=n||s,c=r??we();if(!i||!c)return a("Unable to resolve user name or id");let u=Ze({userName:i,userId:c,preferredEditor:o??""});return d(u)?u:(Fe({userName:i,userId:c}),E({mode:v.DEFAULT}),l(`Username set to "${i}"`,null))}case re.EDITOR:{if(!n)return a("No editor provided");let r=Ze({preferredEditor:n});return d(r)?r:(Fe({preferredEditor:n}),E({mode:v.DEFAULT}),l(`Editor configuration set to "${n}"`,null))}case re.VIEW:{if(n!=="wide"&&n!=="dense")return a("Invalid view mode");let r=Ze({viewMode:n});return d(r)?r:(Fe({viewMode:n}),E({mode:v.DEFAULT}),l(`View set to "${n}"`,null))}case re.AUTOSYNC:return Uc();case re.LOG_LEVEL:return Oc();case re.SYNC_DEBOUNCE_MS:return Bc();case re.ATTACHMENT_MAX_KB:return Td();default:return a("Unknown config command")}}},{intent:w.Coffee,description:"Sponsor the development of Epiq!",mode:v.COMMAND_LINE,action:()=>{let e=Y().commandMeta.modifier;return e==="custom"?yr("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):yr(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),W(""),l("Thanks you!",null)}}];var kg=new Set(["peek","replay","filter","view-help","yank"]),vt=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=Y();if(!t)return a("No command to confirm");if(!e&&n===pt.Invalid)return a("Invalid command");let s=xo(t);jd();let{readOnly:i}=g();if(i&&!kg.has(s))return mr({status:Pt.Fail,message:"Command not available in readonly state",value:null});let c=Fo.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===s);if(!c)return mr({status:Pt.Fail,message:"Command not found",value:null});let u;try{u=await c.action(c,{command:t,inputString:o,modifier:r})}catch(m){return mr({status:Pt.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(u)?mr(u):(Vd({addToHistory:!e}),c.onSuccess?.(),K().autoSync&&ao(),u)};var Bo=[{intent:h.Exit,mode:v.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(E({mode:v.COMMAND_LINE}),W("move cancel"),vt({isForceExecutedBySystem:!0}))},{intent:h.InitMove,mode:v.DEFAULT,description:"[m] move (init/confirm)",action:()=>(E({mode:v.COMMAND_LINE}),W("move start"),vt({isForceExecutedBySystem:!0}))},{intent:h.ConfirmMove,mode:v.MOVE,action:()=>(E({mode:v.COMMAND_LINE}),W("move confirm"),vt({isForceExecutedBySystem:!0}))}],Uo=[{intent:h.MovePreviousItem,mode:v.MOVE,action:()=>Gt()?(E({mode:v.COMMAND_LINE}),W("move previous"),vt({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveNextItem,mode:v.MOVE,action:()=>Gt()?(E({mode:v.COMMAND_LINE}),W("move next"),vt({isForceExecutedBySystem:!0})):a("No pending move")}],Vc=[{intent:h.MoveToNextContainer,mode:v.MOVE,action:()=>Gt()?(E({mode:v.COMMAND_LINE}),W("move to-next"),vt({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveToPreviousContainer,mode:v.MOVE,action:()=>Gt()?(E({mode:v.COMMAND_LINE}),W("move to-previous"),vt({isForceExecutedBySystem:!0})):a("No pending move")}];var Kc={[L.WORKSPACE]:[...Bo,...Uo],[L.BOARD]:[...Bo,...Uo],[L.SWIMLANE]:[...Bo,...Uo,...Vc],[L.TICKET]:[],[L.FIELD]:[],[L.FIELD_LIST]:[],[L.TEXT]:[],[L.COMMENT]:[]};import Dg from"node:fs";import Fg from"node:path";var Gc=e=>{let t=qe(process.cwd());if(d(t))return a("Unable to resolve project root");let n=Pe({repoRoot:t.value});if(d(n))return a(n.message);let r=Mn(e.hash,e.ext),o=Fg.join(Gn(n.value),r);return Dg.existsSync(o)?(yr(o),l(`Opened ${e.name}`,null)):a("Attachment file not found \u2014 run :sync to fetch it")};var zc=()=>{W("");let{pendingNavTarget:e}=Vt();E({mode:v.DEFAULT}),e&&T.navigate(e),Kt({pendingNavTarget:void 0})},qc=[{intent:h.ExitCommandLine,mode:v.HELP,action:()=>(zc(),l("Exiting help",null))},{intent:h.Exit,mode:v.HELP,action:()=>(zc(),l("Closed help",null))},{intent:h.NavPreviousItem,mode:v.HELP,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous help item",null))},{intent:h.NavNextItem,mode:v.HELP,action:()=>(T.navigateToNextItem(),l("Navigating to next help item",null))},{intent:h.NavToPreviousContainer,mode:v.HELP,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous help container",null))},{intent:h.NavToNextContainer,mode:v.HELP,action:()=>(T.navigateToNextContainer(),l("Navigating to next help container",null))}];var Bg=e=>{E({mode:v.COMMAND_LINE});let{pendingNavTarget:t}=Vt();t&&T.navigate(t),Kt({pendingNavTarget:void 0}),W(`${e} `)},Yc=()=>{W("");let{pendingNavTarget:e}=Vt();e&&T.navigate(e),Kt({pendingNavTarget:void 0}),E({mode:v.DEFAULT})},Xc=[{intent:h.InitCommandPalette,mode:v.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{W("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=g();return Kt({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),E({mode:v.PALETTE}),l("Opening command palette",null)}},{intent:h.Confirm,mode:v.PALETTE,action:()=>{let{selectedNode:e}=g();if(!e||!kt(e))return a("Command only applicable on text nodes");if(e.props.disabled)return a("Command is not available in this context");let t=e.title;return t?(Bg(t),l("Selected command",t)):l("No command selected",null)}},{intent:h.ExitCommandLine,mode:v.PALETTE,action:()=>(Yc(),l("Exiting palette",null))},{intent:h.Exit,mode:v.PALETTE,action:()=>(Yc(),l("Closed command palette",null))},{intent:h.NavPreviousItem,mode:v.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:v.PALETTE,action:()=>(T.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:v.PALETTE,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:v.PALETTE,action:()=>(T.navigateToNextContainer(),l("Navigating to next container",null))}];var Jc=[...qc,...Xc,{intent:h.AddItem,mode:v.DEFAULT,description:"[n] new...",action:()=>(E({mode:v.COMMAND_LINE}),W(`${x.NEW} `),l("Adding new item",null))},{intent:h.Delete,mode:v.DEFAULT,description:"[d] delete",action:()=>(E({mode:v.COMMAND_LINE}),W(`${x.DELETE} `),l("Deleting item",null))},{intent:h.InitCommandLine,mode:v.DEFAULT,description:"[:] focus command line",action:()=>(E({mode:v.COMMAND_LINE}),W(""),l("Entering command line mode",null))},{intent:h.Confirm,mode:v.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=g();if(!q(e?.id??"")?.length){let r=e?I.getAttachment(e.id):void 0;if(r)return Gc(r);if(e?.title===Q.DESCRIPTION)return E({mode:v.COMMAND_LINE}),W(`${x.EDIT} description `),l("Propose command",!0);if(e?.title===Q.ASSIGNEES)return E({mode:v.COMMAND_LINE}),W(`${x.ASSIGN} `),l("Propose command",!0);if(e?.title===Q.TAGS)return E({mode:v.COMMAND_LINE}),W(`${x.TAG} `),l("Propose command",!0);if(t.title===Q.DESCRIPTION&&e?.context==="TEXT")return E({mode:v.COMMAND_LINE}),W(`${x.EDIT} description `),l("Propose command",!0)}return T.enterChildNode(),l("Entering context",null)}},{intent:h.Yank,mode:v.DEFAULT,description:"[y] yank to clipboard",action:()=>{let{selectedNode:e}=g(),t=e?.title===Q.DESCRIPTION?fe.DESCRIPTION:e?.title===Q.TAGS?fe.TAGS:e?.title===Q.ASSIGNEES?fe.ASSIGNEES:fe.REF,r=ae(x.YANK).includes(t)?t:fe.REF;return E({mode:v.COMMAND_LINE}),W(`${x.YANK} ${r}`),l("Propose command",!0)}},{intent:h.EditTitle,mode:v.DEFAULT,description:"[r] rename title",action:()=>(E({mode:v.COMMAND_LINE}),W(`${x.EDIT} title ${g().selectedNode?.title}`),l("Exiting context",null))},{intent:h.EditDescription,mode:v.DEFAULT,description:"[e] edit description",action:()=>(E({mode:v.COMMAND_LINE}),W(`${x.EDIT} description `),l("Exiting context",null))},{intent:h.Exit,mode:v.DEFAULT,description:"[q] exit context",action:()=>(T.enterParentNode(),l("Exiting context",null))},{intent:h.NavPreviousItem,mode:v.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:v.DEFAULT,action:()=>(T.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:v.DEFAULT,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:v.DEFAULT,action:()=>(T.navigateToNextContainer(),l("Navigating to next container",null))}];var Ug=500,Og=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),Qc=e=>{let t=Og(e);t&&ho(n=>(n+t).slice(0,Ug))};var _g=[v.COMMAND_LINE,v.PALETTE],$g=e=>[{intent:h.MoveCursorLeft,mode:e,action:()=>(Xs(-1),l("Moving cursor left",null))},{intent:h.MoveCursorRight,mode:e,action:()=>(Xs(1),l("Moving cursor right",null))},{intent:h.MoveCursorLeftOfWord,mode:e,action:()=>(Js("left"),l("Moving cursor left of word",null))},{intent:h.MoveCursorRightOfWord,mode:e,action:()=>(Js("right"),l("Moving cursor right of word",null))},{intent:h.AutoCompleteCommand,mode:e,action:()=>(ho((t,{remainder:n})=>{let r=n?t+n:t,o="";return r==="edit title "&&(o=g().selectedNode?.title??""),r+o}),l("Auto-completing command",null))},{intent:h.CaptureInput,mode:e,action:(t,{sequence:n})=>(Qc(n??""),l("Capturing input",null))},{intent:h.EraseInput,mode:e,action:()=>(Hd(),l("Erasing input",null))},{intent:h.EraseInputWord,mode:e,action:()=>(Wd(),l("Erasing input word",null))}],Zc=[{intent:h.Confirm,mode:v.COMMAND_LINE,action:()=>(vt(),l("Executing command",null))},{intent:h.ViewHelp,mode:v.DEFAULT,action:()=>(E({mode:v.HELP}),l("Viewing help",null))},..._g.flatMap($g),{intent:h.ExitCommandLine,mode:v.COMMAND_LINE,action:()=>(E({mode:v.DEFAULT}),l("Exiting command line",null))},{intent:h.GetLastCommandFromHistory,mode:v.COMMAND_LINE,action:()=>(Kd(),l("Getting last command from history",null))},{intent:h.GetNextCommandFromHistory,mode:v.COMMAND_LINE,action:()=>(Gd(),l("Getting next command from history",null))}];import nl from"chalk";var Oo=nl.dim.hex(y.secondary2)(": for command line"),el="q to exit",tl=`${nl.hex(y.accent)("m")} to confirm`,ui={[L.WORKSPACE]:[Oo],[L.BOARD]:[Oo],[L.BOARD+v.COMMAND_LINE]:[Oo],[L.SWIMLANE]:[Oo],[L.TICKET+v.HELP]:[el],[L.SWIMLANE+v.HELP]:[el],[L.TICKET]:[],[L.FIELD]:[],[L.SWIMLANE+v.MOVE]:[tl],[L.TICKET+v.MOVE]:[tl]};var br=e=>e.trim().toLocaleLowerCase(),Hg=e=>{let{tags:t}=g();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},Wg=e=>{let{contributors:t}=g();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},rl=(e,t)=>{let n=br(t.value);if(!n)return!0;switch(t.target){case"title":return br(e.title??"").includes(n);case"description":return br(e.props.description??"").includes(n);case"tag":return Hg(e).map(br).some(o=>o.includes(n));case"assignee":return Wg(e).map(br).some(o=>o.includes(n));case"ref":return Ea(e.id,t.value);default:return!0}};function ol(e,t,n){let r=t[e];if(!r)return a("buildBreadCrumb(): current node not found");let o=[],s=r;for(;s&&(o.push(s),!(s.id===n||!s.parentNodeId));)s=t[s.parentNodeId];let i=o[o.length-1];return!i||i.id!==n?a("buildBreadCrumb(): node is not connected to root"):(o.reverse(),l("Breadcrumb built",o))}var sl=e=>{let t={};for(let n of e)n.intent&&(t[n.mode]||(t[n.mode]={}),t[n.mode][n.intent]=n);return t};var gn,mi,pi=new Set,il=()=>{for(let e of pi)e()},Vg=e=>(pi.add(e),()=>pi.delete(e));function al(e){let{contextNodeId:t,mode:n,rootNodeId:r,nodes:o,filters:s}=e;if(!t)return a("derive(): contextNodeId is missing");if(!r)return a("derive(): rootNode is missing");if(!o[r])return a("derive(): unable to find root node");let c=o[t];if(!c)return a("Unable to derive state, contextNode not found");let u=ol(t,o,r);if(d(u))return logger.error(u.message),u;let m=u.value,{context:p}=c,f=ui[p+n]??ui[p]??[],b=[...Jc,...Kc[p]??[],...Zc],C=sl(b),N=Kg(o,s),A=N[t]?.[e.selectedIndex]??null;return l("Derived successfully",{...e,contextNode:c,breadCrumb:m,availableHints:f,availableActions:b,actionIndex:C,selectedNode:A,renderedChildrenIndex:N})}var g=()=>{if(!gn)throw new Error("State not initialized. Call initWorkspaceState() first.");return gn},Je=()=>gn?l("Retrieved state",gn):a("State not initialized. Call initWorkspaceState() first.");function rr(e){mi=e;let t=qe(process.cwd()),n=!1;if(!d(t)){let s=Lt(t.value);if(d(s))return a(s.message);n=!0}let r={readOnly:!1,filters:[],tags:{},contributors:{},mode:v.DEFAULT,nodes:{[e.id]:e},rootNodeId:e.id,contextNodeId:e.id,renderedChildrenIndex:{},selectedIndex:-1,syncStatus:{status:"synced",msg:""},eventLog:[],unappliedEvents:[],replay:null,timeMode:"live",hasProjectDefinition:n,hasInitializingEvents:!1,comments:{},attachments:{}},o=al(r);return d(o)?o:(gn=o.value,il(),l("State initialized",null))}function he(e){let t=g(),n=e(t),r=al(n);return d(r)?a(r.message??"Unable to update state"):(gn=r.value,il(),l("State updated",null))}var E=e=>he(t=>({...t,...e}));var H=()=>jg(Vg,g,g),Kg=(e,t)=>{let n={};for(let r of Object.values(e))R(r)&&t.length>0&&!t.every(o=>rl(r,o))||!r.parentNodeId||r.isDeleted||((!r.parentNodeId||!n[r.parentNodeId])&&(n[r.parentNodeId]=[]),n[r.parentNodeId].push(r));for(let r of Object.keys(n))n[r].sort((o,s)=>{let i=e[o.id],c=e[s.id];return!i||!c?0:i.rank.localeCompare(c.rank)});return n},G=e=>g()?.renderedChildrenIndex[e]??[],zt=()=>mi?rr(mi):a("Cannot reset state: no initial workspace found"),Rn=()=>gn!==void 0;var fi=e=>{Rn()&&(E({syncStatus:e}),nn({type:"sync-status",payload:e}))},_o=(e="Syncing...")=>{fi({status:"syncing",msg:e})},$o=(e="Synced")=>{fi({status:"synced",msg:e})},gi=e=>{fi({status:"failed",msg:e})},Qe=e=>(gi(e),a(e));import{decodeTime as rk}from"ulid";var Gg=async({cwd:e,ensureUpstream:t})=>{logger.debug("[sync] ensureSyncReady:start",{cwd:e,ensureUpstream:t});let n=X("getRepoRootDir",await dt(e));if(d(n))return a(n.message);let r=n.value;logger.debug("[sync] repo root",r);let o=X("getStateBranchRoot",Pe({repoRoot:r}));if(d(o))return a(o.message);let s=o.value;logger.debug("[sync] state branch root",s);let i=X("ensureInitialCommit",await ra(r));if(d(i))return a(i.message);logger.debug("[sync] initial commit result",{created:i.value}),logger.debug("[sync] bootstrapping state branch storage",{repoRoot:r,stateBranchRoot:s,ensureUpstream:t});let c=X("bootstrapStateBranchStorage",await ia({repoRoot:r,stateBranchRoot:s,ensureUpstream:t}));if(d(c))return a(c.message);logger.debug("[sync] bootstrap result",{bootstrapped:c.value,stateBranchRoot:s}),logger.debug("[sync] checking state branch git operation",{stateBranchRoot:s});let u=X("hasInProgressGitOperation(stateBranchRoot)",await Br(s));if(d(u))return a(u.message);if(logger.debug("[sync] state branch git operation check result",{inProgress:u.value}),u.value)return logger.info("[sync] state branch git operation in progress"),a("Cannot sync while a git operation is in progress in the state branch");logger.debug("[sync] ensuring state branch layout",{repoRoot:r,stateBranchRoot:s});let m=X("ensureStateBranchLayout",ea(r,s));return d(m)?a(m.message):(logger.debug("[sync] state branch layout ready"),logger.debug("[sync] ensureSyncReady:done",{repoRoot:r,stateBranchRoot:s,bootstrapped:c.value}),l("Sync preconditions satisfied",{repoRoot:r,stateBranchRoot:s,bootstrapped:c.value}))},zg=async({repoRoot:e,stateBranchRoot:t,ownEventFileName:n})=>{logger.debug("[sync] committing own event file from state branch",{ownEventFileName:n,stateBranchRoot:t}),logger.debug("[sync] staging own event file",{stateBranchRoot:t,ownEventFileName:n});let r=X("stageStateBranchOwnEventFile",await jr({stateBranchRoot:t,eventFileName:n}));if(d(r))return a(r.message);let o=X("stageStateBranchMediaFiles",await oa({stateBranchRoot:t}));if(d(o))return a(o.message);let s=X("hasStagedChanges(after stage)",await zi(t));if(d(s))return a(s.message);if(logger.debug("[sync] state branch change check after stage result",{changed:s.value}),!s.value)return logger.info("[sync] no own event file changes to commit"),l("No own event file changes to commit",{createdCommit:!1});logger.debug("[sync] creating sync commit");let i=X("createStateBranchSyncCommit",await sa({repoRoot:e,stateBranchRoot:t}));return d(i)?a(i.message):(logger.debug("[sync] created sync commit",i.value),l("Committed own event file",{createdCommit:!0,commitSha:i.value}))},io=async({cwd:e=process.cwd(),ownEventFileName:t})=>{if(logger.debug("[sync] syncEpiqWithRemote:start",{cwd:e,ownEventFileName:t}),t.includes("/")||t.includes("\\"))return logger.error("[sync] invalid own event file name: contains path separator",{ownEventFileName:t}),a("Own event file must be a file name, not a path");if(!t.endsWith(".jsonl"))return logger.error("[sync] invalid own event file name: missing .jsonl suffix",{ownEventFileName:t}),a("Own event file must end with .jsonl");_o();let n=X("ensureSyncReady",await Gg({cwd:e,ensureUpstream:!0}));if(d(n))return Qe(n.message);let{repoRoot:r,stateBranchRoot:o,bootstrapped:s}=n.value,i=X("isDetachedHead(stateBranchRoot)",await qi(o));if(d(i))return Qe(i.message);if(logger.debug("[sync] detached state branch check result",{detached:i.value}),i.value)return Qe("Cannot run :sync while the state branch is in detached HEAD state");let c=!1,u,m=!1,p=!1,f=X("getStateBranch",hn(r));if(d(f))return Qe(f.message);let b=f.value;logger.debug("[sync] resolved state branch",{stateBranch:b,stateBranchRoot:o});let C=X("commitOwnEventFileToStateBranch",await zg({repoRoot:r,stateBranchRoot:o,ownEventFileName:t}));if(d(C))return Qe(C.message);c=C.value.createdCommit,u=C.value.commitSha;let N=X("pullBranchRebaseIfPresent",await xs({cwd:o,branch:b}));if(d(N))return Qe(N.message);if(m=N.value,c||s){logger.info("[sync] pushing state branch",{createdCommit:c,bootstrapped:s,stateBranchRoot:o});let A=X("pushStateBranch",await Qn({stateBranchRoot:o,repoRoot:r}));if(d(A)&&Gi(A.message)){let M=X("pullBranchRebaseIfPresent(retry)",await xs({cwd:o,branch:b}));if(d(M))return Qe(M.message);m=m||M.value,A=X("pushStateBranch(retry)",await Qn({stateBranchRoot:o,repoRoot:r}))}if(d(A))return Qe(A.message);p=A.value}if(c){logger.debug("[sync] resolving final sync commit sha",{stateBranchRoot:o});let A=X("git rev-parse HEAD",await _({args:["rev-parse","HEAD"],cwd:o}));if(d(A))return Qe(A.message);u=A.value.stdout.trim(),logger.debug("[sync] final sync commit sha",u)}return $o(p?"Synced and pushed":m||c?"Synced local state":"Already synced"),logger.debug("[sync] syncEpiqWithRemote:done"),l("Synced event logs with state branch",{repoRoot:r,stateBranchRoot:o,createdCommit:c,commitSha:u,pulled:m,pushed:p,bootstrapped:s})};var vi=()=>{let e=wn();return d(e)?mt:e.value.attachmentMaxKb??mt},yi=e=>{let t=qe(e??process.cwd());return d(t)?a(t.message):l("Resolved Epiq repo root",t.value)},Me=async(e,t)=>{let n=yi(e);if(d(n))return n;let r=Pe({repoRoot:n.value});if(d(r))return a(r.message);let o=yn(),s=await tn({repoRoot:n.value,stateBranchRoot:r.value,stateBranchName:o.stateBranch});if(d(s))return a(s.message);if(t?.pull??!1){let u=await _({cwd:r.value,args:["pull","--ff-only"]});d(u)&&se.info(3,u.message)}let i=Et(r.value);if(d(i))return a(i.message);let c=an(i.value);return d(c)?a(c.message):l("Booted Epiq state",{repoRoot:n.value,stateBranchRoot:r.value})},ke=()=>{let e=wn();return d(e)?a(e.message):e.value.userId?e.value.userName?l("Resolved actor",{userId:e.value.userId,userName:e.value.userName}):a("Unable to retrieve user name"):a("Unable to retrieve user id")},Oe=()=>{let e=Je();return d(e)?a(e.message):e},cl=e=>(e.props.tags??[]).map(t=>I.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:ue(t.name)})),ll=e=>(e.props.assignees??[]).map(t=>I.getContributor(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:ue(t.name)}));var ul=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=Oe();if(d(n))return n;let r=n.value.nodes,o=Object.values(r).filter(R).filter(s=>!s.isDeleted).filter(s=>e.includeClosed||s.parentNodeId!==pe).filter(s=>e.boardId?(s.parentNodeId?r[s.parentNodeId]:void 0)?.parentNodeId===e.boardId:!0).map(s=>({id:s.id,ref:Ue(s.id),title:Xe(s.title),description:s.props.description??"",parentNodeId:s.parentNodeId,isClosed:s.parentNodeId===pe,readonly:!!s.readonly,tags:cl(s),assignees:ll(s)}));return l("Listed issues",o)},ml=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=Nn(e.parentId,n.value,t.value.stateBranchRoot);if(d(o))return o;let s=Mo({name:e.title,parent:e.parentId,user:n.value,rank:o.value});if(d(s))return s;let i=[...s.value],c=i.find(f=>f.action==="add.issue")?.payload.id;if(!c)return a("Unable to determine created issue id");e.description&&i.push({id:J(),...n.value,action:"edit.description",payload:{id:c,md:e.description}});let u=[];for(let f of e.tagNames??[]){let b=Xe(f).trim();if(!b||u.some(A=>A.name===b))continue;let C=Object.values(r.value.tags).find(A=>A.name===b),N=C?.id??J();C||i.push({id:J(),...n.value,action:"create.tag",payload:{id:N,name:b}}),i.push({id:J(),...n.value,action:"add.issue.tag",payload:{id:c,tag:N}}),u.push({id:N,name:b})}let m=[];for(let f of e.assigneeNames??[]){let b=Xe(f).trim();if(!b||m.some(A=>A.name===b))continue;let C=Object.values(r.value.contributors).find(A=>A.name===b),N=C?.id??J();C||i.push({id:J(),...n.value,action:"create.contributor",payload:{id:N,name:b}}),i.push({id:J(),...n.value,action:"add.issue.assignee",payload:{id:c,assignee:N}}),m.push({id:N,name:b})}let p=B(i,t.value.stateBranchRoot);return d(p)?a(p.message):l("Created issue",{id:c,title:e.title,parentId:e.parentId,description:e.description??"",tags:u,assignees:m})},pl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=sn(pe,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(r))return r;let o={id:J(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:pe,rank:r.value}},s=B([o],t.value.stateBranchRoot);return d(s)?a(s.message):l("Closed issue",{id:e.issueId})},fl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Target node is not issue");if(o.parentNodeId!==pe)return a("Issue is not closed");let s=Ro(o);if(!s)return a("Unable to resolve previous parent from issue history");if(s===pe)return a("Previous parent resolves to closed swimlane");let i=r.value.nodes[s];if(!i)return a("Previous parent no longer exists");let c=sn(i.id,o.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let u={id:J(),...n.value,action:"reopen.issue",payload:{id:o.id,parent:i.id,rank:c.value}},m=B([u],t.value.stateBranchRoot);return d(m)?a(m.message):l("Reopened issue",{id:o.id,parentId:i.id})},gl=async e=>{let t=yi(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=Pe({repoRoot:t.value});if(d(r))return r;let o=Et(r.value);if(d(o))return o;let s=an(o.value);if(d(s))return s;let i=sn(e.parentId,e.issueId,e.position??{at:"end"},n.value,r.value);if(d(i))return i;let c={id:J(),...n.value,action:"move.node",payload:{id:e.issueId,parent:e.parentId,rank:i.value}},u=B([c],r.value);return d(u)?a(u.message):l("Moved issue",{id:e.issueId,parentId:e.parentId})};var Ho=async(e={})=>{_o();let t=yi(e.repoRoot);if(d(t))return a("Sync failed");let n=ke();if(d(n))return n;let r=await io({cwd:t.value,ownEventFileName:on(n.value)});return d(r)?(gi(r.message),r):($o(),l("Synced",r.value))};var yt=async(e={})=>{let t=await Me(e.repoRoot,{pull:!0});if(d(t))return t;let n=Oe();if(d(n))return n;let r=Object.values(n.value.nodes),o=r.filter(f=>Kr(f)&&!f.isDeleted),s=new Map,i=new Map;for(let f of r)if(!f.isDeleted){if(Dt(f)&&f.parentNodeId){let b=s.get(f.parentNodeId)??[];b.push(f),s.set(f.parentNodeId,b)}if(R(f)&&f.parentNodeId){let b=i.get(f.parentNodeId)??[];b.push(f),i.set(f.parentNodeId,b)}}let c=wn();if(d(c))return c;let u={};for(let f of r.filter(R))f.isDeleted||(u[f.id]=I.getCommentsByIssue(f.id).map(b=>{let C=I.getContributor(b.authorId);return{id:b.id,issueId:b.issue,body:b.md,author:{id:b.authorId,name:C?.name??"Unknown",color:ue(C?.name??b.authorId)},createdAt:dl(b.id)}}));let m=new Map;for(let f of n.value.eventLog)f.action==="add.issue.attachment"&&m.set(f.payload.id,f.payload.author);let p={};for(let f of r.filter(R))f.isDeleted||(p[f.id]=I.getAttachmentsByIssue(f.id).map(b=>({id:b.id,issueId:b.issue,name:b.name,fileName:Mn(b.hash,b.ext),bytes:b.bytes,createdAt:dl(b.id),canDelete:m.get(b.id)===c.value.userId})));return l("Retrieved Epiq GUI state",{boards:o.sort((f,b)=>f.rank.localeCompare(b.rank)).map(f=>({id:f.id,ref:Ue(f.id),title:f.title,swimlanes:(s.get(f.id)??[]).sort((b,C)=>b.rank.localeCompare(C.rank)).map(b=>({id:b.id,title:b.title,readonly:!!b.readonly,issues:(i.get(b.id)??[]).sort((C,N)=>C.rank.localeCompare(N.rank)).map(C=>({id:C.id,ref:Ue(C.id),title:Xe(C.title),description:C.props.description??"",readonly:!!C.readonly,tags:cl(C),assignees:ll(C),parentNodeId:C.parentNodeId,isClosed:C.parentNodeId===pe})),parentNodeId:b.parentNodeId}))})),tags:Object.values(n.value.tags).map(f=>({...f,color:ue(f.name)})),contributors:Object.values(n.value.contributors).map(f=>({...f,color:ue(f.name)})),user:{name:c.value.userName??"",id:c.value.userId??"",color:ue(c.value.userName??"")},commentsByIssueId:u,attachmentsByIssueId:p,attachmentMaxKb:vi()})},vl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=o.props.description??"";if(s===e.description)return l("No changes made",{id:e.issueId,description:s});let i={id:J(),...n.value,action:"edit.description",payload:{id:e.issueId,md:e.description}},c=B([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue description",{id:e.issueId,description:e.description})},yl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=Xe(e.title);if(!s.trim())return a("Issue title cannot be empty");if(o.title===s)return l("No changes made",{id:e.issueId,title:s});let i={id:J(),...n.value,action:"edit.title",payload:{id:e.issueId,name:s}},c=B([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue title",{id:e.issueId,title:s})},hl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Tag target must be an issue");if(o.readonly)return a("Cannot tag readonly issue");let s=Xe(e.tagName).trim();if(!s)return a("Tag name cannot be empty");let i=Object.values(r.value.tags).find(p=>p.name===s),c=i?.id??J(),u=[...i?[]:[{id:J(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:J(),...n.value,action:"add.issue.tag",payload:{id:e.issueId,tag:c}}],m=B(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue tag",{id:e.issueId,tag:{id:c,name:s}})},xl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Untag target must be an issue");if(o.readonly)return a("Cannot untag readonly issue");if(!r.value.tags[e.tagId])return a("Tag not found");let s={id:J(),...n.value,action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},i=B([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue tag",{id:e.issueId,tagId:e.tagId})},bl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Assign target must be an issue");if(o.readonly)return a("Cannot assign readonly issue");let s=Xe(e.assigneeName).trim();if(!s)return a("Assignee name cannot be empty");let i=Object.values(r.value.contributors).find(p=>p.name===s),c=i?.id??J(),u=[...i?[]:[{id:J(),...n.value,action:"create.contributor",payload:{id:c,name:s}}],{id:J(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:c}}],m=B(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue assignee",{id:e.issueId,assignee:{id:c,name:s}})},Il=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Unassign target must be an issue");if(o.readonly)return a("Cannot unassign readonly issue");if(!r.value.contributors[e.assigneeId])return a("Assignee not found");let s={id:J(),...n.value,action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},i=B([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue assignee",{id:e.issueId,assigneeId:e.assigneeId})},Wo=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Comment target must be an issue");if(o.readonly)return a("Cannot comment on readonly issue");let s=e.body.trim();if(!s)return a("Comment cannot be empty");let i=J(),c={id:J(),...n.value,action:"add.issue.comment",payload:{id:i,issue:e.issueId,md:s,author:n.value.userId}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Added issue comment",{id:i,issueId:e.issueId,body:s})},jo=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.eventLog.find(m=>m.action==="add.issue.comment"&&m.payload.id===e.commentId);if(!o)return a("Unable to resolve comment");if(o.payload.author!==n.value.userId)return a("You can only delete your own comments");let s=r.value.nodes[o.payload.issue];if(!s)return a("Issue not found");if(!R(s))return a("Comment target must be an issue");if(s.readonly)return a("Cannot delete comment on readonly issue");if(r.value.eventLog.some(m=>m.action==="delete.issue.comment"&&m.payload.id===e.commentId))return l("Comment already deleted",{id:e.commentId,issueId:o.payload.issue});let c={id:J(),...n.value,action:"delete.issue.comment",payload:{id:e.commentId,issue:o.payload.issue}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue comment",{id:e.commentId,issueId:o.payload.issue})},El=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Attachment target must be an issue");if(o.readonly)return a("Cannot attach to readonly issue");let s=Buffer.from(e.dataBase64??"","base64"),i=Ad(t.value.stateBranchRoot,s,vi());if(d(i))return i;let c=Xe(e.name??"").trim()||"image",u=J(),m={id:J(),...n.value,action:"add.issue.attachment",payload:{id:u,issue:e.issueId,author:n.value.userId,hash:i.value.hash,ext:i.value.ext,name:c,bytes:i.value.bytes}},p=B([m],t.value.stateBranchRoot);return d(p)?a(p.message):l("Added issue attachment",{id:u,issueId:e.issueId,fileName:Mn(i.value.hash,i.value.ext),bytes:i.value.bytes})},Sl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.eventLog.find(m=>m.action==="add.issue.attachment"&&m.payload.id===e.attachmentId);if(!o)return a("Unable to resolve attachment");if(o.payload.author!==n.value.userId)return a("You can only delete your own attachments");let s=r.value.nodes[o.payload.issue];if(!s)return a("Issue not found");if(!R(s))return a("Attachment target must be an issue");if(s.readonly)return a("Cannot delete attachment on readonly issue");if(r.value.eventLog.some(m=>m.action==="delete.issue.attachment"&&m.payload.id===e.attachmentId))return l("Attachment already deleted",{id:e.attachmentId,issueId:o.payload.issue});let c={id:J(),...n.value,action:"delete.issue.attachment",payload:{id:e.attachmentId,issue:o.payload.issue}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue attachment",{id:e.attachmentId,issueId:o.payload.issue})},Cl=async e=>{let t=await Me(e.repoRoot,{pull:!1});return d(t)?t:Rd(t.value.stateBranchRoot,e.fileName,vi())};var Nl=e=>{let t,n,r=!1,o=!1,s=!1,i=()=>{let p=dr();if(d(p))return se.error(p.message);let{autoSync:f,userName:b,preferredEditor:C}=p.value;return!!(f&&b&&C)},c=async()=>{if(!r){if(o){s=!0;return}o=!0;try{await Ho({repoRoot:e.repoRoot}),nn({type:"state",payload:await yt({repoRoot:e.repoRoot})})}finally{o=!1,s&&(s=!1,c())}}},u=(p=750)=>{r||(n&&clearTimeout(n),n=setTimeout(()=>{c()},p))},m=()=>{if(r)return;let p=dr();if(d(p))return se.error(p.message);let{autoSyncDebounceMs:f}=p.value;i()&&(t=setTimeout(()=>{c(),m()},f??15e3))};return m(),{scheduleSync:u,dispose:()=>{r=!0,t&&clearTimeout(t),n&&clearTimeout(n)}}};import{WebSocketServer as qg}from"ws";var Ve=(e,t)=>{e.send(JSON.stringify(t))},Ir=async(e,t)=>Ve(e,{type:"state",payload:await yt({repoRoot:t})}),ht=async(e,t,n,r,o)=>{if(Ve(e,{type:r,payload:o}),d(o))return Ve(e,{type:"failed",payload:o.message});n(),Ir(e,t)},Al=(e,t,{onStateChanged:n})=>{new qg({server:e,path:"/ws"}).on("connection",o=>{aa(o),o.on("message",async s=>{try{let i=JSON.parse(s.toString()),{type:c}=i;if(c==="state:get")return Ir(o,t);if(c==="sync"){let u=await Ho({repoRoot:t});return Ve(o,{type:"sync:result",payload:u}),n(),Ir(o,t)}if(c==="issue:comment:add"){let u=await Wo({repoRoot:t,...i.payload});return ht(o,t,n,"issue:comment:add:result",u)}if(c==="issue:comment:delete"){let u=await jo({repoRoot:t,...i.payload});return Ve(o,{type:"issue:comment:delete:result",payload:u}),d(u)?Ve(o,{type:"failed",payload:u.message}):(n(),Ir(o,t))}if(c==="issue:edit:description"){let u=await vl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:edit:description:result",u)}if(c==="issue:edit:title"){let u=await yl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:edit:title:result",u)}if(c==="issue:tag:add"){let u=await hl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:tag:add:result",u)}if(c==="issue:tag:remove"){let u=await xl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:tag:remove:result",u)}if(c==="issue:assignee:add"){let u=await bl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:assignee:add:result",u)}if(c==="issue:assignee:remove"){let u=await Il({repoRoot:t,...i.payload});return ht(o,t,n,"issue:assignee:remove:result",u)}if(c==="issues:list")return Ve(o,{type:"issues",payload:await ul({repoRoot:t})});if(c==="issues:create"){let u=await ml({...i.payload,repoRoot:t});return Ve(o,{type:"issues:create:result",payload:u}),d(u)?nn({type:"failed",payload:u.message}):(nn({type:"issue:created",payload:u.value}),n(),Ir(o,t))}if(c==="issues:move"){if(!i.payload.position)return Ve(o,{type:"error",message:"Missing move position"});let u=await gl({...i.payload,repoRoot:t});return ht(o,t,n,"issues:move:result",u)}if(c==="issue:close"){if(!i.payload.issueId)return Ve(o,{type:"error",message:"Missing issueId"});let u=await pl({repoRoot:t,issueId:i.payload.issueId});return ht(o,t,n,"issue:close:result",u)}if(c==="issue:reopen"){if(!i.payload.issueId)return Ve(o,{type:"error",message:"Missing issueId"});let u=await fl({repoRoot:t,issueId:i.payload.issueId});return ht(o,t,n,"issue:reopen:result",u)}return Ve(o,{type:"error",message:"Unknown message type"})}catch(i){return Ve(o,{type:"error",message:i instanceof Error?i.message:String(i)})}})})};var Jg=vn.dirname(Xg(import.meta.url)),Qg=process.env.IS_LOCAL==="true"?vn.resolve(process.cwd(),"dist/gui"):vn.join(Jg,"gui"),Vo,Zg=async()=>(Vo===void 0&&(Vo=await import("node:sea").catch(()=>null)),Vo?.isSea()?Vo:null),ve=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},Rl=async(e,t=1024*1024)=>new Promise((n,r)=>{let o="",s=0;e.on("data",i=>{if(s+=i.length,s>t){e.destroy(),r(new Error("Request body too large"));return}o+=i}),e.on("end",()=>{try{n(o?JSON.parse(o):{})}catch{r(new Error("Invalid JSON body"))}}),e.on("error",r)}),ev=2*1024*1024,tv={png:"image/png",jpg:"image/jpeg",gif:"image/gif",webp:"image/webp"},nv=e=>e.endsWith(".html")?"text/html; charset=utf-8":e.endsWith(".js")?"text/javascript; charset=utf-8":e.endsWith(".css")?"text/css; charset=utf-8":e.endsWith(".json")?"application/json; charset=utf-8":e.endsWith(".ico")?"image/x-icon":"application/octet-stream",Tl=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),r=vn.resolve(Qg),o=vn.resolve(r,n),s=vn.relative(r,o);if(s.startsWith("..")||vn.isAbsolute(s))return ve(t,403,{isError:!0,message:"Forbidden"});let i=await Zg();try{let c=i?Buffer.from(i.getAsset(`gui/${s}`)):await wl(o);return t.writeHead(200,{"content-type":nv(o)}),t.end(c)}catch{return ve(t,404,{isError:!0,message:`Not found: ${n}`})}},rv=async(e,t=3710)=>new Promise((n,r)=>{let o=s=>{let i=u=>{if(e.off("listening",c),u.code==="EADDRINUSE"&&s===t){e.removeListener("error",i),o(0);return}r(u)},c=()=>{e.off("error",i);let u=e.address();if(!u||typeof u=="string"){r(new Error("Unable to resolve address"));return}n(u.port)};e.once("error",i),e.once("listening",c),e.listen(s,"127.0.0.1")};o(t)}),Ml=async e=>{let t=Yg.createServer(async(o,s)=>{let i=new URL(o.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return ve(s,200,await yt({repoRoot:e.repoRoot}));if(o.method==="POST"&&i.pathname==="/api/comments")try{let c=await Rl(o);if(!c.issueId||!c.body?.trim())return ve(s,400,{isError:!0,message:"Missing issueId or body"});let u=await Wo({repoRoot:e.repoRoot,issueId:c.issueId,body:c.body});return"isError"in u&&u.isError?ve(s,400,u):ve(s,200,await yt({repoRoot:e.repoRoot}))}catch(c){return ve(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add comment"})}if(o.method==="POST"&&i.pathname==="/api/attachments")try{let c=await Rl(o,ev);if(!c.issueId||!c.dataBase64)return ve(s,400,{isError:!0,message:"Missing issueId or dataBase64"});let u=await El({repoRoot:e.repoRoot,issueId:c.issueId,name:c.name??"",dataBase64:c.dataBase64});return d(u)?ve(s,400,{isError:!0,message:u.message}):ve(s,200,await yt({repoRoot:e.repoRoot}))}catch(c){return ve(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add attachment"})}if(o.method==="DELETE"&&i.pathname.startsWith("/api/attachments/")){let c=decodeURIComponent(i.pathname.replace("/api/attachments/",""));if(!c)return ve(s,400,{isError:!0,message:"Missing attachment id"});let u=await Sl({repoRoot:e.repoRoot,attachmentId:c});return d(u)?ve(s,400,{isError:!0,message:u.message}):ve(s,200,await yt({repoRoot:e.repoRoot}))}if(o.method==="GET"&&i.pathname.startsWith("/media/")){let c=decodeURIComponent(i.pathname.replace("/media/","")),u=await Cl({repoRoot:e.repoRoot,fileName:c});if(d(u))return ve(s,404,{isError:!0,message:u.message});try{let m=await wl(u.value.filePath);return s.writeHead(200,{"content-type":tv[u.value.ext]??"application/octet-stream","cache-control":"public, max-age=31536000, immutable"}),s.end(m)}catch{return ve(s,404,{isError:!0,message:"Attachment blob not found"})}}if(o.method==="DELETE"&&i.pathname.startsWith("/api/comments/")){let c=decodeURIComponent(i.pathname.replace("/api/comments/",""));if(!c)return ve(s,400,{isError:!0,message:"Missing comment id"});let u=await jo({repoRoot:e.repoRoot,commentId:c});return"isError"in u&&u.isError?ve(s,400,u):ve(s,200,await yt({repoRoot:e.repoRoot}))}return i.pathname.startsWith("/board/")?Tl("/",s):Tl(i.pathname,s)});try{await rv(t)}catch(o){return a(o instanceof Error?`Unable to start GUI server: ${o.message}`:`Unable to start GUI server: ${String(o)}`)}let n=Nl({repoRoot:e.repoRoot});Al(t,e.repoRoot,{onStateChanged:()=>n.scheduleSync()}),t.on("close",n.dispose);let r=t.address();return!r||typeof r=="string"?(t.close(),a("Unable to resolve GUI server address")):l("Started GUI server",{url:`http://epiq.localhost:${r.port}${e.boardId?`/board/${e.boardId}`:""}`,server:t})};var Pl=async e=>{let t=await Ml({...e,boardId:""});if(d(t))return t;let{url:n}=t.value;return console.log(`Epiq GUI running at ${ov.cyan(n)}`),Di(n),l("Started GUI",{url:n})};import{Box as Qt}from"ink";import de from"react";import{Box as hi,Text as Er}from"ink";import ot,{useEffect as sv,useMemo as iv}from"react";import{ulid as av}from"ulid";var Ll=({text:e,match:t,color:n,highlightColor:r=y.secondary,dimColor:o=!1})=>{if(!t)return ot.createElement(Er,{color:n,dimColor:o},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?ot.createElement(Er,{color:n,dimColor:o},e):ot.createElement(Er,{color:n,dimColor:o},e.slice(0,c),ot.createElement(Er,{backgroundColor:r,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},kl=av(),dv=e=>`${e}`,cv=e=>{let{pendingNavTarget:t}=Vt();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,s=new Set(ae(x.NONE,{breadCrumb:n,contextNode:r,readOnly:g().readOnly,selectedNode:o}));return[...new Set(Object.values(x))].filter(i=>i!=="move").filter(i=>i.length>0).filter(i=>i!==x.PALETTE).map(i=>{let c=xo(i),u=Fo.find(m=>m.intent===c);return{command:i,description:u?.description??`[${i}] Run command`,isAvailable:s.has(i)}}).filter(i=>i.command.toLowerCase().startsWith(e)||e.length>=2&&i.description.toLowerCase().includes(e)).sort((i,c)=>i.isAvailable!==c.isAvailable?i.isAvailable?-1:1:i.command.localeCompare(c.command))},lv=e=>Z.text({id:kl,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),uv=(e,t,n)=>Z.text({id:dv(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),xi=[],mv=e=>{Dl();let t=I.createNode(lv(g().rootNodeId));d(t)||!kt(t.value)||(xi=[t.value,...e.map((n,r)=>uv(n,r,kl)).map(I.createNode).filter(ne).map(({value:n})=>n).filter(kt)],T.navigate({contextNode:t.value,selectedIndex:0}))},Dl=()=>{let e=xi.map(t=>t.id);xi=[];for(let t of e)I.deleteNode(t)};function Fl({width:e,height:t}){let r=zd().value.trim().toLowerCase(),o=iv(()=>cv(r),[r]);sv(()=>(mv(o),()=>{Dl()}),[o]);let s=g().selectedIndex;return ot.createElement(hi,{flexDirection:"column",width:e,height:t-2},ot.createElement(et,{height:t-4,itemHeight:3,selectedIndex:s},o.map((i,c)=>{let u=c===s,m=i.isAvailable?y.accent:y.secondary2,p=i.isAvailable?"":"[unavailable] ";return ot.createElement(hi,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:y.secondary,borderStyle:"single"},ot.createElement(Er,{color:m,dimColor:!i.isAvailable},u?"\u276F ":" ",ot.createElement(Ll,{text:pa(i.command),match:r,color:m,dimColor:!i.isAvailable})),ot.createElement(hi,{paddingLeft:2},ot.createElement(Ll,{text:p+i.description,match:r.length>=2?r:"",color:u&&i.isAvailable?y.primary:y.secondary2,dimColor:!i.isAvailable})))})))}import{Box as wv}from"ink";import zo from"react";import Cr from"chalk";import{Box as bi,Text as Bl}from"ink";import Sr,{useEffect as pv,useMemo as fv,useState as gv}from"react";var Ul=Cr.hex(y.secondary),vv=Cr.inverse,yv=Cr.inverse.hex(y.secondary2),hv={hint:"",hints:[],overlap:0,remainder:""},_l=({value:e,command:t})=>{if(!t)return null;let n=e.trimStart(),o=e.length-n.length;return e.slice(o,o+t.length)!==t?null:{start:o,end:o+t.length}},xv=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=ue(t);return{bg:r=>Cr.bgHex(n).black(r),bgCursor:r=>Cr.bgHex(n).inverse.black(r)}}return ws(t)},bv=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=_l({value:e,command:t});if(!r)return null;let s=e.slice(r.end).match(/^\s*/)?.[0].length??0,i=r.end+s;return e.slice(i,i+n.length)!==n?null:{start:i,end:i+n.length}},Ol=()=>({value:Ae.value,cursorPosition:Ae.cursorPosition,commandIsPending:Ae.commandIsPending,autoCompletion:Ae.commandMeta.autoCompletion??hv,infoMessage:Ae.commandMeta.infoMessage,validationStatus:Ae.commandMeta.validity,command:Ae.commandMeta.command,inputString:Ae.commandMeta.inputString,modifier:Ae.commandMeta.modifier}),Iv=(e,t)=>e.value===t.value&&e.cursorPosition===t.cursorPosition&&e.commandIsPending===t.commandIsPending&&e.infoMessage===t.infoMessage&&e.autoCompletion.hint===t.autoCompletion.hint&&e.autoCompletion.overlap===t.autoCompletion.overlap&&e.autoCompletion.remainder===t.autoCompletion.remainder&&e.validationStatus===t.validationStatus&&e.command===t.command&&e.modifier===t.modifier&&e.inputString===t.inputString,$l=({width:e,mode:t})=>{let[n,r]=gv(Ol());pv(()=>{let N=()=>{let M=Ol();r(U=>Iv(U,M)?U:M)},A=Ys(N);return N(),()=>{A()}},[]);let{value:o,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:u,command:m,modifier:p,validationStatus:f}=n,b=c&&f===pt.Invalid,C=fv(()=>{let N=Math.max(0,Math.min(s,o.length)),A=_l({value:o,command:m}),M=bv({value:o,command:m,modifier:p}),U=m?ws(m):null,j=xv({command:m,modifier:p}),D=(me,le)=>{let $n=A&&le>=A.start&&le<A.end,Hn=M&&le>=M.start&&le<M.end;return $n&&U?U.fg(me):Hn&&j?j.bg(me):me},z=(me,le)=>{let $n=A&&le>=A.start&&le<A.end,Hn=M&&le>=M.start&&le<M.end;return $n&&U?U.fgCursor(me):Hn&&j?j.bgCursor(me):vv(me)},$=o.slice(0,N),P=o[N]??" ",O=N<o.length?o.slice(N+1):"",Ge=Array.from($).map((me,le)=>D(me,le)).join(""),Ce=z(P,N),ze=Array.from(O).map((me,le)=>D(me,N+1+le)).join("");if(u.hint){let me=u.hint[u.overlap]??P;Ce=yv(me),ze=Ul(u.remainder.slice(1)+O)}return Ul(t===v.PALETTE?"?":":")+Ge+Ce+ze},[o,s,u,m,p]);return Sr.createElement(bi,{flexDirection:"column",justifyContent:"flex-start"},Sr.createElement(bi,{flexDirection:"column",paddingX:1,borderColor:y.secondary,borderStyle:"round",width:e},Sr.createElement(bi,null,Sr.createElement(Bl,null,C),i&&Sr.createElement(Bl,{wrap:"truncate",color:b?y.red:y.secondary2},` ${i} `))))};import{Box as Ev,Text as Sv}from"ink";import Hl from"react";var Cv=(e,t)=>{let n=[],r=0;for(let o of e){let i=(n.length>0?" | ":"").length+o.length;if(r+i>t-4)break;n.push(o),r+=i}return n},Wl=({width:e,availableHints:t})=>{let n=Cv(t,e).join(" | ");return Hl.createElement(Ev,{width:e,borderStyle:"round",borderColor:y.secondary,paddingX:1},Hl.createElement(Sv,{color:y.secondary2},n.length?n:"\xA0"))};import{Box as Nv,Text as Ko}from"ink";import Nr,{useEffect as Av,useRef as Un,useState as Rv}from"react";var Tv=40,Go=.3,Ii="\u2500",jl=1,Vl=16,Kl=({width:e})=>{let{replay:t}=H(),n=t!==null,r=t?Math.min(1,Math.max(0,t.progress)):0,s=Math.max(4,e-6),i=s*jl,[c,u]=Rv(0),m=Un(r);m.current=r;let p=Un(0),f=Un(0),b=Un(0),C=Un(0),N=Un(0);if(Av(()=>{if(!n){p.current=0,b.current=0,C.current=0,N.current=0,u(0);return}p.current=m.current,f.current=Date.now(),b.current=m.current;let D=setInterval(()=>{let z=Date.now(),$=m.current;if($!==b.current){let ze=$-b.current,me=z-f.current;if(ze<0)C.current=0,N.current=0;else if(ze>0&&me>0){let le=ze/me;C.current=C.current===0?le:C.current*(1-Go)+le*Go,N.current=N.current===0?ze:N.current*(1-Go)+ze*Go}p.current=$,f.current=z,b.current=$}let P=z-f.current,O=Math.min(N.current,C.current*P),Ge=Math.min(1,p.current+O),Ce=Math.round(Ge*i);u(ze=>ze===Ce?ze:Ce)},Tv);return()=>clearInterval(D)},[n,i]),!t)return null;let A=D=>{let z=s>1?D/(s-1):0,$=Math.round(z*(Vl-1))/(Vl-1);return zr($)},M=Math.min(s,Math.floor(c/jl)),U=[];for(let D=0;D<M;D++){let z=A(D),$=U[U.length-1];$&&$.color===z?$.text+=Ii:U.push({text:Ii,color:z})}let j=Ii.repeat(Math.max(0,s-M));return Nr.createElement(Nv,{width:e,borderStyle:"round",borderColor:y.secondary,paddingX:1,columnGap:1},Nr.createElement(Ko,{color:y.secondary2},"\u25B6"),Nr.createElement(Ko,null,U.map((D,z)=>Nr.createElement(Ko,{key:z,color:D.color},D.text)),Nr.createElement(Ko,{color:y.secondary,dimColor:!0},j)))};var Ar=({width:e,mode:t,availableHints:n})=>{let{timeMode:r}=H(),o=t===v.COMMAND_LINE||t===v.PALETTE;return zo.createElement(wv,null,o?zo.createElement($l,{width:e,mode:t}):r==="replay"?zo.createElement(Kl,{width:e}):zo.createElement(Wl,{width:e,mode:t,availableHints:n}))};import{Box as qt,Text as On}from"ink";import De,{useEffect as Mv,useMemo as Pv}from"react";import{ulid as Gl}from"ulid";var Yo=Gl(),Lv=()=>[...new Set([...g().availableActions].map(e=>e.description).filter(e=>e!==void 0))].map(e=>{let[t,n]=e.split("]"),r=t?.replace("[",""),o=n?.trim();return[r,o]}).filter(e=>e[0]!==void 0&&e[1]!==void 0).sort(([e],[t])=>e.length===1&&t.length!==1?-1:e.length!==1&&t.length===1?1:e.localeCompare(t,void 0,{sensitivity:"base"})).map(([e,t])=>({keys:e,action:t})),kv=e=>Z.text({id:Yo,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),Dv=(e,t,n)=>Z.text({id:Gl(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),qo=[],zl=()=>{let e=qo.filter(n=>n.id!==Yo).map(n=>n.id),t=qo.filter(n=>n.id===Yo).map(n=>n.id);qo=[];for(let n of[...e,...t])I.deleteNode(n)},Fv=e=>{zl();let t=I.createNode(kv(g().rootNodeId));if(d(t)||!kt(t.value))return logger.error("Could not attach help nodes");qo=[t.value,...e.map((n,r)=>Dv(n,r,Yo)).map(I.createNode).filter(ne).map(({value:n})=>n).filter(kt)],T.navigate({contextNode:t.value,selectedIndex:0})},ql=({width:e,height:t})=>{let n=Pv(()=>Lv(),[]);Mv(()=>(Fv(n),()=>{zl()}),[n]);let r=g().selectedIndex;return De.createElement(qt,{flexDirection:"column",marginTop:3,borderColor:y.secondary,borderStyle:"round",width:e,height:t-2},De.createElement(qt,{paddingX:1,justifyContent:"center"},De.createElement(On,{color:y.accent},"Help"),De.createElement(On,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),De.createElement(qt,{paddingX:1,marginTop:1},De.createElement(qt,{width:20,justifyContent:"flex-end"},De.createElement(On,{color:y.secondary},"Key(s)")),De.createElement(qt,{flexGrow:1,width:40,paddingLeft:2},De.createElement(On,{color:y.secondary},"Action"))),De.createElement(et,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:s},i)=>{let c=i===r;return De.createElement(qt,{paddingX:1,key:`${o}-${s}-${i}`,flexDirection:"row"},De.createElement(qt,{width:20,justifyContent:"flex-end"},De.createElement(On,{color:y.accent},o)),De.createElement(qt,{flexGrow:1,width:40,paddingLeft:2},De.createElement(On,{color:c?y.primary:y.secondary2},s)))})))};import Bv from"chalk";import{Box as Xo,Text as Mt}from"ink";import Ke from"react";var Yl=({width:e,height:t})=>Ke.createElement(Xo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},Ke.createElement(Mt,{color:y.accent,bold:!0},"Initialize project"),Ke.createElement(Mt,null,`This folder is not an ${Bv.hex(y.accent)("epiq")} project yet.`),Ke.createElement(Mt,{color:y.primary},"To start tracking issues here, we need to initialize a new",Ke.createElement(Mt,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json "),"file in this repository."),Ke.createElement(Xo,{marginTop:1,flexDirection:"column"},Ke.createElement(Xo,null,Ke.createElement(Mt,{color:y.accent}," "),Ke.createElement(Mt,{color:y.primary},"Type "),Ke.createElement(Mt,{backgroundColor:y.secondary}," :init "))),Ke.createElement(Xo,{marginTop:1},Ke.createElement(Mt,{color:y.secondary2},"This will create, commit and push "),Ke.createElement(Mt,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json ")));import{Box as Jo,Text as xt}from"ink";import Se from"react";var Uv=({isDone:e,command:t,value:n})=>Se.createElement(Jo,null,Se.createElement(xt,{color:y.accent,dimColor:e},e?" \u2714 ":" "),Se.createElement(xt,{dimColor:e},"Type "),Se.createElement(xt,{backgroundColor:y.secondary,dimColor:e}," "+t+" "),n!==void 0&&Se.createElement(Se.Fragment,null,Se.createElement(xt,{dimColor:e}," "),Se.createElement(xt,{color:y.secondary,dimColor:e},"<"+n+">"))),Ov=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function Ei({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:s,autoSync:i,isSetAutoSync:c}=_t(),u=[{key:"username",done:r,command:":config username",value:o,message:"First, choose your username."},{key:"editor",done:n,command:":config editor",value:s,message:"Nice. Now pick your editor."},{key:"autosync",done:c,command:":config autosync",value:i,message:"Almost there. Configure auto sync."}],m=u.findIndex(f=>!f.done),p=m===-1?void 0:u[m];return Se.createElement(Jo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},Se.createElement(xt,{color:y.accent,bold:!0},"Welcome! \u{1F539}"),Se.createElement(xt,null,"Let's get you started - it's a breeze."),Se.createElement(xt,{color:y.secondary2},"Remember - you can always search available commands by typing:",Se.createElement(xt,{color:y.accent}," ? ")),p&&Se.createElement(xt,{color:y.secondary2},p.message),Se.createElement(Jo,{flexDirection:"column"},u.map((f,b)=>m===-1||b<=m?Se.createElement(Jo,{key:f.key,marginBottom:1},Se.createElement(Uv,{isDone:f.done,command:f.command,value:f.done?Ov(f.value):void 0})):null)))}import ns from"chalk";import{Box as Tr,Text as _n}from"ink";import ye from"react";import{Box as Qo,Text as Xl}from"ink";import Yt from"react";import _v from"chalk";var $v=e=>(I.getTag(e)?.name??"").length+3,Hv=e=>(I.getContributor(e)?.name??"").length+3,Jl=({width:e})=>{let{viewMode:t}=K(),n=H(),{breadCrumb:r,contextNode:o,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[o.id]?.[s],u=It(c?.id??o.id,"TICKET"),m=ne(u)?u.value:void 0,p=m?.props.tags??[],f=m?.props.assignees??[],b=m?.parentNodeId?!As(o.id,m.parentNodeId)&&t==="dense":!1,C=r.map(($,P)=>{let O=P===r.length-1,Ge=q($.id),Ce=O?Ge?.[s]?.title:void 0;return`${P?" / ":""}${$.title??""}${Ce?` \u25B8 ${Ce}`:""}`}).join(""),N=m?I.getCommentsByIssue(m.id):[],A=N.length?String(N.length).length+11:0,M=b?p.reduce(($,P)=>$+$v(P),0)+f.reduce(($,P)=>$+Hv(P),0)+A:0,U=c?.id!=null&&!(t==="wide"&&R(c)),j=Math.max(0,e-M),D=C.substring(0,j)+(U?_v.hex(y.secondary2).dim(` ${Ue(c.id)}`):""),z=b?[...p.map($=>Yt.createElement(Qo,{key:`tag-${$}`,paddingLeft:1},Yt.createElement(kn,{id:$}))),...f.map($=>Yt.createElement(Qo,{key:`assignee-${$}`,paddingLeft:1},Yt.createElement(Wt,{id:$}))),N.length?Yt.createElement(Qo,{key:"comments",paddingLeft:1},Yt.createElement(Xl,{color:y.accent},"[",N.length," comment",N.length===1?"":"s","]")):null]:[];return Yt.createElement(Qo,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},Yt.createElement(Xl,{color:y.secondary2},D),z)};import{Box as Wv,Text as Ql}from"ink";import Zo from"react";var jv=({filters:e})=>Zo.createElement(Wv,{columnGap:1},Zo.createElement(Ql,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>Zo.createElement(Ql,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),Zl=Zo.memo(jv);import{Box as Vv,Text as es}from"ink";import Rr from"react";function eu(){let{eventLog:e,unappliedEvents:t}=H(),n=e.at(-1)?.id,r=Jr(n??""),o=ne(r)?Xr(r.value):"INVALID DATE";return Rr.createElement(Vv,{paddingLeft:1},Rr.createElement(es,{backgroundColor:y.accent,color:y.secondary}," Readonly "),Rr.createElement(es,{color:y.accent}," "+t.length+" edits ago at "+o+"."),Rr.createElement(es,{color:y.accent}," Resume with "),Rr.createElement(es,{backgroundColor:y.accent,color:y.secondary}," ",":peek now"," "))}import{Box as Kv,Text as Si}from"ink";import ts from"react";function tu(){let{replay:e}=H();if(!e)return null;let{appliedCount:t,totalCount:n,currentTime:r}=e;return ts.createElement(Kv,{paddingRight:2,columnGap:1,justifyContent:"flex-end"},ts.createElement(Si,{backgroundColor:y.accent,color:y.secondary}," \u25B6 REPLAY "),ts.createElement(Si,{color:y.secondary2},Xr(new Date(r))),ts.createElement(Si,{color:y.accent},`${t}/${n} edits`))}import Ci from"chalk";import{Box as Gv,Text as nu}from"ink";import Ni,{useEffect as zv,useState as qv}from"react";var Yv=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],Xv=150,ru=12,Jv=.36,ou=e=>{let t=e.replace("#","");return{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16)}},Qv=({r:e,g:t,b:n})=>{let r=o=>Math.round(Math.max(0,Math.min(255,o))).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(n)}`},Zv=(e,t,n)=>{let r=ou(e),o=ou(t);return Qv({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},ey=(e,t)=>{if(e.length===1)return e[0];let n=t*(e.length-1),r=Math.floor(n),o=n-r,s=e[r],i=e[Math.min(r+1,e.length-1)];return Zv(s,i,o)};function su({syncStatus:e,autoSync:t}){let[n,r]=qv(0);zv(()=>{if(e.status!=="syncing"){r(0);return}let c=0,u=setInterval(()=>{c+=1;let m=(Math.sin(c*Jv)+1)/2,p=Math.round(m*(ru-1));r(f=>f===p?f:p)},Xv);return()=>clearInterval(u)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:y.secondary2,failed:y.yellow,pending:y.secondary2,syncing:ey(Yv,n/(ru-1))??""}[e.status];return Ni.createElement(Gv,null,Ni.createElement(nu,null,Ci.hex(y.secondary2).dim(t?"Sync (auto): ":"Sync: ")),Ni.createElement(nu,null,Ci.hex(i)("\u25CF")+Ci.hex(y.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}import lu from"chalk";import{Text as uu}from"ink";import mu,{useEffect as oy,useState as sy}from"react";var Xt="1.3.4";import Ai from"chalk";var ty="https://registry.npmjs.org/epiq/latest",Ri=null,iu=0,ny=1e3*60*60*24,au=e=>e.replace(/^v/,""),ry=(e,t)=>{let n=au(e).split(".").map(Number),r=au(t).split(".").map(Number);for(let o=0;o<Math.max(n.length,r.length);o++){let s=n[o]??0,i=r[o]??0;if(s>i)return 1;if(s<i)return-1}return 0},du=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(Ri&&Date.now()-iu<ny)return Ri;try{let t=await fetch(ty);if(!t.ok)throw new Error(`Failed to fetch latest version: ${t.status}`);let r=(await t.json()).version??null,o={current:e,latest:r,updateAvailable:r?ry(r,e)>0:!1};return Ri=o,iu=Date.now(),o}catch{return{current:e,latest:null,updateAvailable:!1}}},cu=(e,t)=>{let n=e.split("."),r=t.split("."),o=r.findIndex((s,i)=>s!=n[i]);return r.map((s,i)=>i>=o?Ai.hex(y.accent).dim(s):Ai.hex(y.secondary).dim(s)).join(Ai.hex(y.secondary2).dim("."))};function pu(){let[e,t]=sy({current:Xt,latest:null,updateAvailable:!1});return oy(()=>{let n=!0;return du(Xt).then(r=>{n&&t(r)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?mu.createElement(uu,{dimColor:!0,color:y.secondary2},Xt+" "):mu.createElement(uu,null,lu.hex(y.secondary2).dim(Xt),lu.hex(y.accent).dim(" \u2197 "),cu(Xt,e.latest))}function wr({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o,replay:s}=H(),{userName:i,preferredEditor:c,autoSync:u}=K(),m=64,p=process.stdout.columns-m-8,f=t||n==="replay",b=s?rn(s.currentLabel,Math.max(0,p)):"";return ye.createElement(Tr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},n==="replay"?ye.createElement(Tr,{paddingLeft:1},ye.createElement(_n,{color:y.secondary2},b)):f?ye.createElement(_n,null," "):o===v.PALETTE?ye.createElement(Tr,null,ye.createElement(_n,{color:y.accent},"Command Palette"),ye.createElement(_n,{dimColor:!0,color:y.secondary2}," ","- search, select and press enter")):ye.createElement(Tr,{paddingLeft:1},e.length>0?ye.createElement(Zl,{filters:e}):ye.createElement(Jl,{width:p})),n==="live"?ye.createElement(Tr,{columnGap:1,paddingRight:2,"max-width":m,overflow:"hidden",justifyContent:"flex-end"},ye.createElement(su,{autoSync:!!u,syncStatus:r}),ye.createElement(_n,null,ns.hex(y.secondary2).dim("Mode: ")+ns.hex(y.secondary2).dim(o.padEnd(8," "))," "),ye.createElement(fu,{icon:"@",value:i}),ye.createElement(fu,{icon:"\u276F",value:c}),ye.createElement(pu,null)):"",n==="peek"?ye.createElement(eu,null):"",n==="replay"?ye.createElement(tu,null):"")}function fu({icon:e,value:t}){return ye.createElement(_n,null,ns.dim(e)+ns.hex(y.accent)(` ${t??"-"} `))}import{Box as iy,Text as ay}from"ink";import Mr from"react";import{Box as rs,Text as Ti}from"ink";import Jt from"react";function wi(){let e=H(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?G(t?.id):[];return Jt.createElement(rs,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:y.secondary,width:s},Jt.createElement(rs,{padding:1,paddingTop:0,paddingBottom:0},Jt.createElement(Ti,null,"Select a board:")),Jt.createElement(rs,{padding:1,flexDirection:"column"},i.map((c,u)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===u,f=G(c.id).flatMap(({id:b})=>q(b)).length;return Jt.createElement(rs,{key:c.id??u},Jt.createElement(Ti,{color:m?y.accent:y.secondary2},Jt.createElement(Re,{isSelected:m})),Jt.createElement(Ti,{color:m?y.accent:y.secondary2},c.title," (",f," issues)",c.readonly?" \u{1F512}":""))})))}var dy=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:s,width:i})=>{let{renderedChildrenIndex:c}=H(),u=n.find(({context:b})=>b==="BOARD"),f=s-1-3;return Mr.createElement(iy,{flexDirection:"row"},e.context==="WORKSPACE"?Mr.createElement(wi,null):u?Mr.createElement(Ao,{height:f,width:i,swimlanes:(c[u.id]??[]).filter(b=>b!==void 0&&Dt(b)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):Mr.createElement(ay,null))},gu=Mr.memo(dy);import{useEffect as cy}from"react";var ly=e=>{cy(()=>{if(!e)return;let t,n=!1,r=()=>{if(n)return;let{autoSyncIntervalMs:o,userName:s,preferredEditor:i}=K();i&&s&&o&&(t=setTimeout(()=>{if(n)return;let{readOnly:c,mode:u}=g();u==="default"&&!c&&ao(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},vu=({autoSync:e})=>(ly(e),null);function Mi({width:e,height:t}){let n=H(),{autoSync:r,viewMode:o}=xa(),s=n.filters;if(n.mode===v.HELP)return de.createElement(Qt,{flexDirection:"column"},de.createElement(ql,{width:e,height:t}));if(n.mode===v.PALETTE)return de.createElement(Qt,{flexDirection:"column"},de.createElement(wr,{filters:s}),de.createElement(Fl,{width:e,height:t-2}),de.createElement(Ar,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=_t(),c=!i,u=i&&!n.hasProjectDefinition;if(c)return de.createElement(Qt,{flexDirection:"column"},de.createElement(Qt,{flexDirection:"column"},de.createElement(wr,{hideBreadCrumb:!0,filters:s}),de.createElement(Ei,{height:t,width:e})),de.createElement(Ar,{width:e,mode:n.mode,availableHints:n.availableHints}));if(u)return de.createElement(Qt,{flexDirection:"column"},de.createElement(Qt,{flexDirection:"column"},de.createElement(wr,{hideBreadCrumb:!0,filters:s}),de.createElement(Yl,{height:t,width:e})),de.createElement(Ar,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Le(n.breadCrumb??[],"BOARD");if(ne(m)){let p=m.value.id,f=G(p).length,b=3,C=Math.floor(e/b),N=Math.floor(e/Math.max(f,1));e=Math.min(N,C)*Math.max(f,b)}return de.createElement(Qt,{flexDirection:"column"},de.createElement(vu,{autoSync:r}),de.createElement(Qt,{flexDirection:"column"},de.createElement(wr,{filters:s}),de.createElement(gu,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),de.createElement(Ar,{width:e,mode:n.mode,availableHints:n.availableHints}))}import uy from"readline";var os,ss,bt,my=new Set([h.MoveCursorLeft,h.EraseInputWord,h.MoveCursorLeftOfWord,h.MoveCursorRight,h.MoveCursorRightOfWord,h.NavToPreviousContainer,h.NavToNextContainer,h.NavPreviousItem,h.NavNextItem,h.SetViewDense,h.SetViewWide,h.Confirm,h.Exit,h.Yank,h.InitCommandLine,h.InitCommandPalette,h.ExitCommandLine,h.CaptureInput,h.EraseInput,h.EraseInputWord,h.HideHelp,h.ViewHelp,h.SetViewDense,h.SetViewWide,h.GetLastCommandFromHistory,h.GetNextCommandFromHistory,h.AutoCompleteCommand]),py=new Set([h.NavPreviousItem,h.NavNextItem,h.NavToPreviousContainer,h.NavToNextContainer,h.Confirm,h.Exit,h.InitCommandPalette,h.InitMove,h.MoveNextItem,h.MovePreviousItem,h.MoveToNextContainer,h.MoveToPreviousContainer,h.Delete,h.AddItem,h.EditTitle,h.EditDescription,h.ConfirmMove,h.Edit,h.ViewHelp,h.Yank]),yu=async e=>{if(e.ctrl&&e.name==="c")return T.exit();let{actionIndex:t,mode:n,readOnly:r,timeMode:o}=g(),s=Yd(e,n);if(!s||r&&!my.has(s)||o==="replay"&&n===v.DEFAULT&&py.has(s))return;let i=t[n]?.[s];if(i?.action)try{await i.action(i,e)}catch(c){logger.error(c)}},fy=()=>async function(t,n){n.name!=="escape"&&(bt&&(clearTimeout(bt),bt=void 0),await yu(n))},gy=()=>async function(t){if(t.length===1&&t[0]===27){bt&&clearTimeout(bt),bt=setTimeout(()=>{yu({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),bt=void 0},25);return}bt&&(clearTimeout(bt),bt=void 0)};function hu(){os&&process.stdin.removeListener("keypress",os),ss&&process.stdin.removeListener("data",ss),os=fy(),ss=gy(),uy.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",ss),process.stdin.on("keypress",os)}async function xu(){try{let e=wn();ne(e)&&Fe(e.value);let t=qe(process.cwd()),n=[];if(ne(t)){let s=Pe({repoRoot:t.value});if(d(s))return dn(3,s.message);let i=yn(),c=await tn({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return dn(3,c.message);let u=await _({cwd:s.value,args:["pull","--ff-only"]});d(u)&&logger.info(3,u.message);let m=Et(s.value);if(d(m))return dn(3,m.message);n=m.value}let r=an(n);if(d(r))return dn(4,r.message);E({hasProjectDefinition:ne(t),hasInitializingEvents:!!n.length});let o=Pi();return d(o)?dn(6,o.message):(hu(),l("Booted Epiq",void 0))}catch(e){return dn(0,oo(e))}}hc();var xy=`${Zt.bold("Epiq CLI")}
58
+ `));let le=Je();if(d(le))return te(16,le.message);let{rootNodeId:$n,nodes:Hn}=le.value,Li=Hn[$n];return Li?(T.navigate({contextNode:Li,selectedIndex:0}),E({hasProjectDefinition:!0,mode:v.DEFAULT}),l(O,null)):te(16,"Unable to resolve initialized root node")};import{ulid as bg}from"ulid";import{ulid as xg}from"ulid";var Nc=null,Gt=()=>structuredClone(Nc),hr=e=>{Nc=e},Ac=()=>{let{contextNode:e,selectedIndex:t}=g(),r=q(e.id)[t];return r?l("Resolved selected child",r):a("Target node not found")},di=({id:e,parentId:t,position:n={at:"end"}})=>{let r=q(t).filter(o=>o.id!==e);return no(r,n)},Rc=({id:e,parentId:t,position:n={at:"end"}})=>{let r=ie();if(d(r))return a("Unable to resolve user ID");let o=di({parentId:t,id:e,position:n});return d(o)?o:l("Created pending move state",{id:xg(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},Tc=e=>{hr(e);let t=Ut(e,!0);return d(t)?t:l("Node moved successfully",t.value)};function ci(e){let t=Ac();if(d(t))return t;let{contextNode:n,nodes:r}=g();if(!n.parentNodeId)return a("Missing parent node id");let o=r[n.parentNodeId];if(!o)return a("Missing parent node");let s=q(o.id),i=s.findIndex(({id:m})=>m===n.id);if(i<0)return a("Current node not found among siblings");let c=s[i+e];if(!c)return a("Missing sibling node");let u=Rc({id:t.value.id,parentId:c.id,position:{at:"end"}});return d(u)?u:Tc(u.value)}function li(e){let t=Ac();if(d(t))return t;let{contextNode:n,selectedIndex:r}=g(),s=q(n.id)[r+e];if(!s)return a("Missing sibling node");let i=Rc({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:s.id}});return d(i)?i:Tc(i.value)}var wc=()=>{let e=Gt();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,r=g().nodes[n];if(!r)return a("Move parent not found");let o=q(n).findIndex(s=>s.id===t);return o===-1?a("Moved node not found among rendered children"):(T.navigate({contextNode:r,selectedIndex:o}),l("Synchronized navigation to moved node",null))},wo=(e,t="Moved preview")=>{if(d(e))return e;let n=wc();return d(n)?n:(E({mode:v.MOVE}),l(t,null))},Mc=async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=Y().commandMeta,{contextNode:n,selectedIndex:r}=g(),o=q(n.id)[r];if(!o)return E({mode:v.DEFAULT}),a("No move target");if(t==="start"){if(o.readonly)return a("Target node is read-only");if(r===-1)return a("No item selected");if(!o.parentNodeId)return a("Target has no parent");let s=q(o.parentNodeId),i=s.findIndex(({id:f})=>f===o.id);if(i===-1)return a("Target not found among siblings");let c=s[i-1],u=s[i+1],m=u!=null?{at:"before",sibling:u.id}:c!=null?{at:"after",sibling:c.id}:{at:"start"},p=di({parentId:o.parentNodeId,id:o.id,position:m});return d(p)?p:(hr({id:bg(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:p.value.rank},...e.value}),E({mode:v.MOVE}),l("Move initialized",null))}if(t==="next")return wo(li(1));if(t==="previous")return wo(li(-1));if(t==="to-next")return wo(ci(1));if(t==="to-previous")return wo(ci(-1));if(t==="confirm"){let s=Gt();if(!s)return a("No pending move to confirm");let i=await at();if(d(i))return i;let c=B([s],i.value);if(d(c))return c;let u=wc();return d(u)?u:(hr(null),E({mode:v.DEFAULT}),l("Moved item",null))}return t==="cancel"?(hr(null),E({mode:v.DEFAULT}),l("Cancelling move",null)):a("Invalid move modifier")};import{ulid as Po}from"ulid";import{monotonicFactory as Ig,ulid as Eg}from"ulid";var Sg=Ig(),Mo=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let s=Sg();return l("Created issue events",[{id:Eg(),userId:r,userName:o,action:"add.issue",payload:{id:s,parent:t,name:e,rank:n}}])};var Pc=async(e,t)=>{let n=ie();if(d(n))return a("Unable to resolve user ID");let r=await at();if(d(r))return r;let o=r.value;if(!t.inputString)return a(`provide a name for your ${t.modifier}`);let{breadCrumb:s,contextNode:i,selectedIndex:c}=g(),u=m=>{let p=B([m],o);if(d(p))return p;let f=I.getNode(p.value[0].result.id);if(!f)return a("Created node not found");if(!f.parentNodeId)return p;let b=I.getNode(f.parentNodeId);return b?(T.navigate({contextNode:b,selectedIndex:I.getSiblings(f.parentNodeId).findIndex(({id:C})=>C===f.id)}),p):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=g(),p=I.getNode(m);if(!p)return a("Workspace not found");let f=Nn(p.id,n.value,o);return d(f)?f:u({id:Po(),action:"add.board",payload:{id:Po(),name:t.inputString,parent:p.id,rank:f.value},...n.value})}if(t.modifier==="swimlane"){let m=Le(s,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let p=Nn(m.value.id,n.value,o);return d(p)?p:u({id:Po(),action:"add.swimlane",payload:{id:Po(),name:t.inputString,parent:m.value.id,rank:p.value},...n.value})}if(t.modifier==="issue"){let m=G(i.id)[c],p=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let j=Le(s,"SWIMLANE");return d(j)?null:j.value})();if(!p)return a("Unable to add issue in this context");let f=Nn(p.id,n.value,o);if(d(f))return f;let b=Mo({name:t.inputString,parent:p.id,rank:f.value,user:n.value});if(d(b))return b;let C=b.value,N=B([...C],o);if(d(N))return N;if(!N.value[0])return a("Issue creation failed");let U=C.find(j=>j.action==="add.issue")?.payload.id;return U?(T.navigate({contextNode:p,selectedIndex:I.getSiblings(p.id).findIndex(({id:j})=>j===U)}),l("Issue created",null)):a("Unable to determine ticket id")}return l("Success",null)};var Lo=({boardId:e,targetTime:t,stateBranchRoot:n,selectedIndex:r})=>{let o=g(),s=$a(n,t);if(d(s))return a(s.message);let{appliedEvents:i,unappliedEvents:c}=s.value,u=zt();if(d(u))return u;let p=Ot(i).filter(d);if(p.length>0)return zt(),E(o),a(p.map(b=>b.message).join(", "));let f=g().nodes[e];return f?(T.navigate({contextNode:f,selectedIndex:r}),l("",{unappliedEvents:c})):(zt(),E(o),a("Board did not exist at that date"))};var Cg=20,Ng=16,Ag=150,ko=null,Do=null;var fn=()=>{ko!==null&&(clearInterval(ko),ko=null),Do!==null&&(clearTimeout(Do),Do=null)},Lc=()=>{fn(),E({mode:v.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null,selectedIndex:0})},Rg=e=>{let t=[],n=0;for(let o=0;o<e.length;o++){let s=o===0?0:Math.max(0,e[o]-e[o-1]);n+=Math.sqrt(s),t[o]=n}let r=n;return t.map((o,s)=>r>0?o/r:(s+1)/e.length)},kc=({events:e,startTime:t,durationMs:n})=>{fn();let r=e.length,o=e.map(f=>Cn(f)??t),s=o[r-1]??Date.now(),i=Rg(o),c=Math.max(1,Math.round(n*Cg/1e3)),u=Math.max(Math.round(n/c),Ng),m=0,p=0;E({mode:v.DEFAULT,readOnly:!0,timeMode:"replay",unappliedEvents:e,replay:{progress:0,appliedCount:0,totalCount:r,currentTime:t,startTime:t,endTime:s,currentLabel:"",flashNodeIds:[]}}),ko=setInterval(()=>{m++;let f=m/c,b=[],C;for(;p<r&&i[p]<=f;){let A=e[p],M=Ut(A);if(d(M)){Lc();return}b.push(...Ms(A)),C=A,p++}if(p>=r||m>=c){for(;p<r;p++){let M=Ut(e[p]);if(d(M))break}let A=g().replay;E({unappliedEvents:[],replay:A&&{...A,progress:1,appliedCount:r}}),fn(),Do=setTimeout(Lc,Ag);return}let N=g().replay;E({unappliedEvents:e.slice(p),replay:{progress:Math.min(1,f),appliedCount:p,totalCount:r,startTime:t,endTime:s,currentTime:C?Cn(C)??N?.currentTime??t:N?.currentTime??t,currentLabel:C?ka(C):N?.currentLabel??"",flashNodeIds:C?[...new Set(b)]:N?.flashNodeIds??[]}})},u)};var Dc=async()=>{let e=Le(g().breadCrumb,"BOARD");if(d(e))return e;let t=await dt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Pe({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=Y().commandMeta;if(fn(),r==="now"){let c=Et(n.value);if(d(c))return a(c.message);let u=zt();if(d(u))return u;let p=Ot(c.value).filter(d);return p.length>0?a(p.map(f=>f.message).join(", ")):(E({mode:v.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),l("Peeking now",!0))}let s;if(r==="prev"){let c=g().eventLog.at(-1),u=Cn(c);if(u===null)return a("No previous event to peek");s=u}else if(r==="next"){let c=g().unappliedEvents.at(0),u=Cn(c);if(u===null)return a("No next event to peek");s=u+1}else{let c=cn(r||o.trim());if(!c)return a("Invalid peek date");s=c.getTime()}let i=Lo({boardId:e.value.id,targetTime:s,stateBranchRoot:n.value,selectedIndex:0});return d(i)?i:(E({mode:v.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:i.value.unappliedEvents,replay:null}),l("Peeking",!0))};var Fc=async()=>{let e=Le(g().breadCrumb,"BOARD");if(d(e))return e;let t=await dt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Pe({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=Y().commandMeta,{dateInput:s,durationInput:i}=mo(r,o);if(fn(),g().syncStatus.status==="syncing")return a("Cannot replay while syncing, try again in a moment");let c=cn(s);if(!c)return a("Invalid replay date");let u=i?uo(i):15e3;if(u===null)return a("Invalid replay duration (try e.g. 30s or 2m)");let m=c.getTime(),p=g(),f=Lo({boardId:e.value.id,targetTime:m,stateBranchRoot:n.value,selectedIndex:-1});if(d(f))return f;let{unappliedEvents:b}=f.value;return b.length===0?(zt(),E(p),l("Nothing to replay from that point",!0)):(kc({events:b,startTime:m,durationMs:u}),l("Replaying board history",!0))};import wg from"zod";var Bc=()=>{let e=Y().commandMeta.inputString,t=wg.coerce.number().int().min(3e3).safeParse(e);if(!t.success)return a("Auto sync duration must be a number of at least 3000 ms");let n=Ze({autoSyncDebounceMs:t.data});return d(n)?n:(Fe({autoSyncIntervalMs:t.data}),E({mode:v.DEFAULT}),l(`Auto sync interval set to ${t.data}ms`,null))};var Uc=()=>{let e=Y().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=cd(e),n=Ze({autoSync:t});return d(n)?n:(Fe({autoSync:t}),E({mode:v.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var Oc=()=>{let e=Y().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=Ze({logLevel:e});return d(n)?n:(Fe({logLevel:e}),E({mode:v.DEFAULT}),l(`Auto sync set to "${e}"`,null))};import{spawn as Mg}from"node:child_process";var Pg=()=>{switch(process.platform){case"darwin":return{command:"pbcopy",args:[]};case"win32":return{command:"clip",args:[]};default:return process.env.WAYLAND_DISPLAY?{command:"wl-copy",args:[]}:{command:"xclip",args:["-selection","clipboard"]}}},_c=async e=>new Promise(t=>{let{command:n,args:r}=Pg();try{let o=Mg(n,r,{stdio:["pipe","ignore","ignore"]});o.on("error",()=>t(a(`Clipboard tool not available (${n})`))),o.on("close",s=>t(s===0?l("Copied to clipboard",null):a(`Clipboard tool failed (${n})`))),o.stdin.on("error",()=>{}),o.stdin.write(e),o.stdin.end()}catch{t(a(`Clipboard tool not available (${n})`))}});var xr=async(e,t)=>{if(!e.trim())return a(`Nothing to copy: ${t} is empty`);let n=await _c(e);return d(n)?n:l(`Copied ${t} to clipboard`,null)},$c=async e=>{let{breadCrumb:t,selectedNode:n}=g(),r=ar({breadCrumb:t,selectedNode:n}),o=r??n;if(!o)return a("Nothing selected to copy from");switch(e.modifier){case fe.REF:return xr(Ue(o.id),"ref");case fe.TITLE:return xr(o.title,"title");case fe.DESCRIPTION:return r?xr(r.props?.description??"","description"):a("No issue in scope");case fe.TAGS:{if(!r)return a("No issue in scope");let s=$t(r).map(({name:i})=>i);return xr(s.join(", "),"tags")}case fe.ASSIGNEES:{if(!r)return a("No issue in scope");let s=Ht(r).map(({name:i})=>i);return xr(s.join(", "),"assignees")}default:return a("Yank one of: ref, title, description, tags, assignees")}};var Hc=async()=>{W(""),E({mode:v.DEFAULT});let e=Je();if(d(e))return a(e.message);if(e.value.syncStatus.status==="syncing")return a("Sync already in progress");E({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await so();return d(t)?(E({syncStatus:{msg:t.message,status:"failed"}}),t):(E({mode:v.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var Lg=e=>e.action==="add.issue.comment",Wc=e=>Object.values(g().tags).find(t=>t.name===e),jc=e=>Object.values(g().contributors).find(t=>t.name===e),wt=async()=>{let e=await at();return d(e)?e:l("Resolved persist root",e.value)},Fo=[{systemOnly:!0,intent:w.Move,description:"Internal move-state command",mode:v.COMMAND_LINE,action:Mc},{intent:w.Delete,description:"Delete the currently selected node",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to resolve child to delete");let o=await wt();if(d(o))return o;if(r.context==="COMMENT"){let s=r.id,i=R(t)?t.id:t.parentNodeId;if(!i)return a("Unable to resolve comment issue");let c=g().nodes[i];if(!c||!R(c))return a("Unable to resolve comment issue");let u=c.log?.filter(Lg).find(m=>m.payload.id===s);return u?u.payload.author!==e.value.userId?a("You can only delete your own comments"):B([{id:we(),action:"delete.issue.comment",payload:{id:s,issue:i},...e.value}],o.value):a("Unable to resolve comment")}return B([{id:we(),action:"delete.node",payload:{id:r.id},...e.value}],o.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:v.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=Y().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(i=>ae(x.FILTER).map(c=>c.split(n)[0]).includes(i))(r))return a("Invalid filter modifier");let s={target:r,operator:"=",value:t.trim()};return he(i=>({...i,filters:e==="clear"?[]:[...i.filters,s],mode:v.DEFAULT})),l("Filter updated",null)}},{intent:w.ViewHelp,description:"Open the help screen",mode:v.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=g();return Kt({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),E({mode:v.HELP}),l("Viewing help",null)}},{intent:w.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to close issue, no target found");if(!R(r))return a("Cannot close in this context");let o=g().nodes[pe];if(!o)return a("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return a("Issue is already closed");let s=await wt();if(d(s))return s;let i=s.value,c=sn(o.id,r.id,{at:"end"},e.value,i);if(d(c))return c;let u=B([{id:we(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:c.value},...e.value}],i);return d(u)?u:l("Issue closed",null)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to reopen issue, no target found");let o=r.context==="TICKET"?l("Resolved ticket",r):It(r.id,"TICKET");if(d(o))return a("Cannot reopen in this context");let s=o.value,i=g().nodes[pe];if(!i)return a("Unable to locate closed swimlane");if(s.parentNodeId!==i.id)return a("Issue is not closed");if(!R(s))return a("Target node is not issue");let c=Ro(s);if(!c)return a("Unable to resolve previous parent from issue history");if(c===i.id)return a("Previous parent resolves to closed swimlane");let u=g().nodes[c];if(!u)return a("Previous parent no longer exists");let m=await wt();if(d(m))return m;let p=m.value,f=sn(u.id,s.id,{at:"end"},e.value,p);if(d(f))return f;let b=B([{id:we(),action:"reopen.issue",payload:{id:s.id,parent:u.id,rank:f.value},...e.value}],p);return d(b)?b:l("Issue reopened",null)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Init,description:"Initialize Epiq in the current git repository",mode:v.COMMAND_LINE,action:Cc},{intent:w.NewItem,description:"Create a new board, swimlane, or issue",mode:v.COMMAND_LINE,action:Pc,onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Rename,description:"Rename the currently selected node",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Missing node");if(r.readonly)return a("Cannot rename readonly node");let o=qd();if(!o)return a("Provide a title");let s=await wt();return d(s)?s:B([{id:we(),action:"edit.title",payload:{id:r.id,name:o},...e.value}],s.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.UntagTicket,description:"Remove a tag from the selected issue",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let o=Wc(r);if(!o)return a(`Tag "${r}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid untag target");let i=It(s.id,"TICKET");if(d(i))return a("Unable to untag issue in this context");let c=i.value;if(!R(c))return a("Target node is not issue");if(!(c.props.tags??[]).includes(o.id))return a("Issue is not tagged with that tag");let m=await wt();return d(m)?m:B([{id:we(),action:"remove.issue.tag",payload:{id:c.id,tag:o.id},...e.value}],m.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.TagTicket,description:"Add or create a tag on the selected issue",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let{selectedNode:o}=g();if(!o)return a("Invalid tag target");let s=It(o.id,"TICKET");if(d(s))return a("Unable to tag issue in this context");let i=s.value;if(!R(i))return a("Target node is not issue");let c=await wt();if(d(c))return c;let u=Wc(r),m=u?.id??we();return(i.props.tags??[]).includes(m)?a("Already tagged with that tag"):B([...u?[]:[{id:we(),action:"create.tag",payload:{id:m,name:r},...e.value}],{id:we(),action:"add.issue.tag",payload:{id:i.id,tag:m},...e.value}],c.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.AssignUserToTicket,description:"Assign a user to the selected issue",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee");let{selectedIndex:o,contextNode:s}=g(),i=G(s.id)[o];if(!i)return a("Invalid assign target");let c=It(i.id,"TICKET");if(d(c))return a("Unable to assign issue in this context");let u=c.value;if(!R(u))return a("Target node is not issue");let m=await wt();if(d(m))return m;let p=jc(r),f=p?.id??we();return(u.props.assignees??[]).includes(f)?a("Assignee already assigned"):B([...p?[]:[{id:we(),action:"create.contributor",payload:{id:f,name:r},...e.value}],{id:we(),action:"add.issue.assignee",payload:{id:u.id,assignee:f},...e.value}],m.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:v.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee to remove");let o=jc(r);if(!o)return a(`Assignee "${r}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid unassign target");let i=It(s.id,"TICKET");if(d(i))return a("Unable to unassign in this context");let c=i.value;if(!R(c))return a("Target node is not issue");if(!(c.props.assignees??[]).includes(o.id))return a(`Issue is not assigned to "${r}"`);let m=await wt();return d(m)?m:B([{id:we(),action:"remove.issue.assignee",payload:{id:c.id,assignee:o.id},...e.value}],m.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Comment,description:"Add a comment to the selected issue",mode:v.COMMAND_LINE,action:async(e,t)=>{let n=t.inputString.trim();if(!n)return a("Provide a comment");if(n.length>Pn)return a(`Cannot exceed ${Pn} characters`);let r=ie();if(d(r))return a("Unable to resolve user ID");let{breadCrumb:o,selectedNode:s}=g(),i=Le([...o,s],"TICKET");if(d(i))return a("Edit target must be an issue");let c=i.value;if(!c)return a("Invalid comment target");let u=c.context==="TICKET"?l("Resolved ticket",c):It(c.id,"TICKET");if(d(u))return a("Unable to comment on issue in this context");let m=u.value;if(!R(m))return a("Target node is not issue");let p=await wt();return d(p)?p:B([{id:we(),action:"add.issue.comment",payload:{id:we(),issue:m.id,author:r.value.userId,md:n},...r.value}],p.value)},onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Sync,description:"Pull, commit, and push Epiq state",mode:v.COMMAND_LINE,action:Hc},{intent:w.Peek,description:"View board state at another point in time",mode:v.COMMAND_LINE,action:Dc},{intent:w.Replay,description:"Replay board history forward from a point in time",mode:v.COMMAND_LINE,action:Fc},{intent:w.Export,description:"Export the current board layout to markdown",mode:v.COMMAND_LINE,action:async()=>{let e=await vc();return d(e)?e:(E({mode:v.DEFAULT}),l("Export successful",!0))}},{intent:w.Exit,description:"Exit the application",mode:v.COMMAND_LINE,action:async()=>(T.exit(),l("Exit successful",!0))},{intent:w.Edit,description:"Edit title or description",mode:v.COMMAND_LINE,action:async(e,t)=>Ic(t),onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Yank,description:"Yank (copy) ref, title, description, tags, or assignees to the clipboard",mode:v.COMMAND_LINE,action:async(e,t)=>$c(t),onSuccess:()=>E({mode:v.DEFAULT})},{intent:w.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:v.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case re.USERNAME:{let{userId:r,preferredEditor:o,userName:s}=K(),i=n||s,c=r??we();if(!i||!c)return a("Unable to resolve user name or id");let u=Ze({userName:i,userId:c,preferredEditor:o??""});return d(u)?u:(Fe({userName:i,userId:c}),E({mode:v.DEFAULT}),l(`Username set to "${i}"`,null))}case re.EDITOR:{if(!n)return a("No editor provided");let r=Ze({preferredEditor:n});return d(r)?r:(Fe({preferredEditor:n}),E({mode:v.DEFAULT}),l(`Editor configuration set to "${n}"`,null))}case re.VIEW:{if(n!=="wide"&&n!=="dense")return a("Invalid view mode");let r=Ze({viewMode:n});return d(r)?r:(Fe({viewMode:n}),E({mode:v.DEFAULT}),l(`View set to "${n}"`,null))}case re.AUTOSYNC:return Uc();case re.LOG_LEVEL:return Oc();case re.SYNC_DEBOUNCE_MS:return Bc();case re.ATTACHMENT_MAX_KB:return Td();default:return a("Unknown config command")}}},{intent:w.Coffee,description:"Sponsor the development of Epiq!",mode:v.COMMAND_LINE,action:()=>{let e=Y().commandMeta.modifier;return e==="custom"?yr("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):yr(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),W(""),l("Thanks you!",null)}}];var kg=new Set(["peek","replay","filter","view-help","yank"]),vt=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=Y();if(!t)return a("No command to confirm");if(!e&&n===pt.Invalid)return a("Invalid command");let s=xo(t);jd();let{readOnly:i}=g();if(i&&!kg.has(s))return mr({status:Pt.Fail,message:"Command not available in readonly state",value:null});let c=Fo.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===s);if(!c)return mr({status:Pt.Fail,message:"Command not found",value:null});let u;try{u=await c.action(c,{command:t,inputString:o,modifier:r})}catch(m){return mr({status:Pt.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(u)?mr(u):(Vd({addToHistory:!e}),c.onSuccess?.(),K().autoSync&&ao(),u)};var Bo=[{intent:h.Exit,mode:v.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(E({mode:v.COMMAND_LINE}),W("move cancel"),vt({isForceExecutedBySystem:!0}))},{intent:h.InitMove,mode:v.DEFAULT,description:"[m] move (init/confirm)",action:()=>(E({mode:v.COMMAND_LINE}),W("move start"),vt({isForceExecutedBySystem:!0}))},{intent:h.ConfirmMove,mode:v.MOVE,action:()=>(E({mode:v.COMMAND_LINE}),W("move confirm"),vt({isForceExecutedBySystem:!0}))}],Uo=[{intent:h.MovePreviousItem,mode:v.MOVE,action:()=>Gt()?(E({mode:v.COMMAND_LINE}),W("move previous"),vt({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveNextItem,mode:v.MOVE,action:()=>Gt()?(E({mode:v.COMMAND_LINE}),W("move next"),vt({isForceExecutedBySystem:!0})):a("No pending move")}],Vc=[{intent:h.MoveToNextContainer,mode:v.MOVE,action:()=>Gt()?(E({mode:v.COMMAND_LINE}),W("move to-next"),vt({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveToPreviousContainer,mode:v.MOVE,action:()=>Gt()?(E({mode:v.COMMAND_LINE}),W("move to-previous"),vt({isForceExecutedBySystem:!0})):a("No pending move")}];var Kc={[L.WORKSPACE]:[...Bo,...Uo],[L.BOARD]:[...Bo,...Uo],[L.SWIMLANE]:[...Bo,...Uo,...Vc],[L.TICKET]:[],[L.FIELD]:[],[L.FIELD_LIST]:[],[L.TEXT]:[],[L.COMMENT]:[]};import Dg from"node:fs";import Fg from"node:path";var Gc=e=>{let t=qe(process.cwd());if(d(t))return a("Unable to resolve project root");let n=Pe({repoRoot:t.value});if(d(n))return a(n.message);let r=Mn(e.hash,e.ext),o=Fg.join(Gn(n.value),r);return Dg.existsSync(o)?(yr(o),l(`Opened ${e.name}`,null)):a("Attachment file not found \u2014 run :sync to fetch it")};var zc=()=>{W("");let{pendingNavTarget:e}=Vt();E({mode:v.DEFAULT}),e&&T.navigate(e),Kt({pendingNavTarget:void 0})},qc=[{intent:h.ExitCommandLine,mode:v.HELP,action:()=>(zc(),l("Exiting help",null))},{intent:h.Exit,mode:v.HELP,action:()=>(zc(),l("Closed help",null))},{intent:h.NavPreviousItem,mode:v.HELP,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous help item",null))},{intent:h.NavNextItem,mode:v.HELP,action:()=>(T.navigateToNextItem(),l("Navigating to next help item",null))},{intent:h.NavToPreviousContainer,mode:v.HELP,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous help container",null))},{intent:h.NavToNextContainer,mode:v.HELP,action:()=>(T.navigateToNextContainer(),l("Navigating to next help container",null))}];var Bg=e=>{E({mode:v.COMMAND_LINE});let{pendingNavTarget:t}=Vt();t&&T.navigate(t),Kt({pendingNavTarget:void 0}),W(`${e} `)},Yc=()=>{W("");let{pendingNavTarget:e}=Vt();e&&T.navigate(e),Kt({pendingNavTarget:void 0}),E({mode:v.DEFAULT})},Xc=[{intent:h.InitCommandPalette,mode:v.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{W("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=g();return Kt({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),E({mode:v.PALETTE}),l("Opening command palette",null)}},{intent:h.Confirm,mode:v.PALETTE,action:()=>{let{selectedNode:e}=g();if(!e||!kt(e))return a("Command only applicable on text nodes");if(e.props.disabled)return a("Command is not available in this context");let t=e.title;return t?(Bg(t),l("Selected command",t)):l("No command selected",null)}},{intent:h.ExitCommandLine,mode:v.PALETTE,action:()=>(Yc(),l("Exiting palette",null))},{intent:h.Exit,mode:v.PALETTE,action:()=>(Yc(),l("Closed command palette",null))},{intent:h.NavPreviousItem,mode:v.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:v.PALETTE,action:()=>(T.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:v.PALETTE,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:v.PALETTE,action:()=>(T.navigateToNextContainer(),l("Navigating to next container",null))}];var Jc=[...qc,...Xc,{intent:h.AddItem,mode:v.DEFAULT,description:"[n] new...",action:()=>(E({mode:v.COMMAND_LINE}),W(`${x.NEW} `),l("Adding new item",null))},{intent:h.Delete,mode:v.DEFAULT,description:"[d] delete",action:()=>(E({mode:v.COMMAND_LINE}),W(`${x.DELETE} `),l("Deleting item",null))},{intent:h.InitCommandLine,mode:v.DEFAULT,description:"[:] focus command line",action:()=>(E({mode:v.COMMAND_LINE}),W(""),l("Entering command line mode",null))},{intent:h.Confirm,mode:v.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=g();if(!q(e?.id??"")?.length){let r=e?I.getAttachment(e.id):void 0;if(r)return Gc(r);if(e?.title===Q.DESCRIPTION)return E({mode:v.COMMAND_LINE}),W(`${x.EDIT} description `),l("Propose command",!0);if(e?.title===Q.ASSIGNEES)return E({mode:v.COMMAND_LINE}),W(`${x.ASSIGN} `),l("Propose command",!0);if(e?.title===Q.TAGS)return E({mode:v.COMMAND_LINE}),W(`${x.TAG} `),l("Propose command",!0);if(t.title===Q.DESCRIPTION&&e?.context==="TEXT")return E({mode:v.COMMAND_LINE}),W(`${x.EDIT} description `),l("Propose command",!0)}return T.enterChildNode(),l("Entering context",null)}},{intent:h.Yank,mode:v.DEFAULT,description:"[y] yank to clipboard",action:()=>{let{selectedNode:e}=g(),t=e?.title===Q.DESCRIPTION?fe.DESCRIPTION:e?.title===Q.TAGS?fe.TAGS:e?.title===Q.ASSIGNEES?fe.ASSIGNEES:fe.REF,r=ae(x.YANK).includes(t)?t:fe.REF;return E({mode:v.COMMAND_LINE}),W(`${x.YANK} ${r}`),l("Propose command",!0)}},{intent:h.EditTitle,mode:v.DEFAULT,description:"[r] rename title",action:()=>(E({mode:v.COMMAND_LINE}),W(`${x.EDIT} title ${g().selectedNode?.title}`),l("Exiting context",null))},{intent:h.EditDescription,mode:v.DEFAULT,description:"[e] edit description",action:()=>(E({mode:v.COMMAND_LINE}),W(`${x.EDIT} description `),l("Exiting context",null))},{intent:h.Exit,mode:v.DEFAULT,description:"[q] exit context",action:()=>(T.enterParentNode(),l("Exiting context",null))},{intent:h.NavPreviousItem,mode:v.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:v.DEFAULT,action:()=>(T.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:v.DEFAULT,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:v.DEFAULT,action:()=>(T.navigateToNextContainer(),l("Navigating to next container",null))}];var Ug=500,Og=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),Qc=e=>{let t=Og(e);t&&ho(n=>(n+t).slice(0,Ug))};var _g=[v.COMMAND_LINE,v.PALETTE],$g=e=>[{intent:h.MoveCursorLeft,mode:e,action:()=>(Xs(-1),l("Moving cursor left",null))},{intent:h.MoveCursorRight,mode:e,action:()=>(Xs(1),l("Moving cursor right",null))},{intent:h.MoveCursorLeftOfWord,mode:e,action:()=>(Js("left"),l("Moving cursor left of word",null))},{intent:h.MoveCursorRightOfWord,mode:e,action:()=>(Js("right"),l("Moving cursor right of word",null))},{intent:h.AutoCompleteCommand,mode:e,action:()=>(ho((t,{remainder:n})=>{let r=n?t+n:t,o="";return r==="edit title "&&(o=g().selectedNode?.title??""),r+o}),l("Auto-completing command",null))},{intent:h.CaptureInput,mode:e,action:(t,{sequence:n})=>(Qc(n??""),l("Capturing input",null))},{intent:h.EraseInput,mode:e,action:()=>(Hd(),l("Erasing input",null))},{intent:h.EraseInputWord,mode:e,action:()=>(Wd(),l("Erasing input word",null))}],Zc=[{intent:h.Confirm,mode:v.COMMAND_LINE,action:()=>(vt(),l("Executing command",null))},{intent:h.ViewHelp,mode:v.DEFAULT,action:()=>(E({mode:v.HELP}),l("Viewing help",null))},..._g.flatMap($g),{intent:h.ExitCommandLine,mode:v.COMMAND_LINE,action:()=>(E({mode:v.DEFAULT}),l("Exiting command line",null))},{intent:h.GetLastCommandFromHistory,mode:v.COMMAND_LINE,action:()=>(Kd(),l("Getting last command from history",null))},{intent:h.GetNextCommandFromHistory,mode:v.COMMAND_LINE,action:()=>(Gd(),l("Getting next command from history",null))}];import nl from"chalk";var Oo=nl.dim.hex(y.secondary2)(": for command line"),el="q to exit",tl=`${nl.hex(y.accent)("m")} to confirm`,ui={[L.WORKSPACE]:[Oo],[L.BOARD]:[Oo],[L.BOARD+v.COMMAND_LINE]:[Oo],[L.SWIMLANE]:[Oo],[L.TICKET+v.HELP]:[el],[L.SWIMLANE+v.HELP]:[el],[L.TICKET]:[],[L.FIELD]:[],[L.SWIMLANE+v.MOVE]:[tl],[L.TICKET+v.MOVE]:[tl]};var br=e=>e.trim().toLocaleLowerCase(),Hg=e=>{let{tags:t}=g();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},Wg=e=>{let{contributors:t}=g();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},rl=(e,t)=>{let n=br(t.value);if(!n)return!0;switch(t.target){case"title":return br(e.title??"").includes(n);case"description":return br(e.props.description??"").includes(n);case"tag":return Hg(e).map(br).some(o=>o.includes(n));case"assignee":return Wg(e).map(br).some(o=>o.includes(n));case"ref":return Ea(e.id,t.value);default:return!0}};function ol(e,t,n){let r=t[e];if(!r)return a("buildBreadCrumb(): current node not found");let o=[],s=r;for(;s&&(o.push(s),!(s.id===n||!s.parentNodeId));)s=t[s.parentNodeId];let i=o[o.length-1];return!i||i.id!==n?a("buildBreadCrumb(): node is not connected to root"):(o.reverse(),l("Breadcrumb built",o))}var sl=e=>{let t={};for(let n of e)n.intent&&(t[n.mode]||(t[n.mode]={}),t[n.mode][n.intent]=n);return t};var gn,mi,pi=new Set,il=()=>{for(let e of pi)e()},Vg=e=>(pi.add(e),()=>pi.delete(e));function al(e){let{contextNodeId:t,mode:n,rootNodeId:r,nodes:o,filters:s}=e;if(!t)return a("derive(): contextNodeId is missing");if(!r)return a("derive(): rootNode is missing");if(!o[r])return a("derive(): unable to find root node");let c=o[t];if(!c)return a("Unable to derive state, contextNode not found");let u=ol(t,o,r);if(d(u))return logger.error(u.message),u;let m=u.value,{context:p}=c,f=ui[p+n]??ui[p]??[],b=[...Jc,...Kc[p]??[],...Zc],C=sl(b),N=Kg(o,s),A=N[t]?.[e.selectedIndex]??null;return l("Derived successfully",{...e,contextNode:c,breadCrumb:m,availableHints:f,availableActions:b,actionIndex:C,selectedNode:A,renderedChildrenIndex:N})}var g=()=>{if(!gn)throw new Error("State not initialized. Call initWorkspaceState() first.");return gn},Je=()=>gn?l("Retrieved state",gn):a("State not initialized. Call initWorkspaceState() first.");function rr(e){mi=e;let t=qe(process.cwd()),n=!1;if(!d(t)){let s=Lt(t.value);if(d(s))return a(s.message);n=!0}let r={readOnly:!1,filters:[],tags:{},contributors:{},mode:v.DEFAULT,nodes:{[e.id]:e},rootNodeId:e.id,contextNodeId:e.id,renderedChildrenIndex:{},selectedIndex:-1,syncStatus:{status:"synced",msg:""},eventLog:[],unappliedEvents:[],replay:null,timeMode:"live",hasProjectDefinition:n,hasInitializingEvents:!1,comments:{},attachments:{}},o=al(r);return d(o)?o:(gn=o.value,il(),l("State initialized",null))}function he(e){let t=g(),n=e(t),r=al(n);return d(r)?a(r.message??"Unable to update state"):(gn=r.value,il(),l("State updated",null))}var E=e=>he(t=>({...t,...e}));var H=()=>jg(Vg,g,g),Kg=(e,t)=>{let n={};for(let r of Object.values(e))R(r)&&t.length>0&&!t.every(o=>rl(r,o))||!r.parentNodeId||r.isDeleted||((!r.parentNodeId||!n[r.parentNodeId])&&(n[r.parentNodeId]=[]),n[r.parentNodeId].push(r));for(let r of Object.keys(n))n[r].sort((o,s)=>{let i=e[o.id],c=e[s.id];return!i||!c?0:i.rank.localeCompare(c.rank)});return n},G=e=>g()?.renderedChildrenIndex[e]??[],zt=()=>mi?rr(mi):a("Cannot reset state: no initial workspace found"),Rn=()=>gn!==void 0;var fi=e=>{Rn()&&(E({syncStatus:e}),nn({type:"sync-status",payload:e}))},_o=(e="Syncing...")=>{fi({status:"syncing",msg:e})},$o=(e="Synced")=>{fi({status:"synced",msg:e})},gi=e=>{fi({status:"failed",msg:e})},Qe=e=>(gi(e),a(e));import{decodeTime as rk}from"ulid";var Gg=async({cwd:e,ensureUpstream:t})=>{logger.debug("[sync] ensureSyncReady:start",{cwd:e,ensureUpstream:t});let n=X("getRepoRootDir",await dt(e));if(d(n))return a(n.message);let r=n.value;logger.debug("[sync] repo root",r);let o=X("getStateBranchRoot",Pe({repoRoot:r}));if(d(o))return a(o.message);let s=o.value;logger.debug("[sync] state branch root",s);let i=X("ensureInitialCommit",await ra(r));if(d(i))return a(i.message);logger.debug("[sync] initial commit result",{created:i.value}),logger.debug("[sync] bootstrapping state branch storage",{repoRoot:r,stateBranchRoot:s,ensureUpstream:t});let c=X("bootstrapStateBranchStorage",await ia({repoRoot:r,stateBranchRoot:s,ensureUpstream:t}));if(d(c))return a(c.message);logger.debug("[sync] bootstrap result",{bootstrapped:c.value,stateBranchRoot:s}),logger.debug("[sync] checking state branch git operation",{stateBranchRoot:s});let u=X("hasInProgressGitOperation(stateBranchRoot)",await Br(s));if(d(u))return a(u.message);if(logger.debug("[sync] state branch git operation check result",{inProgress:u.value}),u.value)return logger.info("[sync] state branch git operation in progress"),a("Cannot sync while a git operation is in progress in the state branch");logger.debug("[sync] ensuring state branch layout",{repoRoot:r,stateBranchRoot:s});let m=X("ensureStateBranchLayout",ea(r,s));return d(m)?a(m.message):(logger.debug("[sync] state branch layout ready"),logger.debug("[sync] ensureSyncReady:done",{repoRoot:r,stateBranchRoot:s,bootstrapped:c.value}),l("Sync preconditions satisfied",{repoRoot:r,stateBranchRoot:s,bootstrapped:c.value}))},zg=async({repoRoot:e,stateBranchRoot:t,ownEventFileName:n})=>{logger.debug("[sync] committing own event file from state branch",{ownEventFileName:n,stateBranchRoot:t}),logger.debug("[sync] staging own event file",{stateBranchRoot:t,ownEventFileName:n});let r=X("stageStateBranchOwnEventFile",await jr({stateBranchRoot:t,eventFileName:n}));if(d(r))return a(r.message);let o=X("stageStateBranchMediaFiles",await oa({stateBranchRoot:t}));if(d(o))return a(o.message);let s=X("hasStagedChanges(after stage)",await zi(t));if(d(s))return a(s.message);if(logger.debug("[sync] state branch change check after stage result",{changed:s.value}),!s.value)return logger.info("[sync] no own event file changes to commit"),l("No own event file changes to commit",{createdCommit:!1});logger.debug("[sync] creating sync commit");let i=X("createStateBranchSyncCommit",await sa({repoRoot:e,stateBranchRoot:t}));return d(i)?a(i.message):(logger.debug("[sync] created sync commit",i.value),l("Committed own event file",{createdCommit:!0,commitSha:i.value}))},io=async({cwd:e=process.cwd(),ownEventFileName:t})=>{if(logger.debug("[sync] syncEpiqWithRemote:start",{cwd:e,ownEventFileName:t}),t.includes("/")||t.includes("\\"))return logger.error("[sync] invalid own event file name: contains path separator",{ownEventFileName:t}),a("Own event file must be a file name, not a path");if(!t.endsWith(".jsonl"))return logger.error("[sync] invalid own event file name: missing .jsonl suffix",{ownEventFileName:t}),a("Own event file must end with .jsonl");_o();let n=X("ensureSyncReady",await Gg({cwd:e,ensureUpstream:!0}));if(d(n))return Qe(n.message);let{repoRoot:r,stateBranchRoot:o,bootstrapped:s}=n.value,i=X("isDetachedHead(stateBranchRoot)",await qi(o));if(d(i))return Qe(i.message);if(logger.debug("[sync] detached state branch check result",{detached:i.value}),i.value)return Qe("Cannot run :sync while the state branch is in detached HEAD state");let c=!1,u,m=!1,p=!1,f=X("getStateBranch",hn(r));if(d(f))return Qe(f.message);let b=f.value;logger.debug("[sync] resolved state branch",{stateBranch:b,stateBranchRoot:o});let C=X("commitOwnEventFileToStateBranch",await zg({repoRoot:r,stateBranchRoot:o,ownEventFileName:t}));if(d(C))return Qe(C.message);c=C.value.createdCommit,u=C.value.commitSha;let N=X("pullBranchRebaseIfPresent",await xs({cwd:o,branch:b}));if(d(N))return Qe(N.message);if(m=N.value,c||s){logger.info("[sync] pushing state branch",{createdCommit:c,bootstrapped:s,stateBranchRoot:o});let A=X("pushStateBranch",await Qn({stateBranchRoot:o,repoRoot:r}));if(d(A)&&Gi(A.message)){let M=X("pullBranchRebaseIfPresent(retry)",await xs({cwd:o,branch:b}));if(d(M))return Qe(M.message);m=m||M.value,A=X("pushStateBranch(retry)",await Qn({stateBranchRoot:o,repoRoot:r}))}if(d(A))return Qe(A.message);p=A.value}if(c){logger.debug("[sync] resolving final sync commit sha",{stateBranchRoot:o});let A=X("git rev-parse HEAD",await _({args:["rev-parse","HEAD"],cwd:o}));if(d(A))return Qe(A.message);u=A.value.stdout.trim(),logger.debug("[sync] final sync commit sha",u)}return $o(p?"Synced and pushed":m||c?"Synced local state":"Already synced"),logger.debug("[sync] syncEpiqWithRemote:done"),l("Synced event logs with state branch",{repoRoot:r,stateBranchRoot:o,createdCommit:c,commitSha:u,pulled:m,pushed:p,bootstrapped:s})};var vi=()=>{let e=wn();return d(e)?mt:e.value.attachmentMaxKb??mt},yi=e=>{let t=qe(e??process.cwd());return d(t)?a(t.message):l("Resolved Epiq repo root",t.value)},Me=async(e,t)=>{let n=yi(e);if(d(n))return n;let r=Pe({repoRoot:n.value});if(d(r))return a(r.message);let o=yn(),s=await tn({repoRoot:n.value,stateBranchRoot:r.value,stateBranchName:o.stateBranch});if(d(s))return a(s.message);if(t?.pull??!1){let u=await _({cwd:r.value,args:["pull","--ff-only"]});d(u)&&se.info(3,u.message)}let i=Et(r.value);if(d(i))return a(i.message);let c=an(i.value);return d(c)?a(c.message):l("Booted Epiq state",{repoRoot:n.value,stateBranchRoot:r.value})},ke=()=>{let e=wn();return d(e)?a(e.message):e.value.userId?e.value.userName?l("Resolved actor",{userId:e.value.userId,userName:e.value.userName}):a("Unable to retrieve user name"):a("Unable to retrieve user id")},Oe=()=>{let e=Je();return d(e)?a(e.message):e},cl=e=>(e.props.tags??[]).map(t=>I.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:ue(t.name)})),ll=e=>(e.props.assignees??[]).map(t=>I.getContributor(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:ue(t.name)}));var ul=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=Oe();if(d(n))return n;let r=n.value.nodes,o=Object.values(r).filter(R).filter(s=>!s.isDeleted).filter(s=>e.includeClosed||s.parentNodeId!==pe).filter(s=>e.boardId?(s.parentNodeId?r[s.parentNodeId]:void 0)?.parentNodeId===e.boardId:!0).map(s=>({id:s.id,ref:Ue(s.id),title:Xe(s.title),description:s.props.description??"",parentNodeId:s.parentNodeId,isClosed:s.parentNodeId===pe,readonly:!!s.readonly,tags:cl(s),assignees:ll(s)}));return l("Listed issues",o)},ml=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=Nn(e.parentId,n.value,t.value.stateBranchRoot);if(d(o))return o;let s=Mo({name:e.title,parent:e.parentId,user:n.value,rank:o.value});if(d(s))return s;let i=[...s.value],c=i.find(f=>f.action==="add.issue")?.payload.id;if(!c)return a("Unable to determine created issue id");e.description&&i.push({id:J(),...n.value,action:"edit.description",payload:{id:c,md:e.description}});let u=[];for(let f of e.tagNames??[]){let b=Xe(f).trim();if(!b||u.some(A=>A.name===b))continue;let C=Object.values(r.value.tags).find(A=>A.name===b),N=C?.id??J();C||i.push({id:J(),...n.value,action:"create.tag",payload:{id:N,name:b}}),i.push({id:J(),...n.value,action:"add.issue.tag",payload:{id:c,tag:N}}),u.push({id:N,name:b})}let m=[];for(let f of e.assigneeNames??[]){let b=Xe(f).trim();if(!b||m.some(A=>A.name===b))continue;let C=Object.values(r.value.contributors).find(A=>A.name===b),N=C?.id??J();C||i.push({id:J(),...n.value,action:"create.contributor",payload:{id:N,name:b}}),i.push({id:J(),...n.value,action:"add.issue.assignee",payload:{id:c,assignee:N}}),m.push({id:N,name:b})}let p=B(i,t.value.stateBranchRoot);return d(p)?a(p.message):l("Created issue",{id:c,title:e.title,parentId:e.parentId,description:e.description??"",tags:u,assignees:m})},pl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=sn(pe,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(r))return r;let o={id:J(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:pe,rank:r.value}},s=B([o],t.value.stateBranchRoot);return d(s)?a(s.message):l("Closed issue",{id:e.issueId})},fl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Target node is not issue");if(o.parentNodeId!==pe)return a("Issue is not closed");let s=Ro(o);if(!s)return a("Unable to resolve previous parent from issue history");if(s===pe)return a("Previous parent resolves to closed swimlane");let i=r.value.nodes[s];if(!i)return a("Previous parent no longer exists");let c=sn(i.id,o.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let u={id:J(),...n.value,action:"reopen.issue",payload:{id:o.id,parent:i.id,rank:c.value}},m=B([u],t.value.stateBranchRoot);return d(m)?a(m.message):l("Reopened issue",{id:o.id,parentId:i.id})},gl=async e=>{let t=yi(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=Pe({repoRoot:t.value});if(d(r))return r;let o=Et(r.value);if(d(o))return o;let s=an(o.value);if(d(s))return s;let i=sn(e.parentId,e.issueId,e.position??{at:"end"},n.value,r.value);if(d(i))return i;let c={id:J(),...n.value,action:"move.node",payload:{id:e.issueId,parent:e.parentId,rank:i.value}},u=B([c],r.value);return d(u)?a(u.message):l("Moved issue",{id:e.issueId,parentId:e.parentId})};var Ho=async(e={})=>{_o();let t=yi(e.repoRoot);if(d(t))return a("Sync failed");let n=ke();if(d(n))return n;let r=await io({cwd:t.value,ownEventFileName:on(n.value)});return d(r)?(gi(r.message),r):($o(),l("Synced",r.value))};var yt=async(e={})=>{let t=await Me(e.repoRoot,{pull:!0});if(d(t))return t;let n=Oe();if(d(n))return n;let r=Object.values(n.value.nodes),o=r.filter(f=>Kr(f)&&!f.isDeleted),s=new Map,i=new Map;for(let f of r)if(!f.isDeleted){if(Dt(f)&&f.parentNodeId){let b=s.get(f.parentNodeId)??[];b.push(f),s.set(f.parentNodeId,b)}if(R(f)&&f.parentNodeId){let b=i.get(f.parentNodeId)??[];b.push(f),i.set(f.parentNodeId,b)}}let c=wn();if(d(c))return c;let u={};for(let f of r.filter(R))f.isDeleted||(u[f.id]=I.getCommentsByIssue(f.id).map(b=>{let C=I.getContributor(b.authorId);return{id:b.id,issueId:b.issue,body:b.md,author:{id:b.authorId,name:C?.name??"Unknown",color:ue(C?.name??b.authorId)},createdAt:dl(b.id)}}));let m=new Map;for(let f of n.value.eventLog)f.action==="add.issue.attachment"&&m.set(f.payload.id,f.payload.author);let p={};for(let f of r.filter(R))f.isDeleted||(p[f.id]=I.getAttachmentsByIssue(f.id).map(b=>({id:b.id,issueId:b.issue,name:b.name,fileName:Mn(b.hash,b.ext),bytes:b.bytes,createdAt:dl(b.id),canDelete:m.get(b.id)===c.value.userId})));return l("Retrieved Epiq GUI state",{boards:o.sort((f,b)=>f.rank.localeCompare(b.rank)).map(f=>({id:f.id,ref:Ue(f.id),title:f.title,swimlanes:(s.get(f.id)??[]).sort((b,C)=>b.rank.localeCompare(C.rank)).map(b=>({id:b.id,title:b.title,readonly:!!b.readonly,issues:(i.get(b.id)??[]).sort((C,N)=>C.rank.localeCompare(N.rank)).map(C=>({id:C.id,ref:Ue(C.id),title:Xe(C.title),description:C.props.description??"",readonly:!!C.readonly,tags:cl(C),assignees:ll(C),parentNodeId:C.parentNodeId,isClosed:C.parentNodeId===pe})),parentNodeId:b.parentNodeId}))})),tags:Object.values(n.value.tags).map(f=>({...f,color:ue(f.name)})),contributors:Object.values(n.value.contributors).map(f=>({...f,color:ue(f.name)})),user:{name:c.value.userName??"",id:c.value.userId??"",color:ue(c.value.userName??"")},commentsByIssueId:u,attachmentsByIssueId:p,attachmentMaxKb:vi()})},vl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=o.props.description??"";if(s===e.description)return l("No changes made",{id:e.issueId,description:s});let i={id:J(),...n.value,action:"edit.description",payload:{id:e.issueId,md:e.description}},c=B([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue description",{id:e.issueId,description:e.description})},yl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=Xe(e.title);if(!s.trim())return a("Issue title cannot be empty");if(o.title===s)return l("No changes made",{id:e.issueId,title:s});let i={id:J(),...n.value,action:"edit.title",payload:{id:e.issueId,name:s}},c=B([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue title",{id:e.issueId,title:s})},hl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Tag target must be an issue");if(o.readonly)return a("Cannot tag readonly issue");let s=Xe(e.tagName).trim();if(!s)return a("Tag name cannot be empty");let i=Object.values(r.value.tags).find(p=>p.name===s),c=i?.id??J(),u=[...i?[]:[{id:J(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:J(),...n.value,action:"add.issue.tag",payload:{id:e.issueId,tag:c}}],m=B(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue tag",{id:e.issueId,tag:{id:c,name:s}})},xl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Untag target must be an issue");if(o.readonly)return a("Cannot untag readonly issue");if(!r.value.tags[e.tagId])return a("Tag not found");let s={id:J(),...n.value,action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},i=B([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue tag",{id:e.issueId,tagId:e.tagId})},bl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Assign target must be an issue");if(o.readonly)return a("Cannot assign readonly issue");let s=Xe(e.assigneeName).trim();if(!s)return a("Assignee name cannot be empty");let i=Object.values(r.value.contributors).find(p=>p.name===s),c=i?.id??J(),u=[...i?[]:[{id:J(),...n.value,action:"create.contributor",payload:{id:c,name:s}}],{id:J(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:c}}],m=B(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue assignee",{id:e.issueId,assignee:{id:c,name:s}})},Il=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Unassign target must be an issue");if(o.readonly)return a("Cannot unassign readonly issue");if(!r.value.contributors[e.assigneeId])return a("Assignee not found");let s={id:J(),...n.value,action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},i=B([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue assignee",{id:e.issueId,assigneeId:e.assigneeId})},Wo=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Comment target must be an issue");if(o.readonly)return a("Cannot comment on readonly issue");let s=e.body.trim();if(!s)return a("Comment cannot be empty");let i=J(),c={id:J(),...n.value,action:"add.issue.comment",payload:{id:i,issue:e.issueId,md:s,author:n.value.userId}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Added issue comment",{id:i,issueId:e.issueId,body:s})},jo=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.eventLog.find(m=>m.action==="add.issue.comment"&&m.payload.id===e.commentId);if(!o)return a("Unable to resolve comment");if(o.payload.author!==n.value.userId)return a("You can only delete your own comments");let s=r.value.nodes[o.payload.issue];if(!s)return a("Issue not found");if(!R(s))return a("Comment target must be an issue");if(s.readonly)return a("Cannot delete comment on readonly issue");if(r.value.eventLog.some(m=>m.action==="delete.issue.comment"&&m.payload.id===e.commentId))return l("Comment already deleted",{id:e.commentId,issueId:o.payload.issue});let c={id:J(),...n.value,action:"delete.issue.comment",payload:{id:e.commentId,issue:o.payload.issue}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue comment",{id:e.commentId,issueId:o.payload.issue})},El=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!R(o))return a("Attachment target must be an issue");if(o.readonly)return a("Cannot attach to readonly issue");let s=Buffer.from(e.dataBase64??"","base64"),i=Ad(t.value.stateBranchRoot,s,vi());if(d(i))return i;let c=Xe(e.name??"").trim()||"image",u=J(),m={id:J(),...n.value,action:"add.issue.attachment",payload:{id:u,issue:e.issueId,author:n.value.userId,hash:i.value.hash,ext:i.value.ext,name:c,bytes:i.value.bytes}},p=B([m],t.value.stateBranchRoot);return d(p)?a(p.message):l("Added issue attachment",{id:u,issueId:e.issueId,fileName:Mn(i.value.hash,i.value.ext),bytes:i.value.bytes})},Sl=async e=>{let t=await Me(e.repoRoot,{pull:!1});if(d(t))return t;let n=ke();if(d(n))return n;let r=Oe();if(d(r))return r;let o=r.value.eventLog.find(m=>m.action==="add.issue.attachment"&&m.payload.id===e.attachmentId);if(!o)return a("Unable to resolve attachment");if(o.payload.author!==n.value.userId)return a("You can only delete your own attachments");let s=r.value.nodes[o.payload.issue];if(!s)return a("Issue not found");if(!R(s))return a("Attachment target must be an issue");if(s.readonly)return a("Cannot delete attachment on readonly issue");if(r.value.eventLog.some(m=>m.action==="delete.issue.attachment"&&m.payload.id===e.attachmentId))return l("Attachment already deleted",{id:e.attachmentId,issueId:o.payload.issue});let c={id:J(),...n.value,action:"delete.issue.attachment",payload:{id:e.attachmentId,issue:o.payload.issue}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue attachment",{id:e.attachmentId,issueId:o.payload.issue})},Cl=async e=>{let t=await Me(e.repoRoot,{pull:!1});return d(t)?t:Rd(t.value.stateBranchRoot,e.fileName,vi())};var Nl=e=>{let t,n,r=!1,o=!1,s=!1,i=()=>{let p=dr();if(d(p))return se.error(p.message);let{autoSync:f,userName:b,preferredEditor:C}=p.value;return!!(f&&b&&C)},c=async()=>{if(!r){if(o){s=!0;return}o=!0;try{await Ho({repoRoot:e.repoRoot}),nn({type:"state",payload:await yt({repoRoot:e.repoRoot})})}finally{o=!1,s&&(s=!1,c())}}},u=(p=750)=>{r||(n&&clearTimeout(n),n=setTimeout(()=>{c()},p))},m=()=>{if(r)return;let p=dr();if(d(p))return se.error(p.message);let{autoSyncDebounceMs:f}=p.value;i()&&(t=setTimeout(()=>{c(),m()},f??15e3))};return m(),{scheduleSync:u,dispose:()=>{r=!0,t&&clearTimeout(t),n&&clearTimeout(n)}}};import{WebSocketServer as qg}from"ws";var Ve=(e,t)=>{e.send(JSON.stringify(t))},Ir=async(e,t)=>Ve(e,{type:"state",payload:await yt({repoRoot:t})}),ht=async(e,t,n,r,o)=>{if(Ve(e,{type:r,payload:o}),d(o))return Ve(e,{type:"failed",payload:o.message});n(),Ir(e,t)},Al=(e,t,{onStateChanged:n})=>{new qg({server:e,path:"/ws"}).on("connection",o=>{aa(o),o.on("message",async s=>{try{let i=JSON.parse(s.toString()),{type:c}=i;if(c==="state:get")return Ir(o,t);if(c==="sync"){let u=await Ho({repoRoot:t});return Ve(o,{type:"sync:result",payload:u}),n(),Ir(o,t)}if(c==="issue:comment:add"){let u=await Wo({repoRoot:t,...i.payload});return ht(o,t,n,"issue:comment:add:result",u)}if(c==="issue:comment:delete"){let u=await jo({repoRoot:t,...i.payload});return Ve(o,{type:"issue:comment:delete:result",payload:u}),d(u)?Ve(o,{type:"failed",payload:u.message}):(n(),Ir(o,t))}if(c==="issue:edit:description"){let u=await vl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:edit:description:result",u)}if(c==="issue:edit:title"){let u=await yl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:edit:title:result",u)}if(c==="issue:tag:add"){let u=await hl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:tag:add:result",u)}if(c==="issue:tag:remove"){let u=await xl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:tag:remove:result",u)}if(c==="issue:assignee:add"){let u=await bl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:assignee:add:result",u)}if(c==="issue:assignee:remove"){let u=await Il({repoRoot:t,...i.payload});return ht(o,t,n,"issue:assignee:remove:result",u)}if(c==="issues:list")return Ve(o,{type:"issues",payload:await ul({repoRoot:t})});if(c==="issues:create"){let u=await ml({...i.payload,repoRoot:t});return Ve(o,{type:"issues:create:result",payload:u}),d(u)?nn({type:"failed",payload:u.message}):(nn({type:"issue:created",payload:u.value}),n(),Ir(o,t))}if(c==="issues:move"){if(!i.payload.position)return Ve(o,{type:"error",message:"Missing move position"});let u=await gl({...i.payload,repoRoot:t});return ht(o,t,n,"issues:move:result",u)}if(c==="issue:close"){if(!i.payload.issueId)return Ve(o,{type:"error",message:"Missing issueId"});let u=await pl({repoRoot:t,issueId:i.payload.issueId});return ht(o,t,n,"issue:close:result",u)}if(c==="issue:reopen"){if(!i.payload.issueId)return Ve(o,{type:"error",message:"Missing issueId"});let u=await fl({repoRoot:t,issueId:i.payload.issueId});return ht(o,t,n,"issue:reopen:result",u)}return Ve(o,{type:"error",message:"Unknown message type"})}catch(i){return Ve(o,{type:"error",message:i instanceof Error?i.message:String(i)})}})})};var Jg=vn.dirname(Xg(import.meta.url)),Qg=process.env.IS_LOCAL==="true"?vn.resolve(process.cwd(),"dist/gui"):vn.join(Jg,"gui"),Vo,Zg=async()=>(Vo===void 0&&(Vo=await import("node:sea").catch(()=>null)),Vo?.isSea()?Vo:null),ve=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},Rl=async(e,t=1024*1024)=>new Promise((n,r)=>{let o="",s=0;e.on("data",i=>{if(s+=i.length,s>t){e.destroy(),r(new Error("Request body too large"));return}o+=i}),e.on("end",()=>{try{n(o?JSON.parse(o):{})}catch{r(new Error("Invalid JSON body"))}}),e.on("error",r)}),ev=2*1024*1024,tv={png:"image/png",jpg:"image/jpeg",gif:"image/gif",webp:"image/webp"},nv=e=>e.endsWith(".html")?"text/html; charset=utf-8":e.endsWith(".js")?"text/javascript; charset=utf-8":e.endsWith(".css")?"text/css; charset=utf-8":e.endsWith(".json")?"application/json; charset=utf-8":e.endsWith(".ico")?"image/x-icon":"application/octet-stream",Tl=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),r=vn.resolve(Qg),o=vn.resolve(r,n),s=vn.relative(r,o);if(s.startsWith("..")||vn.isAbsolute(s))return ve(t,403,{isError:!0,message:"Forbidden"});let i=await Zg();try{let c=i?Buffer.from(i.getAsset(`gui/${s}`)):await wl(o);return t.writeHead(200,{"content-type":nv(o)}),t.end(c)}catch{return ve(t,404,{isError:!0,message:`Not found: ${n}`})}},rv=async(e,t=3710)=>new Promise((n,r)=>{let o=s=>{let i=u=>{if(e.off("listening",c),u.code==="EADDRINUSE"&&s===t){e.removeListener("error",i),o(0);return}r(u)},c=()=>{e.off("error",i);let u=e.address();if(!u||typeof u=="string"){r(new Error("Unable to resolve address"));return}n(u.port)};e.once("error",i),e.once("listening",c),e.listen(s,"127.0.0.1")};o(t)}),Ml=async e=>{let t=Yg.createServer(async(o,s)=>{let i=new URL(o.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return ve(s,200,await yt({repoRoot:e.repoRoot}));if(o.method==="POST"&&i.pathname==="/api/comments")try{let c=await Rl(o);if(!c.issueId||!c.body?.trim())return ve(s,400,{isError:!0,message:"Missing issueId or body"});let u=await Wo({repoRoot:e.repoRoot,issueId:c.issueId,body:c.body});return"isError"in u&&u.isError?ve(s,400,u):ve(s,200,await yt({repoRoot:e.repoRoot}))}catch(c){return ve(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add comment"})}if(o.method==="POST"&&i.pathname==="/api/attachments")try{let c=await Rl(o,ev);if(!c.issueId||!c.dataBase64)return ve(s,400,{isError:!0,message:"Missing issueId or dataBase64"});let u=await El({repoRoot:e.repoRoot,issueId:c.issueId,name:c.name??"",dataBase64:c.dataBase64});return d(u)?ve(s,400,{isError:!0,message:u.message}):ve(s,200,await yt({repoRoot:e.repoRoot}))}catch(c){return ve(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add attachment"})}if(o.method==="DELETE"&&i.pathname.startsWith("/api/attachments/")){let c=decodeURIComponent(i.pathname.replace("/api/attachments/",""));if(!c)return ve(s,400,{isError:!0,message:"Missing attachment id"});let u=await Sl({repoRoot:e.repoRoot,attachmentId:c});return d(u)?ve(s,400,{isError:!0,message:u.message}):ve(s,200,await yt({repoRoot:e.repoRoot}))}if(o.method==="GET"&&i.pathname.startsWith("/media/")){let c=decodeURIComponent(i.pathname.replace("/media/","")),u=await Cl({repoRoot:e.repoRoot,fileName:c});if(d(u))return ve(s,404,{isError:!0,message:u.message});try{let m=await wl(u.value.filePath);return s.writeHead(200,{"content-type":tv[u.value.ext]??"application/octet-stream","cache-control":"public, max-age=31536000, immutable"}),s.end(m)}catch{return ve(s,404,{isError:!0,message:"Attachment blob not found"})}}if(o.method==="DELETE"&&i.pathname.startsWith("/api/comments/")){let c=decodeURIComponent(i.pathname.replace("/api/comments/",""));if(!c)return ve(s,400,{isError:!0,message:"Missing comment id"});let u=await jo({repoRoot:e.repoRoot,commentId:c});return"isError"in u&&u.isError?ve(s,400,u):ve(s,200,await yt({repoRoot:e.repoRoot}))}return i.pathname.startsWith("/board/")?Tl("/",s):Tl(i.pathname,s)});try{await rv(t)}catch(o){return a(o instanceof Error?`Unable to start GUI server: ${o.message}`:`Unable to start GUI server: ${String(o)}`)}let n=Nl({repoRoot:e.repoRoot});Al(t,e.repoRoot,{onStateChanged:()=>n.scheduleSync()}),t.on("close",n.dispose);let r=t.address();return!r||typeof r=="string"?(t.close(),a("Unable to resolve GUI server address")):l("Started GUI server",{url:`http://epiq.localhost:${r.port}${e.boardId?`/board/${e.boardId}`:""}`,server:t})};var Pl=async e=>{let t=await Ml({...e,boardId:""});if(d(t))return t;let{url:n}=t.value;return console.log(`Epiq GUI running at ${ov.cyan(n)}`),Di(n),l("Started GUI",{url:n})};import{Box as Qt}from"ink";import de from"react";import{Box as hi,Text as Er}from"ink";import ot,{useEffect as sv,useMemo as iv}from"react";import{ulid as av}from"ulid";var Ll=({text:e,match:t,color:n,highlightColor:r=y.secondary,dimColor:o=!1})=>{if(!t)return ot.createElement(Er,{color:n,dimColor:o},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?ot.createElement(Er,{color:n,dimColor:o},e):ot.createElement(Er,{color:n,dimColor:o},e.slice(0,c),ot.createElement(Er,{backgroundColor:r,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},kl=av(),dv=e=>`${e}`,cv=e=>{let{pendingNavTarget:t}=Vt();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,s=new Set(ae(x.NONE,{breadCrumb:n,contextNode:r,readOnly:g().readOnly,selectedNode:o}));return[...new Set(Object.values(x))].filter(i=>i!=="move").filter(i=>i.length>0).filter(i=>i!==x.PALETTE).map(i=>{let c=xo(i),u=Fo.find(m=>m.intent===c);return{command:i,description:u?.description??`[${i}] Run command`,isAvailable:s.has(i)}}).filter(i=>i.command.toLowerCase().startsWith(e)||e.length>=2&&i.description.toLowerCase().includes(e)).sort((i,c)=>i.isAvailable!==c.isAvailable?i.isAvailable?-1:1:i.command.localeCompare(c.command))},lv=e=>Z.text({id:kl,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),uv=(e,t,n)=>Z.text({id:dv(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),xi=[],mv=e=>{Dl();let t=I.createNode(lv(g().rootNodeId));d(t)||!kt(t.value)||(xi=[t.value,...e.map((n,r)=>uv(n,r,kl)).map(I.createNode).filter(ne).map(({value:n})=>n).filter(kt)],T.navigate({contextNode:t.value,selectedIndex:0}))},Dl=()=>{let e=xi.map(t=>t.id);xi=[];for(let t of e)I.deleteNode(t)};function Fl({width:e,height:t}){let r=zd().value.trim().toLowerCase(),o=iv(()=>cv(r),[r]);sv(()=>(mv(o),()=>{Dl()}),[o]);let s=g().selectedIndex;return ot.createElement(hi,{flexDirection:"column",width:e,height:t-2},ot.createElement(et,{height:t-4,itemHeight:3,selectedIndex:s},o.map((i,c)=>{let u=c===s,m=i.isAvailable?y.accent:y.secondary2,p=i.isAvailable?"":"[unavailable] ";return ot.createElement(hi,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:y.secondary,borderStyle:"single"},ot.createElement(Er,{color:m,dimColor:!i.isAvailable},u?"\u276F ":" ",ot.createElement(Ll,{text:pa(i.command),match:r,color:m,dimColor:!i.isAvailable})),ot.createElement(hi,{paddingLeft:2},ot.createElement(Ll,{text:p+i.description,match:r.length>=2?r:"",color:u&&i.isAvailable?y.primary:y.secondary2,dimColor:!i.isAvailable})))})))}import{Box as wv}from"ink";import zo from"react";import Cr from"chalk";import{Box as bi,Text as Bl}from"ink";import Sr,{useEffect as pv,useMemo as fv,useState as gv}from"react";var Ul=Cr.hex(y.secondary),vv=Cr.inverse,yv=Cr.inverse.hex(y.secondary2),hv={hint:"",hints:[],overlap:0,remainder:""},_l=({value:e,command:t})=>{if(!t)return null;let n=e.trimStart(),o=e.length-n.length;return e.slice(o,o+t.length)!==t?null:{start:o,end:o+t.length}},xv=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=ue(t);return{bg:r=>Cr.bgHex(n).black(r),bgCursor:r=>Cr.bgHex(n).inverse.black(r)}}return ws(t)},bv=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=_l({value:e,command:t});if(!r)return null;let s=e.slice(r.end).match(/^\s*/)?.[0].length??0,i=r.end+s;return e.slice(i,i+n.length)!==n?null:{start:i,end:i+n.length}},Ol=()=>({value:Ae.value,cursorPosition:Ae.cursorPosition,commandIsPending:Ae.commandIsPending,autoCompletion:Ae.commandMeta.autoCompletion??hv,infoMessage:Ae.commandMeta.infoMessage,validationStatus:Ae.commandMeta.validity,command:Ae.commandMeta.command,inputString:Ae.commandMeta.inputString,modifier:Ae.commandMeta.modifier}),Iv=(e,t)=>e.value===t.value&&e.cursorPosition===t.cursorPosition&&e.commandIsPending===t.commandIsPending&&e.infoMessage===t.infoMessage&&e.autoCompletion.hint===t.autoCompletion.hint&&e.autoCompletion.overlap===t.autoCompletion.overlap&&e.autoCompletion.remainder===t.autoCompletion.remainder&&e.validationStatus===t.validationStatus&&e.command===t.command&&e.modifier===t.modifier&&e.inputString===t.inputString,$l=({width:e,mode:t})=>{let[n,r]=gv(Ol());pv(()=>{let N=()=>{let M=Ol();r(U=>Iv(U,M)?U:M)},A=Ys(N);return N(),()=>{A()}},[]);let{value:o,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:u,command:m,modifier:p,validationStatus:f}=n,b=c&&f===pt.Invalid,C=fv(()=>{let N=Math.max(0,Math.min(s,o.length)),A=_l({value:o,command:m}),M=bv({value:o,command:m,modifier:p}),U=m?ws(m):null,j=xv({command:m,modifier:p}),D=(me,le)=>{let $n=A&&le>=A.start&&le<A.end,Hn=M&&le>=M.start&&le<M.end;return $n&&U?U.fg(me):Hn&&j?j.bg(me):me},z=(me,le)=>{let $n=A&&le>=A.start&&le<A.end,Hn=M&&le>=M.start&&le<M.end;return $n&&U?U.fgCursor(me):Hn&&j?j.bgCursor(me):vv(me)},$=o.slice(0,N),P=o[N]??" ",O=N<o.length?o.slice(N+1):"",Ge=Array.from($).map((me,le)=>D(me,le)).join(""),Ce=z(P,N),ze=Array.from(O).map((me,le)=>D(me,N+1+le)).join("");if(u.hint){let me=u.hint[u.overlap]??P;Ce=yv(me),ze=Ul(u.remainder.slice(1)+O)}return Ul(t===v.PALETTE?"?":":")+Ge+Ce+ze},[o,s,u,m,p]);return Sr.createElement(bi,{flexDirection:"column",justifyContent:"flex-start"},Sr.createElement(bi,{flexDirection:"column",paddingX:1,borderColor:y.secondary,borderStyle:"round",width:e},Sr.createElement(bi,null,Sr.createElement(Bl,null,C),i&&Sr.createElement(Bl,{wrap:"truncate",color:b?y.red:y.secondary2},` ${i} `))))};import{Box as Ev,Text as Sv}from"ink";import Hl from"react";var Cv=(e,t)=>{let n=[],r=0;for(let o of e){let i=(n.length>0?" | ":"").length+o.length;if(r+i>t-4)break;n.push(o),r+=i}return n},Wl=({width:e,availableHints:t})=>{let n=Cv(t,e).join(" | ");return Hl.createElement(Ev,{width:e,borderStyle:"round",borderColor:y.secondary,paddingX:1},Hl.createElement(Sv,{color:y.secondary2},n.length?n:"\xA0"))};import{Box as Nv,Text as Ko}from"ink";import Nr,{useEffect as Av,useRef as Un,useState as Rv}from"react";var Tv=40,Go=.3,Ii="\u2500",jl=1,Vl=16,Kl=({width:e})=>{let{replay:t}=H(),n=t!==null,r=t?Math.min(1,Math.max(0,t.progress)):0,s=Math.max(4,e-6),i=s*jl,[c,u]=Rv(0),m=Un(r);m.current=r;let p=Un(0),f=Un(0),b=Un(0),C=Un(0),N=Un(0);if(Av(()=>{if(!n){p.current=0,b.current=0,C.current=0,N.current=0,u(0);return}p.current=m.current,f.current=Date.now(),b.current=m.current;let D=setInterval(()=>{let z=Date.now(),$=m.current;if($!==b.current){let ze=$-b.current,me=z-f.current;if(ze<0)C.current=0,N.current=0;else if(ze>0&&me>0){let le=ze/me;C.current=C.current===0?le:C.current*(1-Go)+le*Go,N.current=N.current===0?ze:N.current*(1-Go)+ze*Go}p.current=$,f.current=z,b.current=$}let P=z-f.current,O=Math.min(N.current,C.current*P),Ge=Math.min(1,p.current+O),Ce=Math.round(Ge*i);u(ze=>ze===Ce?ze:Ce)},Tv);return()=>clearInterval(D)},[n,i]),!t)return null;let A=D=>{let z=s>1?D/(s-1):0,$=Math.round(z*(Vl-1))/(Vl-1);return zr($)},M=Math.min(s,Math.floor(c/jl)),U=[];for(let D=0;D<M;D++){let z=A(D),$=U[U.length-1];$&&$.color===z?$.text+=Ii:U.push({text:Ii,color:z})}let j=Ii.repeat(Math.max(0,s-M));return Nr.createElement(Nv,{width:e,borderStyle:"round",borderColor:y.secondary,paddingX:1,columnGap:1},Nr.createElement(Ko,{color:y.secondary2},"\u25B6"),Nr.createElement(Ko,null,U.map((D,z)=>Nr.createElement(Ko,{key:z,color:D.color},D.text)),Nr.createElement(Ko,{color:y.secondary,dimColor:!0},j)))};var Ar=({width:e,mode:t,availableHints:n})=>{let{timeMode:r}=H(),o=t===v.COMMAND_LINE||t===v.PALETTE;return zo.createElement(wv,null,o?zo.createElement($l,{width:e,mode:t}):r==="replay"?zo.createElement(Kl,{width:e}):zo.createElement(Wl,{width:e,mode:t,availableHints:n}))};import{Box as qt,Text as On}from"ink";import De,{useEffect as Mv,useMemo as Pv}from"react";import{ulid as Gl}from"ulid";var Yo=Gl(),Lv=()=>[...new Set([...g().availableActions].map(e=>e.description).filter(e=>e!==void 0))].map(e=>{let[t,n]=e.split("]"),r=t?.replace("[",""),o=n?.trim();return[r,o]}).filter(e=>e[0]!==void 0&&e[1]!==void 0).sort(([e],[t])=>e.length===1&&t.length!==1?-1:e.length!==1&&t.length===1?1:e.localeCompare(t,void 0,{sensitivity:"base"})).map(([e,t])=>({keys:e,action:t})),kv=e=>Z.text({id:Yo,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),Dv=(e,t,n)=>Z.text({id:Gl(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),qo=[],zl=()=>{let e=qo.filter(n=>n.id!==Yo).map(n=>n.id),t=qo.filter(n=>n.id===Yo).map(n=>n.id);qo=[];for(let n of[...e,...t])I.deleteNode(n)},Fv=e=>{zl();let t=I.createNode(kv(g().rootNodeId));if(d(t)||!kt(t.value))return logger.error("Could not attach help nodes");qo=[t.value,...e.map((n,r)=>Dv(n,r,Yo)).map(I.createNode).filter(ne).map(({value:n})=>n).filter(kt)],T.navigate({contextNode:t.value,selectedIndex:0})},ql=({width:e,height:t})=>{let n=Pv(()=>Lv(),[]);Mv(()=>(Fv(n),()=>{zl()}),[n]);let r=g().selectedIndex;return De.createElement(qt,{flexDirection:"column",marginTop:3,borderColor:y.secondary,borderStyle:"round",width:e,height:t-2},De.createElement(qt,{paddingX:1,justifyContent:"center"},De.createElement(On,{color:y.accent},"Help"),De.createElement(On,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),De.createElement(qt,{paddingX:1,marginTop:1},De.createElement(qt,{width:20,justifyContent:"flex-end"},De.createElement(On,{color:y.secondary},"Key(s)")),De.createElement(qt,{flexGrow:1,width:40,paddingLeft:2},De.createElement(On,{color:y.secondary},"Action"))),De.createElement(et,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:s},i)=>{let c=i===r;return De.createElement(qt,{paddingX:1,key:`${o}-${s}-${i}`,flexDirection:"row"},De.createElement(qt,{width:20,justifyContent:"flex-end"},De.createElement(On,{color:y.accent},o)),De.createElement(qt,{flexGrow:1,width:40,paddingLeft:2},De.createElement(On,{color:c?y.primary:y.secondary2},s)))})))};import Bv from"chalk";import{Box as Xo,Text as Mt}from"ink";import Ke from"react";var Yl=({width:e,height:t})=>Ke.createElement(Xo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},Ke.createElement(Mt,{color:y.accent,bold:!0},"Initialize project"),Ke.createElement(Mt,null,`This folder is not an ${Bv.hex(y.accent)("epiq")} project yet.`),Ke.createElement(Mt,{color:y.primary},"To start tracking issues here, we need to initialize a new",Ke.createElement(Mt,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json "),"file in this repository."),Ke.createElement(Xo,{marginTop:1,flexDirection:"column"},Ke.createElement(Xo,null,Ke.createElement(Mt,{color:y.accent}," "),Ke.createElement(Mt,{color:y.primary},"Type "),Ke.createElement(Mt,{backgroundColor:y.secondary}," :init "))),Ke.createElement(Xo,{marginTop:1},Ke.createElement(Mt,{color:y.secondary2},"This will create, commit and push "),Ke.createElement(Mt,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json ")));import{Box as Jo,Text as xt}from"ink";import Se from"react";var Uv=({isDone:e,command:t,value:n})=>Se.createElement(Jo,null,Se.createElement(xt,{color:y.accent,dimColor:e},e?" \u2714 ":" "),Se.createElement(xt,{dimColor:e},"Type "),Se.createElement(xt,{backgroundColor:y.secondary,dimColor:e}," "+t+" "),n!==void 0&&Se.createElement(Se.Fragment,null,Se.createElement(xt,{dimColor:e}," "),Se.createElement(xt,{color:y.secondary,dimColor:e},"<"+n+">"))),Ov=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function Ei({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:s,autoSync:i,isSetAutoSync:c}=_t(),u=[{key:"username",done:r,command:":config username",value:o,message:"First, choose your username."},{key:"editor",done:n,command:":config editor",value:s,message:"Nice. Now pick your editor."},{key:"autosync",done:c,command:":config autosync",value:i,message:"Almost there. Configure auto sync."}],m=u.findIndex(f=>!f.done),p=m===-1?void 0:u[m];return Se.createElement(Jo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},Se.createElement(xt,{color:y.accent,bold:!0},"Welcome! \u{1F539}"),Se.createElement(xt,null,"Let's get you started - it's a breeze."),Se.createElement(xt,{color:y.secondary2},"Remember - you can always search available commands by typing:",Se.createElement(xt,{color:y.accent}," ? ")),p&&Se.createElement(xt,{color:y.secondary2},p.message),Se.createElement(Jo,{flexDirection:"column"},u.map((f,b)=>m===-1||b<=m?Se.createElement(Jo,{key:f.key,marginBottom:1},Se.createElement(Uv,{isDone:f.done,command:f.command,value:f.done?Ov(f.value):void 0})):null)))}import ns from"chalk";import{Box as Tr,Text as _n}from"ink";import ye from"react";import{Box as Qo,Text as Xl}from"ink";import Yt from"react";import _v from"chalk";var $v=e=>(I.getTag(e)?.name??"").length+3,Hv=e=>(I.getContributor(e)?.name??"").length+3,Jl=({width:e})=>{let{viewMode:t}=K(),n=H(),{breadCrumb:r,contextNode:o,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[o.id]?.[s],u=It(c?.id??o.id,"TICKET"),m=ne(u)?u.value:void 0,p=m?.props.tags??[],f=m?.props.assignees??[],b=m?.parentNodeId?!As(o.id,m.parentNodeId)&&t==="dense":!1,C=r.map(($,P)=>{let O=P===r.length-1,Ge=q($.id),Ce=O?Ge?.[s]?.title:void 0;return`${P?" / ":""}${$.title??""}${Ce?` \u25B8 ${Ce}`:""}`}).join(""),N=m?I.getCommentsByIssue(m.id):[],A=N.length?String(N.length).length+11:0,M=b?p.reduce(($,P)=>$+$v(P),0)+f.reduce(($,P)=>$+Hv(P),0)+A:0,U=c?.id!=null&&!(t==="wide"&&R(c)),j=Math.max(0,e-M),D=C.substring(0,j)+(U?_v.hex(y.secondary2).dim(` ${Ue(c.id)}`):""),z=b?[...p.map($=>Yt.createElement(Qo,{key:`tag-${$}`,paddingLeft:1},Yt.createElement(kn,{id:$}))),...f.map($=>Yt.createElement(Qo,{key:`assignee-${$}`,paddingLeft:1},Yt.createElement(Wt,{id:$}))),N.length?Yt.createElement(Qo,{key:"comments",paddingLeft:1},Yt.createElement(Xl,{color:y.accent},"[",N.length," comment",N.length===1?"":"s","]")):null]:[];return Yt.createElement(Qo,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},Yt.createElement(Xl,{color:y.secondary2},D),z)};import{Box as Wv,Text as Ql}from"ink";import Zo from"react";var jv=({filters:e})=>Zo.createElement(Wv,{columnGap:1},Zo.createElement(Ql,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>Zo.createElement(Ql,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),Zl=Zo.memo(jv);import{Box as Vv,Text as es}from"ink";import Rr from"react";function eu(){let{eventLog:e,unappliedEvents:t}=H(),n=e.at(-1)?.id,r=Jr(n??""),o=ne(r)?Xr(r.value):"INVALID DATE";return Rr.createElement(Vv,{paddingLeft:1},Rr.createElement(es,{backgroundColor:y.accent,color:y.secondary}," Readonly "),Rr.createElement(es,{color:y.accent}," "+t.length+" edits ago at "+o+"."),Rr.createElement(es,{color:y.accent}," Resume with "),Rr.createElement(es,{backgroundColor:y.accent,color:y.secondary}," ",":peek now"," "))}import{Box as Kv,Text as Si}from"ink";import ts from"react";function tu(){let{replay:e}=H();if(!e)return null;let{appliedCount:t,totalCount:n,currentTime:r}=e;return ts.createElement(Kv,{paddingRight:2,columnGap:1,justifyContent:"flex-end"},ts.createElement(Si,{backgroundColor:y.accent,color:y.secondary}," \u25B6 REPLAY "),ts.createElement(Si,{color:y.secondary2},Xr(new Date(r))),ts.createElement(Si,{color:y.accent},`${t}/${n} edits`))}import Ci from"chalk";import{Box as Gv,Text as nu}from"ink";import Ni,{useEffect as zv,useState as qv}from"react";var Yv=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],Xv=150,ru=12,Jv=.36,ou=e=>{let t=e.replace("#","");return{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16)}},Qv=({r:e,g:t,b:n})=>{let r=o=>Math.round(Math.max(0,Math.min(255,o))).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(n)}`},Zv=(e,t,n)=>{let r=ou(e),o=ou(t);return Qv({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},ey=(e,t)=>{if(e.length===1)return e[0];let n=t*(e.length-1),r=Math.floor(n),o=n-r,s=e[r],i=e[Math.min(r+1,e.length-1)];return Zv(s,i,o)};function su({syncStatus:e,autoSync:t}){let[n,r]=qv(0);zv(()=>{if(e.status!=="syncing"){r(0);return}let c=0,u=setInterval(()=>{c+=1;let m=(Math.sin(c*Jv)+1)/2,p=Math.round(m*(ru-1));r(f=>f===p?f:p)},Xv);return()=>clearInterval(u)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:y.secondary2,failed:y.yellow,pending:y.secondary2,syncing:ey(Yv,n/(ru-1))??""}[e.status];return Ni.createElement(Gv,null,Ni.createElement(nu,null,Ci.hex(y.secondary2).dim(t?"Sync (auto): ":"Sync: ")),Ni.createElement(nu,null,Ci.hex(i)("\u25CF")+Ci.hex(y.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}import lu from"chalk";import{Text as uu}from"ink";import mu,{useEffect as oy,useState as sy}from"react";var Xt="1.3.5";import Ai from"chalk";var ty="https://registry.npmjs.org/epiq/latest",Ri=null,iu=0,ny=1e3*60*60*24,au=e=>e.replace(/^v/,""),ry=(e,t)=>{let n=au(e).split(".").map(Number),r=au(t).split(".").map(Number);for(let o=0;o<Math.max(n.length,r.length);o++){let s=n[o]??0,i=r[o]??0;if(s>i)return 1;if(s<i)return-1}return 0},du=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(Ri&&Date.now()-iu<ny)return Ri;try{let t=await fetch(ty);if(!t.ok)throw new Error(`Failed to fetch latest version: ${t.status}`);let r=(await t.json()).version??null,o={current:e,latest:r,updateAvailable:r?ry(r,e)>0:!1};return Ri=o,iu=Date.now(),o}catch{return{current:e,latest:null,updateAvailable:!1}}},cu=(e,t)=>{let n=e.split("."),r=t.split("."),o=r.findIndex((s,i)=>s!=n[i]);return r.map((s,i)=>i>=o?Ai.hex(y.accent).dim(s):Ai.hex(y.secondary).dim(s)).join(Ai.hex(y.secondary2).dim("."))};function pu(){let[e,t]=sy({current:Xt,latest:null,updateAvailable:!1});return oy(()=>{let n=!0;return du(Xt).then(r=>{n&&t(r)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?mu.createElement(uu,{dimColor:!0,color:y.secondary2},Xt+" "):mu.createElement(uu,null,lu.hex(y.secondary2).dim(Xt),lu.hex(y.accent).dim(" \u2197 "),cu(Xt,e.latest))}function wr({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o,replay:s}=H(),{userName:i,preferredEditor:c,autoSync:u}=K(),m=64,p=process.stdout.columns-m-8,f=t||n==="replay",b=s?rn(s.currentLabel,Math.max(0,p)):"";return ye.createElement(Tr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},n==="replay"?ye.createElement(Tr,{paddingLeft:1},ye.createElement(_n,{color:y.secondary2},b)):f?ye.createElement(_n,null," "):o===v.PALETTE?ye.createElement(Tr,null,ye.createElement(_n,{color:y.accent},"Command Palette"),ye.createElement(_n,{dimColor:!0,color:y.secondary2}," ","- search, select and press enter")):ye.createElement(Tr,{paddingLeft:1},e.length>0?ye.createElement(Zl,{filters:e}):ye.createElement(Jl,{width:p})),n==="live"?ye.createElement(Tr,{columnGap:1,paddingRight:2,"max-width":m,overflow:"hidden",justifyContent:"flex-end"},ye.createElement(su,{autoSync:!!u,syncStatus:r}),ye.createElement(_n,null,ns.hex(y.secondary2).dim("Mode: ")+ns.hex(y.secondary2).dim(o.padEnd(8," "))," "),ye.createElement(fu,{icon:"@",value:i}),ye.createElement(fu,{icon:"\u276F",value:c}),ye.createElement(pu,null)):"",n==="peek"?ye.createElement(eu,null):"",n==="replay"?ye.createElement(tu,null):"")}function fu({icon:e,value:t}){return ye.createElement(_n,null,ns.dim(e)+ns.hex(y.accent)(` ${t??"-"} `))}import{Box as iy,Text as ay}from"ink";import Mr from"react";import{Box as rs,Text as Ti}from"ink";import Jt from"react";function wi(){let e=H(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?G(t?.id):[];return Jt.createElement(rs,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:y.secondary,width:s},Jt.createElement(rs,{padding:1,paddingTop:0,paddingBottom:0},Jt.createElement(Ti,null,"Select a board:")),Jt.createElement(rs,{padding:1,flexDirection:"column"},i.map((c,u)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===u,f=G(c.id).flatMap(({id:b})=>q(b)).length;return Jt.createElement(rs,{key:c.id??u},Jt.createElement(Ti,{color:m?y.accent:y.secondary2},Jt.createElement(Re,{isSelected:m})),Jt.createElement(Ti,{color:m?y.accent:y.secondary2},c.title," (",f," issues)",c.readonly?" \u{1F512}":""))})))}var dy=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:s,width:i})=>{let{renderedChildrenIndex:c}=H(),u=n.find(({context:b})=>b==="BOARD"),f=s-1-3;return Mr.createElement(iy,{flexDirection:"row"},e.context==="WORKSPACE"?Mr.createElement(wi,null):u?Mr.createElement(Ao,{height:f,width:i,swimlanes:(c[u.id]??[]).filter(b=>b!==void 0&&Dt(b)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):Mr.createElement(ay,null))},gu=Mr.memo(dy);import{useEffect as cy}from"react";var ly=e=>{cy(()=>{if(!e)return;let t,n=!1,r=()=>{if(n)return;let{autoSyncIntervalMs:o,userName:s,preferredEditor:i}=K();i&&s&&o&&(t=setTimeout(()=>{if(n)return;let{readOnly:c,mode:u}=g();u==="default"&&!c&&ao(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},vu=({autoSync:e})=>(ly(e),null);function Mi({width:e,height:t}){let n=H(),{autoSync:r,viewMode:o}=xa(),s=n.filters;if(n.mode===v.HELP)return de.createElement(Qt,{flexDirection:"column"},de.createElement(ql,{width:e,height:t}));if(n.mode===v.PALETTE)return de.createElement(Qt,{flexDirection:"column"},de.createElement(wr,{filters:s}),de.createElement(Fl,{width:e,height:t-2}),de.createElement(Ar,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=_t(),c=!i,u=i&&!n.hasProjectDefinition;if(c)return de.createElement(Qt,{flexDirection:"column"},de.createElement(Qt,{flexDirection:"column"},de.createElement(wr,{hideBreadCrumb:!0,filters:s}),de.createElement(Ei,{height:t,width:e})),de.createElement(Ar,{width:e,mode:n.mode,availableHints:n.availableHints}));if(u)return de.createElement(Qt,{flexDirection:"column"},de.createElement(Qt,{flexDirection:"column"},de.createElement(wr,{hideBreadCrumb:!0,filters:s}),de.createElement(Yl,{height:t,width:e})),de.createElement(Ar,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Le(n.breadCrumb??[],"BOARD");if(ne(m)){let p=m.value.id,f=G(p).length,b=3,C=Math.floor(e/b),N=Math.floor(e/Math.max(f,1));e=Math.min(N,C)*Math.max(f,b)}return de.createElement(Qt,{flexDirection:"column"},de.createElement(vu,{autoSync:r}),de.createElement(Qt,{flexDirection:"column"},de.createElement(wr,{filters:s}),de.createElement(gu,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),de.createElement(Ar,{width:e,mode:n.mode,availableHints:n.availableHints}))}import uy from"readline";var os,ss,bt,my=new Set([h.MoveCursorLeft,h.EraseInputWord,h.MoveCursorLeftOfWord,h.MoveCursorRight,h.MoveCursorRightOfWord,h.NavToPreviousContainer,h.NavToNextContainer,h.NavPreviousItem,h.NavNextItem,h.SetViewDense,h.SetViewWide,h.Confirm,h.Exit,h.Yank,h.InitCommandLine,h.InitCommandPalette,h.ExitCommandLine,h.CaptureInput,h.EraseInput,h.EraseInputWord,h.HideHelp,h.ViewHelp,h.SetViewDense,h.SetViewWide,h.GetLastCommandFromHistory,h.GetNextCommandFromHistory,h.AutoCompleteCommand]),py=new Set([h.NavPreviousItem,h.NavNextItem,h.NavToPreviousContainer,h.NavToNextContainer,h.Confirm,h.Exit,h.InitCommandPalette,h.InitMove,h.MoveNextItem,h.MovePreviousItem,h.MoveToNextContainer,h.MoveToPreviousContainer,h.Delete,h.AddItem,h.EditTitle,h.EditDescription,h.ConfirmMove,h.Edit,h.ViewHelp,h.Yank]),yu=async e=>{if(e.ctrl&&e.name==="c")return T.exit();let{actionIndex:t,mode:n,readOnly:r,timeMode:o}=g(),s=Yd(e,n);if(!s||r&&!my.has(s)||o==="replay"&&n===v.DEFAULT&&py.has(s))return;let i=t[n]?.[s];if(i?.action)try{await i.action(i,e)}catch(c){logger.error(c)}},fy=()=>async function(t,n){n.name!=="escape"&&(bt&&(clearTimeout(bt),bt=void 0),await yu(n))},gy=()=>async function(t){if(t.length===1&&t[0]===27){bt&&clearTimeout(bt),bt=setTimeout(()=>{yu({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),bt=void 0},25);return}bt&&(clearTimeout(bt),bt=void 0)};function hu(){os&&process.stdin.removeListener("keypress",os),ss&&process.stdin.removeListener("data",ss),os=fy(),ss=gy(),uy.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",ss),process.stdin.on("keypress",os)}async function xu(){try{let e=wn();ne(e)&&Fe(e.value);let t=qe(process.cwd()),n=[];if(ne(t)){let s=Pe({repoRoot:t.value});if(d(s))return dn(3,s.message);let i=yn(),c=await tn({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return dn(3,c.message);let u=await _({cwd:s.value,args:["pull","--ff-only"]});d(u)&&logger.info(3,u.message);let m=Et(s.value);if(d(m))return dn(3,m.message);n=m.value}let r=an(n);if(d(r))return dn(4,r.message);E({hasProjectDefinition:ne(t),hasInitializingEvents:!!n.length});let o=Pi();return d(o)?dn(6,o.message):(hu(),l("Booted Epiq",void 0))}catch(e){return dn(0,oo(e))}}hc();var xy=`${Zt.bold("Epiq CLI")}
59
59
 
60
60
  ${Zt.dim("Boot in directory:")}
61
61
  ${Zt.cyan("$ epiq")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epiq",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "EPIQ - ergonomic, distributed CLI-first issue tracker TUI ready for the agentic era",
@@ -64,7 +64,10 @@
64
64
  "meow": "^14.1.0",
65
65
  "react": "^19.2.4",
66
66
  "react-dom": "^19.2.6",
67
+ "react-markdown": "^10.1.0",
67
68
  "react-router-dom": "^7.17.0",
69
+ "remark-breaks": "^4.0.0",
70
+ "remark-gfm": "^4.0.1",
68
71
  "string-width": "^8.2.0",
69
72
  "ulid": "^3.0.2",
70
73
  "ws": "^8.21.0",