epiq 1.4.3 → 1.4.4

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.
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ ${c}
57
57
  `,wi.writeFileSync(t,n,"utf8"),le.info(`Added ${s.join(", ")} to .gitignore (epiq local state)`),u("Local epiq paths ignored",!0)};var Nv=async e=>{let t=await F({cwd:e,args:["status","--porcelain"]});return d(t)?t:u("Checked git diff",t.value.stdout.trim().length>0)},re=(e,t)=>a(`[${e}] ${t}`),sl=async()=>{V("");let e=Cn(),t=await gt(process.cwd());if(d(t))return re(1,t.message);let n=t.value,r=await Wr(n);if(d(r))return re(2,r.message);if(r.value)return re(2,`Cannot initialize Epiq while a git operation is in progress: ${r.value}`);let o=await Nv(n);if(d(o))return re(2.5,o.message);if(o.value)return re(3,"Cannot initialize Epiq with uncommitted changes. Commit or stash your changes first.");if(_s(n))return re(4,"Epiq project already initialized");let s=Kt();if(!s.isSetupDone||!s.userName)return re(5,"Missing Epiq user configuration (userId / userName). Run setup first.");let i=K(),c=i.userName,l=i.userId;if(!l||!c)return re(5,"Missing Epiq user id");let m=e.stateBranch,p=await Gr({repoRoot:n,branch:m});if(d(p))return re(6,p.message);if(p.value)return re(6,`State branch already exists: ${m}`);let f=await Gs({repoRoot:n,stateBranchName:m});if(d(f))return re(6,f.message);let g=qr();if(d(g))return re(7,g.message);let E=ol.join(zr(),e.projectId),I=await un({repoRoot:n,stateBranchRoot:E,stateBranchName:m});if(d(I))return re(8,I.message);let R=ol.join(E,".epiq");Cv.mkdirSync(R,{recursive:!0});let A=Fd({userId:l,userName:c});if(d(A))return re(9,A.message);for(let As of A.value){let ca=go({event:As,rootDir:E});if(d(ca))return re(9,ca.message)}let P=await Zr({stateBranchRoot:E,eventFileName:pn({userId:l,userName:c})});if(d(P))return re(10,P.message);let _=await Rn({cwd:E,message:"[epiq:init]"});if(d(_))return re(10,_.message);let w=await rl(n);if(d(w))return re(11,w.message);let W=ua({repoRoot:n,fileContents:e});if(d(W))return re(12,W.message);let H=await ue.stage({cwd:n,pathspec:[".epiq/project.json",".gitignore"]});if(d(H))return re(13,H.message);let D=await ue.commit({cwd:n,message:"[epiq:init-project]"});if(d(D))return re(13,D.message);let $="Project initialized!",Ye=await F({cwd:n,args:["push","-u","origin","HEAD"]});d(Ye)&&($+=` Warn: [init:14] ${Ye.message}`);let we=await sr({repoRoot:n,stateBranchRoot:E});d(we)&&($+=` Warn: [init:15] ${we.message}`);let ge=st(A.value).filter(d);if(ge.length>0)return re(16,ge.map(As=>As.message).join(`
58
58
  `));let me=We();if(d(me))return re(16,me.message);let{rootNodeId:Kn,nodes:zn}=me.value,da=zn[Kn];return da?(M.navigate({contextNode:da,selectedIndex:0}),C({hasProjectDefinition:!0,mode:y.DEFAULT}),u($,null)):re(16,"Unable to resolve initialized root node")};import{ulid as Av}from"ulid";import{ulid as Rv}from"ulid";var il=null,tn=()=>structuredClone(il),Cr=e=>{il=e},al=()=>{let{contextNode:e,selectedIndex:t}=v(),r=Y(e.id)[t];return r?u("Resolved selected child",r):a("Target node not found")},Mi=({id:e,parentId:t,position:n={at:"end"}})=>{let r=Y(t).filter(o=>o.id!==e);return vo(r,n)},dl=({id:e,parentId:t,position:n={at:"end"}})=>{let r=ae();if(d(r))return a("Unable to resolve user ID");let o=Mi({parentId:t,id:e,position:n});return d(o)?o:u("Created pending move state",{id:Rv(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},cl=e=>{Cr(e);let t=Vt(e,!0);return d(t)?t:u("Node moved successfully",t.value)};function Pi(e){let t=al();if(d(t))return t;let{contextNode:n,nodes:r}=v();if(!n.parentNodeId)return a("Missing parent node id");let o=r[n.parentNodeId];if(!o)return a("Missing parent node");let s=Y(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 l=dl({id:t.value.id,parentId:c.id,position:{at:"end"}});return d(l)?l:cl(l.value)}function Li(e){let t=al();if(d(t))return t;let{contextNode:n,selectedIndex:r}=v(),s=Y(n.id)[r+e];if(!s)return a("Missing sibling node");let i=dl({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:s.id}});return d(i)?i:cl(i.value)}var ll=()=>{let e=tn();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,r=v().nodes[n];if(!r)return a("Move parent not found");let o=Y(n).findIndex(s=>s.id===t);return o===-1?a("Moved node not found among rendered children"):(M.navigate({contextNode:r,selectedIndex:o}),u("Synchronized navigation to moved node",null))},Vo=(e,t="Moved preview")=>{if(d(e))return e;let n=ll();return d(n)?n:(C({mode:y.MOVE}),u(t,null))},ul=async()=>{let e=ae();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=X().commandMeta,{contextNode:n,selectedIndex:r}=v(),o=Y(n.id)[r];if(!o)return C({mode:y.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=Y(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],l=s[i+1],m=l!=null?{at:"before",sibling:l.id}:c!=null?{at:"after",sibling:c.id}:{at:"start"},p=Mi({parentId:o.parentNodeId,id:o.id,position:m});return d(p)?p:(Cr({id:Av(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:p.value.rank},...e.value}),C({mode:y.MOVE}),u("Move initialized",null))}if(t==="next")return Vo(Li(1));if(t==="previous")return Vo(Li(-1));if(t==="to-next")return Vo(Pi(1));if(t==="to-previous")return Vo(Pi(-1));if(t==="confirm"){let s=tn();if(!s)return a("No pending move to confirm");let i=await yt();if(d(i))return i;let c=U([s],i.value);if(d(c))return c;let l=ll();return d(l)?l:(Cr(null),C({mode:y.DEFAULT}),u("Moved item",null))}return t==="cancel"?(Cr(null),C({mode:y.DEFAULT}),u("Cancelling move",null)):a("Invalid move modifier")};import{ulid as Ko}from"ulid";import{monotonicFactory as Tv,ulid as wv}from"ulid";var Mv=Tv(),Go=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let s=Mv();return u("Created issue events",[{id:wv(),userId:r,userName:o,action:"add.issue",payload:{id:s,parent:t,name:e,rank:n}}])};var ml=async(e,t)=>{let n=ae();if(d(n))return a("Unable to resolve user ID");let r=await yt();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}=v(),l=m=>{let p=U([m],o);if(d(p))return p;let f=S.getNode(p.value[0].result.id);if(!f)return a("Created node not found");if(!f.parentNodeId)return p;let g=S.getNode(f.parentNodeId);return g?(M.navigate({contextNode:g,selectedIndex:S.getSiblings(f.parentNodeId).findIndex(({id:E})=>E===f.id)}),p):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=v(),p=S.getNode(m);if(!p)return a("Workspace not found");let f=Ln(p.id,n.value,o);return d(f)?f:l({id:Ko(),action:"add.board",payload:{id:Ko(),name:t.inputString,parent:p.id,rank:f.value},...n.value})}if(t.modifier==="swimlane"){let m=Oe(s,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let p=Ln(m.value.id,n.value,o);return d(p)?p:l({id:Ko(),action:"add.swimlane",payload:{id:Ko(),name:t.inputString,parent:m.value.id,rank:p.value},...n.value})}if(t.modifier==="issue"){let m=z(i.id)[c],p=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let _=Oe(s,"SWIMLANE");return d(_)?null:_.value})();if(!p)return a("Unable to add issue in this context");let f=Ln(p.id,n.value,o);if(d(f))return f;let g=Go({name:t.inputString,parent:p.id,rank:f.value,user:n.value});if(d(g))return g;let E=g.value,I=U([...E],o);if(d(I))return I;if(!I.value[0])return a("Issue creation failed");let P=E.find(_=>_.action==="add.issue")?.payload.id;return P?(M.navigate({contextNode:p,selectedIndex:S.getSiblings(p.id).findIndex(({id:_})=>_===P)}),u("Issue created",null)):a("Unable to determine ticket id")}return u("Success",null)};var zo=({boardId:e,targetTime:t,stateBranchRoot:n,selectedIndex:r})=>{let o=v(),s=fo(n,t);if(d(s))return a(s.message);let{appliedEvents:i,unappliedEvents:c}=s.value,l=it();if(d(l))return l;let p=st(i).filter(d);if(p.length>0)return it(),C(o),a(p.map(g=>g.message).join(", "));let f=v().nodes[e];return f?(M.navigate({contextNode:f,selectedIndex:r}),u("",{unappliedEvents:c})):(it(),C(o),a("Board did not exist at that date"))};var Pv=20,Lv=16,kv=150,qo=null,Yo=null;var En=()=>{qo!==null&&(clearInterval(qo),qo=null),Yo!==null&&(clearTimeout(Yo),Yo=null)},pl=()=>{En(),C({mode:y.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null,selectedIndex:0})},Dv=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)},fl=({events:e,startTime:t,durationMs:n})=>{En();let r=e.length,o=e.map(f=>Yt(f)??t),s=o[r-1]??Date.now(),i=Dv(o),c=Math.max(1,Math.round(n*Pv/1e3)),l=Math.max(Math.round(n/c),Lv),m=0,p=0;C({mode:y.DEFAULT,readOnly:!0,timeMode:"replay",unappliedEvents:e,replay:{progress:0,appliedCount:0,totalCount:r,currentTime:t,startTime:t,endTime:s,currentLabel:"",flashNodeIds:[]}}),qo=setInterval(()=>{m++;let f=m/c,g=[],E;for(;p<r&&i[p]<=f;){let R=e[p],A=Vt(R);if(d(A)){pl();return}g.push(...Qs(R)),E=R,p++}if(p>=r||m>=c){for(;p<r;p++){let A=Vt(e[p]);if(d(A))break}let R=v().replay;C({unappliedEvents:[],replay:R&&{...R,progress:1,appliedCount:r}}),En(),Yo=setTimeout(pl,kv);return}let I=v().replay;C({unappliedEvents:e.slice(p),replay:{progress:Math.min(1,f),appliedCount:p,totalCount:r,startTime:t,endTime:s,currentTime:E?Yt(E)??I?.currentTime??t:I?.currentTime??t,currentLabel:E?fd(E):I?.currentLabel??"",flashNodeIds:E?[...new Set(g)]:I?.flashNodeIds??[]}})},l)};var gl=async()=>{let e=Oe(v().breadCrumb,"BOARD");if(d(e))return e;let t=await gt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Re({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=X().commandMeta;if(En(),r==="now"){let c=je(n.value);if(d(c))return a(c.message);let l=it();if(d(l))return l;let p=st(c.value).filter(d);return p.length>0?a(p.map(f=>f.message).join(", ")):(C({mode:y.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),u("Peeking now",!0))}let s;if(r==="prev"){let c=v().eventLog.at(-1),l=Yt(c);if(l===null)return a("No previous event to peek");s=l}else if(r==="next"){let c=v().unappliedEvents.at(0),l=Yt(c);if(l===null)return a("No next event to peek");s=l+1}else{let c=yn(r||o.trim());if(!c)return a("Invalid peek date");s=c.getTime()}let i=zo({boardId:e.value.id,targetTime:s,stateBranchRoot:n.value,selectedIndex:0});return d(i)?i:(C({mode:y.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:i.value.unappliedEvents,replay:null}),u("Peeking",!0))};var vl=async()=>{let e=Oe(v().breadCrumb,"BOARD");if(d(e))return e;let t=await gt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Re({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=X().commandMeta,{dateInput:s,durationInput:i}=No(r,o);if(En(),v().syncStatus.status==="syncing")return a("Cannot replay while syncing, try again in a moment");let c=yn(s);if(!c)return a("Invalid replay date");let l=i?Co(i):15e3;if(l===null)return a("Invalid replay duration (try e.g. 30s or 2m)");let m=c.getTime(),p=v(),f=zo({boardId:e.value.id,targetTime:m,stateBranchRoot:n.value,selectedIndex:-1});if(d(f))return f;let{unappliedEvents:g}=f.value;return g.length===0?(it(),C(p),u("Nothing to replay from that point",!0)):(fl({events:g,startTime:m,durationMs:l}),u("Replaying board history",!0))};import Fv from"zod";var yl=()=>{let e=X().commandMeta.inputString,t=Fv.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=Qe({autoSyncDebounceMs:t.data});return d(n)?n:(Me({autoSyncIntervalMs:t.data}),C({mode:y.DEFAULT}),u(`Auto sync interval set to ${t.data}ms`,null))};var hl=()=>{let e=X().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=Wd(e),n=Qe({autoSync:t});return d(n)?n:(Me({autoSync:t}),C({mode:y.DEFAULT}),u(`Auto sync set to "${e}"`,null))};var xl=()=>{let e=X().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=Qe({logLevel:e});return d(n)?n:(Me({logLevel:e}),C({mode:y.DEFAULT}),u(`Auto sync set to "${e}"`,null))};import{spawn as Uv}from"node:child_process";var Ov=()=>{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"]}}},bl=async e=>new Promise(t=>{let{command:n,args:r}=Ov();try{let o=Uv(n,r,{stdio:["pipe","ignore","ignore"]});o.on("error",()=>t(a(`Clipboard tool not available (${n})`))),o.on("close",s=>t(s===0?u("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 Nr=async(e,t)=>{if(!e.trim())return a(`Nothing to copy: ${t} is empty`);let n=await bl(e);return d(n)?n:u(`Copied ${t} to clipboard`,null)},Il=async e=>{let{breadCrumb:t,selectedNode:n}=v(),r=fr({breadCrumb:t,selectedNode:n}),o=r??n;if(!o)return a("Nothing selected to copy from");switch(e.modifier){case ye.REF:return Nr(He(o.id),"ref");case ye.TITLE:return Nr(o.title,"title");case ye.DESCRIPTION:return r?Nr(r.props?.description??"","description"):a("No issue in scope");case ye.TAGS:{if(!r)return a("No issue in scope");let s=zt(r).map(({name:i})=>i);return Nr(s.join(", "),"tags")}case ye.ASSIGNEES:{if(!r)return a("No issue in scope");let s=qt(r).map(({name:i})=>i);return Nr(s.join(", "),"assignees")}default:return a("Yank one of: ref, title, description, tags, assignees")}};var El=async()=>{V(""),C({mode:y.DEFAULT});let e=We();if(d(e))return a(e.message);if(e.value.syncStatus.status==="syncing")return a("Sync already in progress");C({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await xo();return d(t)?(C({syncStatus:{msg:t.message,status:"failed"}}),t):(C({mode:y.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var _v=e=>e.action==="add.issue.comment",Sl=e=>Object.values(v().tags).find(t=>t.name===e),Cl=()=>{let{eventLog:e=[],contributors:t}=v(),n=new Map,r=new Set;for(let o of e)o.userId&&(n.set(o.userId,o.userName??""),r.add(o.userId));for(let o of Object.values(t)){if(o.tombstoned){n.set(o.id,o.name);continue}n.set(o.id,Fn(o.name,n.get(o.id))??o.name)}return[...n.entries()].map(([o,s])=>({id:o,name:s,isExternal:!r.has(o)}))},Dt=async()=>{let e=await yt();return d(e)?e:u("Resolved persist root",e.value)},Xo=[{systemOnly:!0,intent:k.Move,description:"Internal move-state command",mode:y.COMMAND_LINE,action:ul},{intent:k.Delete,description:"Delete the currently selected node",mode:y.COMMAND_LINE,action:async()=>{let e=ae();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=z(t.id)[n];if(!r)return a("Unable to resolve child to delete");let o=await Dt();if(d(o))return o;if(r.context==="COMMENT"){let s=r.id,i=T(t)?t.id:t.parentNodeId;if(!i)return a("Unable to resolve comment issue");let c=v().nodes[i];if(!c||!T(c))return a("Unable to resolve comment issue");let l=c.log?.filter(_v).find(m=>m.payload.id===s);return l?l.payload.author!==e.value.userId?a("You can only delete your own comments"):U([{id:Be(),action:"delete.issue.comment",payload:{id:s,issue:i},...e.value}],o.value):a("Unable to resolve comment")}return U([{id:Be(),action:"delete.node",payload:{id:r.id},...e.value}],o.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:y.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=X().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(i=>de(b.FILTER).map(c=>c.split(n)[0]).includes(i))(r))return a("Invalid filter modifier");let s={target:r,operator:"=",value:t.trim()};return pe(i=>({...i,filters:e==="clear"?[]:[...i.filters,s],mode:y.DEFAULT})),u("Filter updated",null)}},{intent:k.ViewHelp,description:"Open the help screen",mode:y.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return en({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),C({mode:y.HELP}),u("Viewing help",null)}},{intent:k.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:y.COMMAND_LINE,action:async()=>{let e=ae();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=z(t.id)[n];if(!r)return a("Unable to close issue, no target found");if(!T(r))return a("Cannot close in this context");let o=v().nodes[ve];if(!o)return a("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return a("Issue is already closed");let s=await Dt();if(d(s))return s;let i=s.value,c=fn(o.id,r.id,{at:"end"},e.value,i);if(d(c))return c;let l=U([{id:Be(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:c.value},...e.value}],i);return d(l)?l:u("Issue closed",null)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:y.COMMAND_LINE,action:async()=>{let e=ae();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=z(t.id)[n];if(!r)return a("Unable to reopen issue, no target found");let o=r.context==="TICKET"?u("Resolved ticket",r):At(r.id,"TICKET");if(d(o))return a("Cannot reopen in this context");let s=o.value,i=v().nodes[ve];if(!i)return a("Unable to locate closed swimlane");if(s.parentNodeId!==i.id)return a("Issue is not closed");if(!T(s))return a("Target node is not issue");let c=Ho(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 l=v().nodes[c];if(!l)return a("Previous parent no longer exists");let m=await Dt();if(d(m))return m;let p=m.value,f=fn(l.id,s.id,{at:"end"},e.value,p);if(d(f))return f;let g=U([{id:Be(),action:"reopen.issue",payload:{id:s.id,parent:l.id,rank:f.value},...e.value}],p);return d(g)?g:u("Issue reopened",null)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Init,description:"Initialize Epiq in the current git repository",mode:y.COMMAND_LINE,action:sl},{intent:k.NewItem,description:"Create a new board, swimlane, or issue",mode:y.COMMAND_LINE,action:ml,onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Rename,description:"Rename the currently selected node",mode:y.COMMAND_LINE,action:async()=>{let e=ae();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=z(t.id)[n];if(!r)return a("Missing node");if(r.readonly)return a("Cannot rename readonly node");let o=Ec();if(!o)return a("Provide a title");let s=await Dt();return d(s)?s:U([{id:Be(),action:"edit.title",payload:{id:r.id,name:o},...e.value}],s.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.UntagTicket,description:"Remove a tag from the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=ae();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=X().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let o=Sl(r);if(!o)return a(`Tag "${r}" does not exist`);let{selectedNode:s}=v();if(!s)return a("Invalid untag target");let i=At(s.id,"TICKET");if(d(i))return a("Unable to untag issue in this context");let c=i.value;if(!T(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 Dt();return d(m)?m:U([{id:Be(),action:"remove.issue.tag",payload:{id:c.id,tag:o.id},...e.value}],m.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.TagTicket,description:"Add or create a tag on the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=ae();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=X().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let{selectedNode:o}=v();if(!o)return a("Invalid tag target");let s=At(o.id,"TICKET");if(d(s))return a("Unable to tag issue in this context");let i=s.value;if(!T(i))return a("Target node is not issue");let c=await Dt();if(d(c))return c;let l=Sl(r),m=l?.id??Be();return(i.props.tags??[]).includes(m)?a("Already tagged with that tag"):U([...l?[]:[{id:Be(),action:"create.tag",payload:{id:m,name:r},...e.value}],{id:Be(),action:"add.issue.tag",payload:{id:i.id,tag:m},...e.value}],c.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.AssignUserToTicket,description:"Assign a user to the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=ae();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=X().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee");let o=r.startsWith("!"),s=(o?r.slice(1):r).trim();if(!s)return a("Provide an assignee");let{selectedIndex:i,contextNode:c}=v(),l=z(c.id)[i];if(!l)return a("Invalid assign target");let m=At(l.id,"TICKET");if(d(m))return a("Unable to assign issue in this context");let p=m.value;if(!T(p))return a("Target node is not issue");let f=await Dt();if(d(f))return f;let g=Cl(),E=!o&&s.toLowerCase()==="me",I,R;if(E)I=e.value.userId,R=g.find(_=>_.id===I)?.name??e.value.userName;else{let _=g.filter(W=>W.name===s);if(_.length>1)return a(`"${s}" matches ${_.length} contributors (${_.map(W=>W.id).join(", ")}). Assign from the GUI to choose by id.`);let w=_[0];if(!w&&!o)return a(`No contributor named "${s}". Use "!${s}" to add them as an external assignee.`);I=w?.id??Be(),R=w?.name??s}if((p.props.assignees??[]).includes(I))return a("Assignee already assigned");let P=!!v().contributors[I];return U([...P?[]:[{id:Be(),action:"create.contributor",payload:{id:I,name:R},...e.value}],{id:Be(),action:"add.issue.assignee",payload:{id:p.id,assignee:I},...e.value}],f.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=ae();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=X().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee to remove");let{selectedNode:o}=v();if(!o)return a("Invalid unassign target");let s=At(o.id,"TICKET");if(d(s))return a("Unable to unassign in this context");let i=s.value;if(!T(i))return a("Target node is not issue");let c=i.props.assignees??[],l=r.toLowerCase()==="me",m=l?c.filter(g=>g===e.value.userId):Cl().filter(g=>g.name===r&&c.includes(g.id)).map(g=>g.id);if(m.length>1)return a(`"${r}" matches ${m.length} assignees (${m.join(", ")}). Unassign from the GUI to choose by id.`);let p=m[0];if(!p)return a(l?"Issue is not assigned to you":`Issue is not assigned to "${r}"`);let f=await Dt();return d(f)?f:U([{id:Be(),action:"remove.issue.assignee",payload:{id:i.id,assignee:p},...e.value}],f.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Comment,description:"Add a comment to the selected issue",mode:y.COMMAND_LINE,action:async(e,t)=>{let n=t.inputString.trim();if(!n)return a("Provide a comment");if(n.length>4e3)return a(`Cannot exceed ${4e3} characters`);let r=ae();if(d(r))return a("Unable to resolve user ID");let{breadCrumb:o,selectedNode:s}=v(),i=Oe([...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 l=c.context==="TICKET"?u("Resolved ticket",c):At(c.id,"TICKET");if(d(l))return a("Unable to comment on issue in this context");let m=l.value;if(!T(m))return a("Target node is not issue");let p=await Dt();return d(p)?p:U([{id:Be(),action:"add.issue.comment",payload:{id:Be(),issue:m.id,author:r.value.userId,md:n},...r.value}],p.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Sync,description:"Pull, commit, and push Epiq state",mode:y.COMMAND_LINE,action:El},{intent:k.Peek,description:"View board state at another point in time",mode:y.COMMAND_LINE,action:gl},{intent:k.Replay,description:"Replay board history forward from a point in time",mode:y.COMMAND_LINE,action:vl},{intent:k.Export,description:"Export the current board layout to markdown",mode:y.COMMAND_LINE,action:async()=>{let e=await zc();return d(e)?e:(C({mode:y.DEFAULT}),u("Export successful",!0))}},{intent:k.Exit,description:"Exit the application",mode:y.COMMAND_LINE,action:async()=>(M.exit(),u("Exit successful",!0))},{intent:k.Edit,description:"Edit title or description",mode:y.COMMAND_LINE,action:async(e,t)=>nl(t),onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Yank,description:"Yank (copy) ref, title, description, tags, or assignees to the clipboard",mode:y.COMMAND_LINE,action:async(e,t)=>Il(t),onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:y.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case oe.USERNAME:{let{userId:r,preferredEditor:o,userName:s}=K(),i=n||s,c=r??Be();if(!i||!c)return a("Unable to resolve user name or id");let l=Qe({userName:i,userId:c,preferredEditor:o??""});return d(l)?l:(Me({userName:i,userId:c}),C({mode:y.DEFAULT}),u(`Username set to "${i}"`,null))}case oe.EDITOR:{if(!n)return a("No editor provided");let r=Qe({preferredEditor:n});return d(r)?r:(Me({preferredEditor:n}),C({mode:y.DEFAULT}),u(`Editor configuration set to "${n}"`,null))}case oe.VIEW:{if(n!=="wide"&&n!=="dense")return a("Invalid view mode");let r=Qe({viewMode:n});return d(r)?r:(Me({viewMode:n}),C({mode:y.DEFAULT}),u(`View set to "${n}"`,null))}case oe.AUTOSYNC:return hl();case oe.LOG_LEVEL:return xl();case oe.SYNC_DEBOUNCE_MS:return yl();case oe.ATTACHMENT_MAX_KB:return nc();default:return a("Unknown config command")}}},{intent:k.Coffee,description:"Sponsor the development of Epiq!",mode:y.COMMAND_LINE,action:()=>{let e=X().commandMeta.modifier;return e==="custom"?Sr("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):Sr(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),V(""),u("Thanks you!",null)}}];var $v=new Set(["peek","replay","filter","view-help","yank"]),St=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=X();if(!t)return a("No command to confirm");if(!e&&n===bt.Invalid)return a("Invalid command");let s=Lo(t);yc();let{readOnly:i}=v();if(i&&!$v.has(s))return hr({status:Ut.Fail,message:"Command not available in readonly state",value:null});let c=Xo.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===s);if(!c)return hr({status:Ut.Fail,message:"Command not found",value:null});let l;try{l=await c.action(c,{command:t,inputString:o,modifier:r})}catch(m){return hr({status:Ut.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(l)?hr(l):(hc({addToHistory:!e}),c.onSuccess?.(),K().autoSync&&Io(),l)};var Jo=[{intent:x.Exit,mode:y.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(C({mode:y.COMMAND_LINE}),V("move cancel"),St({isForceExecutedBySystem:!0}))},{intent:x.InitMove,mode:y.DEFAULT,description:"[m] move (init/confirm)",action:()=>(C({mode:y.COMMAND_LINE}),V("move start"),St({isForceExecutedBySystem:!0}))},{intent:x.ConfirmMove,mode:y.MOVE,action:()=>(C({mode:y.COMMAND_LINE}),V("move confirm"),St({isForceExecutedBySystem:!0}))}],Qo=[{intent:x.MovePreviousItem,mode:y.MOVE,action:()=>tn()?(C({mode:y.COMMAND_LINE}),V("move previous"),St({isForceExecutedBySystem:!0})):a("No pending move")},{intent:x.MoveNextItem,mode:y.MOVE,action:()=>tn()?(C({mode:y.COMMAND_LINE}),V("move next"),St({isForceExecutedBySystem:!0})):a("No pending move")}],Nl=[{intent:x.MoveToNextContainer,mode:y.MOVE,action:()=>tn()?(C({mode:y.COMMAND_LINE}),V("move to-next"),St({isForceExecutedBySystem:!0})):a("No pending move")},{intent:x.MoveToPreviousContainer,mode:y.MOVE,action:()=>tn()?(C({mode:y.COMMAND_LINE}),V("move to-previous"),St({isForceExecutedBySystem:!0})):a("No pending move")}];var Rl={[B.WORKSPACE]:[...Jo,...Qo],[B.BOARD]:[...Jo,...Qo],[B.SWIMLANE]:[...Jo,...Qo,...Nl],[B.TICKET]:[],[B.FIELD]:[],[B.FIELD_LIST]:[],[B.TEXT]:[],[B.COMMENT]:[]};import Hv from"node:fs";import jv from"node:path";var Al=e=>{let t=$e(process.cwd());if(d(t))return a("Unable to resolve project root");let n=Re({repoRoot:t.value});if(d(n))return a(n.message);let r=Dn(e.hash,e.ext),o=jv.join(rr(n.value),r);return Hv.existsSync(o)?(Sr(o),u(`Opened ${e.name}`,null)):a("Attachment file not found \u2014 run :sync to fetch it")};var Tl=()=>{V("");let{pendingNavTarget:e}=Zt();C({mode:y.DEFAULT}),e&&M.navigate(e),en({pendingNavTarget:void 0})},wl=[{intent:x.ExitCommandLine,mode:y.HELP,action:()=>(Tl(),u("Exiting help",null))},{intent:x.Exit,mode:y.HELP,action:()=>(Tl(),u("Closed help",null))},{intent:x.NavPreviousItem,mode:y.HELP,description:"[arrows/hjkl] navigate",action:()=>(M.navigateToPreviousItem(),u("Navigating to previous help item",null))},{intent:x.NavNextItem,mode:y.HELP,action:()=>(M.navigateToNextItem(),u("Navigating to next help item",null))},{intent:x.NavToPreviousContainer,mode:y.HELP,action:()=>(M.navigateToPreviousContainer(),u("Navigating to previous help container",null))},{intent:x.NavToNextContainer,mode:y.HELP,action:()=>(M.navigateToNextContainer(),u("Navigating to next help container",null))}];var Wv=e=>{C({mode:y.COMMAND_LINE});let{pendingNavTarget:t}=Zt();t&&M.navigate(t),en({pendingNavTarget:void 0}),V(`${e} `)},Ml=()=>{V("");let{pendingNavTarget:e}=Zt();e&&M.navigate(e),en({pendingNavTarget:void 0}),C({mode:y.DEFAULT})},Pl=[{intent:x.InitCommandPalette,mode:y.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{V("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return en({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),C({mode:y.PALETTE}),u("Opening command palette",null)}},{intent:x.Confirm,mode:y.PALETTE,action:()=>{let{selectedNode:e}=v();if(!e||!$t(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?(Wv(t),u("Selected command",t)):u("No command selected",null)}},{intent:x.ExitCommandLine,mode:y.PALETTE,action:()=>(Ml(),u("Exiting palette",null))},{intent:x.Exit,mode:y.PALETTE,action:()=>(Ml(),u("Closed command palette",null))},{intent:x.NavPreviousItem,mode:y.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(M.navigateToPreviousItem(),u("Navigating to previous item",null))},{intent:x.NavNextItem,mode:y.PALETTE,action:()=>(M.navigateToNextItem(),u("Navigating to next item",null))},{intent:x.NavToPreviousContainer,mode:y.PALETTE,action:()=>(M.navigateToPreviousContainer(),u("Navigating to previous container",null))},{intent:x.NavToNextContainer,mode:y.PALETTE,action:()=>(M.navigateToNextContainer(),u("Navigating to next container",null))}];var Ll=[...wl,...Pl,{intent:x.AddItem,mode:y.DEFAULT,description:"[n] new...",action:()=>(C({mode:y.COMMAND_LINE}),V(`${b.NEW} `),u("Adding new item",null))},{intent:x.Delete,mode:y.DEFAULT,description:"[d] delete",action:()=>(C({mode:y.COMMAND_LINE}),V(`${b.DELETE} `),u("Deleting item",null))},{intent:x.InitCommandLine,mode:y.DEFAULT,description:"[:] focus command line",action:()=>(C({mode:y.COMMAND_LINE}),V(""),u("Entering command line mode",null))},{intent:x.Confirm,mode:y.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=v();if(!Y(e?.id??"")?.length){let r=e?S.getAttachment(e.id):void 0;if(r)return Al(r);if(e?.title===Z.DESCRIPTION)return C({mode:y.COMMAND_LINE}),V(`${b.EDIT} description `),u("Propose command",!0);if(e?.title===Z.ASSIGNEES)return C({mode:y.COMMAND_LINE}),V(`${b.ASSIGN} `),u("Propose command",!0);if(e?.title===Z.TAGS)return C({mode:y.COMMAND_LINE}),V(`${b.TAG} `),u("Propose command",!0);if(t.title===Z.DESCRIPTION&&e?.context==="TEXT")return C({mode:y.COMMAND_LINE}),V(`${b.EDIT} description `),u("Propose command",!0)}return M.enterChildNode(),u("Entering context",null)}},{intent:x.Yank,mode:y.DEFAULT,description:"[y] yank to clipboard",action:()=>{let{selectedNode:e}=v(),t=e?.title===Z.DESCRIPTION?ye.DESCRIPTION:e?.title===Z.TAGS?ye.TAGS:e?.title===Z.ASSIGNEES?ye.ASSIGNEES:ye.REF,r=de(b.YANK).includes(t)?t:ye.REF;return C({mode:y.COMMAND_LINE}),V(`${b.YANK} ${r}`),u("Propose command",!0)}},{intent:x.EditTitle,mode:y.DEFAULT,description:"[r] rename title",action:()=>(C({mode:y.COMMAND_LINE}),V(`${b.EDIT} title ${v().selectedNode?.title}`),u("Exiting context",null))},{intent:x.EditDescription,mode:y.DEFAULT,description:"[e] edit description",action:()=>(C({mode:y.COMMAND_LINE}),V(`${b.EDIT} description `),u("Exiting context",null))},{intent:x.Exit,mode:y.DEFAULT,description:"[q] exit context",action:()=>(M.enterParentNode(),u("Exiting context",null))},{intent:x.NavPreviousItem,mode:y.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(M.navigateToPreviousItem(),u("Navigating to previous item",null))},{intent:x.NavNextItem,mode:y.DEFAULT,action:()=>(M.navigateToNextItem(),u("Navigating to next item",null))},{intent:x.NavToPreviousContainer,mode:y.DEFAULT,action:()=>(M.navigateToPreviousContainer(),u("Navigating to previous container",null))},{intent:x.NavToNextContainer,mode:y.DEFAULT,action:()=>(M.navigateToNextContainer(),u("Navigating to next container",null))}];var Vv=500,Gv=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),kl=e=>{let t=Gv(e);t&&Po(n=>(n+t).slice(0,Vv))};var Kv=[y.COMMAND_LINE,y.PALETTE],zv=e=>[{intent:x.MoveCursorLeft,mode:e,action:()=>(gi(-1),u("Moving cursor left",null))},{intent:x.MoveCursorRight,mode:e,action:()=>(gi(1),u("Moving cursor right",null))},{intent:x.MoveCursorLeftOfWord,mode:e,action:()=>(vi("left"),u("Moving cursor left of word",null))},{intent:x.MoveCursorRightOfWord,mode:e,action:()=>(vi("right"),u("Moving cursor right of word",null))},{intent:x.AutoCompleteCommand,mode:e,action:()=>(Po((t,{remainder:n})=>{let r=n?t+n:t,o="";return r==="edit title "&&(o=v().selectedNode?.title??""),r+o}),u("Auto-completing command",null))},{intent:x.CaptureInput,mode:e,action:(t,{sequence:n})=>(kl(n??""),u("Capturing input",null))},{intent:x.EraseInput,mode:e,action:()=>(gc(),u("Erasing input",null))},{intent:x.EraseInputWord,mode:e,action:()=>(vc(),u("Erasing input word",null))}],Dl=[{intent:x.Confirm,mode:y.COMMAND_LINE,action:()=>(St(),u("Executing command",null))},{intent:x.ViewHelp,mode:y.DEFAULT,action:()=>(C({mode:y.HELP}),u("Viewing help",null))},...Kv.flatMap(zv),{intent:x.ExitCommandLine,mode:y.COMMAND_LINE,action:()=>(C({mode:y.DEFAULT}),u("Exiting command line",null))},{intent:x.GetLastCommandFromHistory,mode:y.COMMAND_LINE,action:()=>(xc(),u("Getting last command from history",null))},{intent:x.GetNextCommandFromHistory,mode:y.COMMAND_LINE,action:()=>(bc(),u("Getting next command from history",null))}];import Ul from"chalk";var Zo=Ul.dim.hex(h.secondary2)(": for command line"),Bl="q to exit",Fl=`${Ul.hex(h.accent)("m")} to confirm`,ki={[B.WORKSPACE]:[Zo],[B.BOARD]:[Zo],[B.BOARD+y.COMMAND_LINE]:[Zo],[B.SWIMLANE]:[Zo],[B.TICKET+y.HELP]:[Bl],[B.SWIMLANE+y.HELP]:[Bl],[B.TICKET]:[],[B.FIELD]:[],[B.SWIMLANE+y.MOVE]:[Fl],[B.TICKET+y.MOVE]:[Fl]};var Rr=e=>e.trim().toLocaleLowerCase(),qv=e=>{let{tags:t}=v();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},Yv=e=>{let{contributors:t}=v();return(e.props.assignees??[]).map(n=>{let r=t[n];return r?Xt(n,r.name):void 0}).filter(n=>!!n)},Ol=(e,t)=>{let n=Rr(t.value);if(!n)return!0;switch(t.target){case"title":return Rr(e.title??"").includes(n);case"description":return Rr(e.props.description??"").includes(n);case"tag":return qv(e).map(Rr).some(o=>o.includes(n));case"assignee":return Yv(e).map(Rr).some(o=>o.includes(n));case"ref":return sd(e.id,t.value);default:return!0}};function _l(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(),u("Breadcrumb built",o))}var $l=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 Bt,Di,Bi=new Set,Fi=()=>{for(let e of Bi)e()},Jv=e=>(Bi.add(e),()=>Bi.delete(e));function Ui(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 l=_l(t,o,r);if(d(l))return logger.error(l.message),l;let m=l.value,{context:p}=c,f=ki[p+n]??ki[p]??[],g=[...Ll,...Rl[p]??[],...Dl],E=$l(g),I=Qv(o,s),R=I[t]?.[e.selectedIndex]??null;return u("Derived successfully",{...e,contextNode:c,breadCrumb:m,availableHints:f,availableActions:g,actionIndex:E,selectedNode:R,renderedChildrenIndex:I})}var v=()=>{if(!Bt)throw new Error("State not initialized. Call initWorkspaceState() first.");return Bt},We=()=>Bt?u("Retrieved state",Bt):a("State not initialized. Call initWorkspaceState() first.");function cr(e){Di=e;let t=$e(process.cwd()),n=!1;if(!d(t)){let s=ut(t.value);if(d(s))return a(s.message);n=!0}let r={readOnly:!1,filters:[],tags:{},contributors:{},mode:y.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=Ui(r);return d(o)?o:(Bt=o.value,Fi(),u("State initialized",null))}var Ar=!1,es=null;function pe(e){let t=v(),n=e(t);if(Ar)return es=n,Bt={...t,...n},u("State updated",null);let r=Ui(n);return d(r)?a(r.message??"Unable to update state"):(Bt=r.value,Fi(),u("State updated",null))}function xd(e){if(Ar)return u("Joined batch",e());Ar=!0,es=null;let t=()=>{let n=es;if(Ar=!1,es=null,n===null)return null;let r=Ui(n);return d(r)?a(r.message??"Unable to update state"):(Bt=r.value,Fi(),u("State updated",null))};try{let n=e(),r=t();return r&&d(r)?a(r.message):u("State updated",n)}finally{Ar&&t()}}var C=e=>pe(t=>({...t,...e}));var j=()=>Xv(Jv,v,v),Qv=(e,t)=>{let n={};for(let r of Object.values(e))T(r)&&t.length>0&&!t.every(o=>Ol(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},z=e=>v()?.renderedChildrenIndex[e]??[],it=()=>Di?cr(Di):a("Cannot reset state: no initial workspace found"),Gt=()=>Bt!==void 0;var Oi=e=>{Gt()&&(C({syncStatus:e}),_t({type:"sync-status",payload:e}))},ts=(e="Syncing...")=>{Oi({status:"syncing",msg:e})},ns=(e="Synced")=>{Oi({status:"synced",msg:e})},_i=e=>{Oi({status:"failed",msg:e})},et=e=>(_i(e),a(e));import{decodeTime as HD}from"ulid";var Zv=async({cwd:e,ensureUpstream:t})=>{logger.debug("[sync] ensureSyncReady:start",{cwd:e,ensureUpstream:t});let n=J("getRepoRootDir",await gt(e));if(d(n))return a(n.message);let r=n.value;logger.debug("[sync] repo root",r);let o=J("getStateBranchRoot",Re({repoRoot:r}));if(d(o))return a(o.message);let s=o.value;logger.debug("[sync] state branch root",s);let i=J("ensureInitialCommit",await $a(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=J("bootstrapStateBranchStorage",await Wa({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 l=J("hasInProgressGitOperation(stateBranchRoot)",await Wr(s));if(d(l))return a(l.message);if(logger.debug("[sync] state branch git operation check result",{inProgress:l.value}),l.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=J("ensureStateBranchLayout",Aa(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}),u("Sync preconditions satisfied",{repoRoot:r,stateBranchRoot:s,bootstrapped:c.value}))},ey=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=J("stageStateBranchOwnEventFile",await Zr({stateBranchRoot:t,eventFileName:n}));if(d(r))return a(r.message);let o=J("stageStateBranchMediaFiles",await Ha({stateBranchRoot:t}));if(d(o))return a(o.message);let s=J("hasStagedChanges(after stage)",await ba(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"),u("No own event file changes to commit",{createdCommit:!1});logger.debug("[sync] creating sync commit");let i=J("createStateBranchSyncCommit",await ja({repoRoot:e,stateBranchRoot:t}));return d(i)?a(i.message):(logger.debug("[sync] created sync commit",i.value),u("Committed own event file",{createdCommit:!0,commitSha:i.value}))},bo=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");ts();let n=J("ensureSyncReady",await Zv({cwd:e,ensureUpstream:!0}));if(d(n))return et(n.message);let{repoRoot:r,stateBranchRoot:o,bootstrapped:s}=n.value,i=J("isDetachedHead(stateBranchRoot)",await Ia(o));if(d(i))return et(i.message);if(logger.debug("[sync] detached state branch check result",{detached:i.value}),i.value)return et("Cannot run :sync while the state branch is in detached HEAD state");let c=!1,l,m=!1,p=!1,f=J("getStateBranch",Nn(r));if(d(f))return et(f.message);let g=f.value;logger.debug("[sync] resolved state branch",{stateBranch:g,stateBranchRoot:o});let E=J("commitOwnEventFileToStateBranch",await ey({repoRoot:r,stateBranchRoot:o,ownEventFileName:t}));if(d(E))return et(E.message);c=E.value.createdCommit,l=E.value.commitSha;let I=J("pullBranchRebaseIfPresent",await Bs({cwd:o,branch:g}));if(d(I))return et(I.message);if(m=I.value,c||s){logger.info("[sync] pushing state branch",{createdCommit:c,bootstrapped:s,stateBranchRoot:o});let R=J("pushStateBranch",await sr({stateBranchRoot:o,repoRoot:r}));if(d(R)&&xa(R.message)){let A=J("pullBranchRebaseIfPresent(retry)",await Bs({cwd:o,branch:g}));if(d(A))return et(A.message);m=m||A.value,R=J("pushStateBranch(retry)",await sr({stateBranchRoot:o,repoRoot:r}))}if(d(R))return et(R.message);p=R.value}if(c){logger.debug("[sync] resolving final sync commit sha",{stateBranchRoot:o});let R=J("git rev-parse HEAD",await F({args:["rev-parse","HEAD"],cwd:o}));if(d(R))return et(R.message);l=R.value.stdout.trim(),logger.debug("[sync] final sync commit sha",l)}return ns(p?"Synced and pushed":m||c?"Synced local state":"Already synced"),logger.debug("[sync] syncEpiqWithRemote:done"),u("Synced event logs with state branch",{repoRoot:r,stateBranchRoot:o,createdCommit:c,commitSha:l,pulled:m,pushed:p,bootstrapped:s})};import{existsSync as $i}from"node:fs";import{chmod as Hi}from"node:fs/promises";import zl from"node:os";import Hn from"node:path";var Hl=(e,t)=>e.reduce((n,r)=>r<n?r:n,t);var jl=1e5,ty=2e4,rs=null,Wl=Promise.resolve(),nn=e=>{let t=Wl.then(e,e);return Wl=t.then(()=>{},()=>{}),t},ji=e=>{let t=$e(e??process.cwd());return d(t)?a(t.message):u("Resolved Epiq repo root",t.value)},Wi=e=>{let t=ji(e);return d(t)?t:Re({repoRoot:t.value})},at=()=>{if(!Gt())return{mode:"live",asOfTime:null};let{timeMode:e}=v();return e==="live"?{mode:"live",asOfTime:null}:{mode:"scrub",asOfTime:rs}},ny=e=>{let t=new Map;for(let n of e){if(n.action!=="create.tag"&&n.action!=="create.contributor")continue;let r=n.payload;r?.id&&r.name&&t.set(r.id,r.name)}return t},ry=(e,t)=>{let n=e.payload,r=n?.tag!==void 0?t.get(n.tag)??"":n?.assignee!==void 0?t.get(n.assignee)??"":n?.name!==void 0?`"${n.name}"`:"";return[e.action?lo(e.action):"",r].filter(Boolean).join(" ")},Vl=(e,t)=>{if(!e)return null;let n=t.get(e)??e;return{id:e,name:n,color:te(n)}},oy=(e,t)=>{let n=e.payload;return{actor:e.userId?{id:e.userId,name:e.userName??e.userId,color:te(e.userName??e.userId)}:null,tag:Vl(n?.tag,t),assignee:Vl(n?.assignee,t)}},Vi=(e,t)=>{let n=new Map,r=new Set,o=i=>{let c=new Set,l=i;for(;l&&!c.has(l);){if(r.has(l))return l;c.add(l),l=n.get(l)}return null},s=[];for(let i of e){let c=i.payload,l=c?.id;if(!l)continue;i.action==="add.board"&&r.add(l);let m=c.parent??c.issue;m&&n.set(l,m),(l===t||o(l)===t)&&s.push(i)}return s},ql=async(e={})=>{let t=Wi(e.repoRoot);if(d(t))return a(t.message);let n=je(t.value);if(d(n))return a(n.message);let r=e.boardId?Vi(n.value,e.boardId):n.value,o=ny(n.value),s=r.flatMap(I=>{let R=Yt(I);return R===null?[]:[{t:R,action:I.action,label:ry(I,o),...oy(I,o)}]}),i=Date.now(),c=e.end??i,l=e.start??Hl(s.map(I=>I.t),c);if(c<=l)return u("Empty time window",{bucketMs:0,buckets:[],events:[],earliest:l,latest:c});let m=s.filter(I=>I.t>=l&&I.t<c).sort((I,R)=>I.t-R.t),p=m.map(I=>I.t),f=Math.max(1,Math.ceil((c-l)/jl)),g=new Map;for(let I of p){let R=Math.min(jl-1,Math.floor((I-l)/f)),A=l+R*f;g.set(A,(g.get(A)??0)+1)}let E=[...g.entries()].sort(([I],[R])=>I-R).map(([I,R])=>({t:I,count:R}));return u("Computed event timeline",{bucketMs:f,buckets:E,events:m.length>ty?[]:m,earliest:l,latest:c})},Tr="",Gl="",Yl=async(e={})=>{let t=ji(e.repoRoot);if(d(t))return a(t.message);let n=ut(t.value);if(d(n))return a(n.message);let r=await F({cwd:t.value,args:["log","--branches","--not",n.value.stateBranch,...e.start!==void 0?[`--since=@${Math.floor(e.start/1e3)}`]:[],...e.end!==void 0?[`--until=@${Math.floor(e.end/1e3)}`]:[],"--shortstat",`--format=${Gl}%H${Tr}%at${Tr}%an${Tr}%s`]});if(d(r))return a(r.message);let o=r.value.stdout.split(Gl).filter(s=>s.trim().length>0).map(s=>{let[i,...c]=s.split(`
59
59
  `),[l,m,p,...f]=(i??"").split(Tr);if(!l||!m)return null;let g=c.join(" "),E=Number(/(\d+) insertion/.exec(g)?.[1]??0),I=Number(/(\d+) deletion/.exec(g)?.[1]??0);return{sha:l,time:Number(m)*1e3,author:p??"unknown",subject:f.join(Tr),linesChanged:E+I}}).filter(s=>s!==null);return u("Computed commit timeline",o)},sy=e=>/^[0-9a-f]{7,40}$/i.test(e),iy=async(e,t)=>{let n=await F({cwd:e,args:["show",t]});if(d(n))return a(n.message);let r=Hn.join(zl.tmpdir(),"epiq","commit-diffs");be.mkDir(r);let o=Hn.join(r,`${t}.diff`);return $i(o)||(be.writeToFile(o,n.value.stdout),await Hi(o,292)),tl(o)},ay=12,dy=800,Kl=async(e,t,n)=>{let r=await F({cwd:e,args:["show",`${t}:${n}`]});return d(r)?"":r.value.stdout},cy=async(e,t,n)=>{let r=await F({cwd:e,args:["diff-tree","--no-commit-id","--name-only","-r",t]});if(d(r))return a(r.message);let o=r.value.stdout.split(`
60
- `).map(f=>f.trim()).filter(Boolean);if(o.length===0)return a("No changed files found for this commit");if(o.length>ay)return a(`Commit touches ${o.length} files \u2014 too many for a side-by-side view`);let s=Hn.join(zl.tmpdir(),"epiq","commit-diffs",t),i=await Promise.all(o.map(async(f,g)=>{let[E,I]=await Promise.all([Kl(e,`${t}~1`,f),Kl(e,t,f)]),R=Hn.basename(f),A=Hn.join(s,String(g),"before",R),P=Hn.join(s,String(g),"after",R);return $i(A)||(be.writeToFile(A,E),await Hi(A,292)),$i(P)||(be.writeToFile(P,I),await Hi(P,292)),{beforePath:A,afterPath:P}})),[c,...l]=i;if(!c)return a("No changed files found for this commit");let m=await Ai(n,c.beforePath,c.afterPath,"new");if(d(m)||l.length===0)return m;await new Promise(f=>setTimeout(f,dy));let p=await Promise.all(l.map(({beforePath:f,afterPath:g})=>Ai(n,f,g,"reuse")));for(let f of p)d(f)&&logger.error(`Failed to open an additional diff tab for ${t}: ${f.message}`);return m},Xl=async e=>{if(!sy(e.sha))return a("Invalid commit sha");let t=ji(e.repoRoot);if(d(t))return a(t.message);let n=t.value,r=Wo()[0];if(r&&Ri(r)){let o=await cy(n,e.sha,r);if(!d(o))return o;logger.error(`Side-by-side diff failed for ${e.sha}, falling back to unified diff: ${o.message}`)}return iy(n,e.sha)},Jl=e=>{let t=je(e);if(d(t))return a(t.message);let n=it();if(d(n))return a(n.message);rs=null;let o=st(t.value).filter(d);return o.length>0?a(o.map(s=>s.message).join(", ")):(C({readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),u("Restored live state",!0))},ly=(e,t)=>{rs=null;let n=Jl(e);return d(n)?a(`${t} (recovery to live also failed: ${n.message})`):a(t)},Ql=e=>nn(async()=>{let t=Wi(e.repoRoot);if(d(t))return a(t.message);let n=fo(t.value,e.targetTime);if(d(n))return a(n.message);let{appliedEvents:r,unappliedEvents:o}=n.value,s=it();if(d(s))return s;let c=st(r).filter(d);return c.length>0?ly(t.value,c.map(l=>l.message).join(", ")):(C({readOnly:!0,timeMode:"peek",unappliedEvents:o,replay:null}),rs=e.targetTime,u("Checked out historical state",{asOfTime:e.targetTime}))}),Zl=(e={})=>nn(async()=>{let t=Wi(e.repoRoot);if(d(t))return a(t.message);let n=Jl(t.value);return d(n)?a(n.message):u("Returned to live state",!0)});var Gi=()=>{let e=Ot();return d(e)?xt:e.value.attachmentMaxKb??xt},Ki=e=>{let t=$e(e??process.cwd());return d(t)?a(t.message):u("Resolved Epiq repo root",t.value)},Ne=async(e,t)=>{let n=Ki(e);if(d(n))return n;let r=Re({repoRoot:n.value});if(d(r))return a(r.message);let o=Cn(),s=await un({repoRoot:n.value,stateBranchRoot:r.value,stateBranchName:o.stateBranch});if(d(s))return a(s.message);if(t?.pull??!1){let l=await F({cwd:r.value,args:["pull","--ff-only"]});d(l)&&le.info(3,l.message)}let i=je(r.value);if(d(i))return a(i.message);let c=gn(i.value);return d(c)?a(c.message):u("Booted Epiq state",{repoRoot:n.value,stateBranchRoot:r.value})},Ae=()=>{let e=Ot();return d(e)?a(e.message):e.value.userId?e.value.userName?u("Resolved actor",{userId:e.value.userId,userName:e.value.userName}):a("Unable to retrieve user name"):a("Unable to retrieve user id")},Fe=()=>{let e=We();return d(e)?a(e.message):e},tu=e=>(e.props.tags??[]).map(t=>S.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:te(t.name)})),zi=()=>{let e=We(),t=d(e)?[]:e.value.eventLog??[],n=new Map;for(let r of t)r.userId&&r.userName&&n.set(r.userId,r.userName);return n},nu=(e,t)=>{let n=new Map(e);for(let r of Object.values(t)){if(r.tombstoned){n.set(r.id,r.name);continue}n.set(r.id,Fn(r.name,n.get(r.id))??r.name)}return n},ru=(e,t=new Map)=>(e.props.assignees??[]).map(n=>S.getContributor(n)).filter(n=>n!=null).map(n=>{let r=n.tombstoned?n.name:Fn(n.name,t.get(n.id))??n.name;return{id:n.id,name:r,color:te(r)}});var ou=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Fe();if(d(n))return n;let r=n.value.nodes,o=zi(),s=Object.values(r).filter(T).filter(i=>!i.isDeleted).filter(i=>e.includeClosed||i.parentNodeId!==ve).filter(i=>e.boardId?(i.parentNodeId?r[i.parentNodeId]:void 0)?.parentNodeId===e.boardId:!0).map(i=>({id:i.id,ref:He(i.id),title:Ze(i.title),description:i.props.description??"",parentNodeId:i.parentNodeId,isClosed:i.parentNodeId===ve,readonly:!!i.readonly,tags:tu(i),assignees:ru(i,o)}));return u("Listed issues",s)},su=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=Ln(e.parentId,n.value,t.value.stateBranchRoot);if(d(o))return o;let s=Go({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:q(),...n.value,action:"edit.description",payload:{id:c,md:e.description}});let l=[];for(let f of e.tagNames??[]){let g=Ze(f).trim();if(!g||l.some(R=>R.name===g))continue;let E=Object.values(r.value.tags).find(R=>R.name===g),I=E?.id??q();E||i.push({id:q(),...n.value,action:"create.tag",payload:{id:I,name:g}}),i.push({id:q(),...n.value,action:"add.issue.tag",payload:{id:c,tag:I}}),l.push({id:I,name:g})}let m=[];for(let f of e.assigneeNames??[]){let g=Ze(f).trim();if(!g||m.some(R=>R.name===g))continue;let E=Object.values(r.value.contributors).find(R=>R.name===g),I=E?.id??q();E||i.push({id:q(),...n.value,action:"create.contributor",payload:{id:I,name:g}}),i.push({id:q(),...n.value,action:"add.issue.assignee",payload:{id:c,assignee:I}}),m.push({id:I,name:g})}let p=U(i,t.value.stateBranchRoot);return d(p)?a(p.message):u("Created issue",{id:c,title:e.title,parentId:e.parentId,description:e.description??"",tags:l,assignees:m})},iu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=fn(ve,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(r))return r;let o={id:q(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:ve,rank:r.value}},s=U([o],t.value.stateBranchRoot);return d(s)?a(s.message):u("Closed issue",{id:e.issueId})},au=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Target node is not issue");if(o.parentNodeId!==ve)return a("Issue is not closed");let s=Ho(o);if(!s)return a("Unable to resolve previous parent from issue history");if(s===ve)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=fn(i.id,o.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let l={id:q(),...n.value,action:"reopen.issue",payload:{id:o.id,parent:i.id,rank:c.value}},m=U([l],t.value.stateBranchRoot);return d(m)?a(m.message):u("Reopened issue",{id:o.id,parentId:i.id})},du=async e=>{let t=Ki(e.repoRoot);if(d(t))return t;let n=Ae();if(d(n))return n;let r=Re({repoRoot:t.value});if(d(r))return r;let o=je(r.value);if(d(o))return o;let s=gn(o.value);if(d(s))return s;let i=fn(e.parentId,e.issueId,e.position??{at:"end"},n.value,r.value);if(d(i))return i;let c={id:q(),...n.value,action:"move.node",payload:{id:e.issueId,parent:e.parentId,rank:i.value}},l=U([c],r.value);return d(l)?a(l.message):u("Moved issue",{id:e.issueId,parentId:e.parentId})};var os=async(e={})=>{ts();let t=Ki(e.repoRoot);if(d(t))return a("Sync failed");let n=Ae();if(d(n))return n;let r=await bo({cwd:t.value,ownEventFileName:pn(n.value)});return d(r)?(_i(r.message),r):(ns(),u("Synced",r.value))};var jn=()=>{let e=Fe();if(d(e))return e;let t=at(),n=t.mode!=="live",r=Object.values(e.value.nodes),o=r.filter(g=>to(g)&&!g.isDeleted),s=zi(),i=new Map,c=new Map;for(let g of r)if(!g.isDeleted){if(Ht(g)&&g.parentNodeId){let E=i.get(g.parentNodeId)??[];E.push(g),i.set(g.parentNodeId,E)}if(T(g)&&g.parentNodeId){let E=c.get(g.parentNodeId)??[];E.push(g),c.set(g.parentNodeId,E)}}let l=Ot();if(d(l))return l;let m={};for(let g of r.filter(T))g.isDeleted||(m[g.id]=S.getCommentsByIssue(g.id).map(E=>{let I=S.getContributor(E.authorId);return{id:E.id,issueId:E.issue,body:E.md,author:{id:E.authorId,name:I?.name??"Unknown",color:te(I?.name??E.authorId)},createdAt:eu(E.id)}}));let p=new Map;for(let g of e.value.eventLog)g.action==="add.issue.attachment"&&p.set(g.payload.id,g.payload.author);let f={};for(let g of r.filter(T))g.isDeleted||(f[g.id]=S.getAttachmentsByIssue(g.id).map(E=>({id:E.id,issueId:E.issue,name:E.name,fileName:Dn(E.hash,E.ext),bytes:E.bytes,createdAt:eu(E.id),canDelete:p.get(E.id)===l.value.userId})));return u("Retrieved Epiq GUI state",{boards:o.sort((g,E)=>g.rank.localeCompare(E.rank)).map(g=>({id:g.id,ref:He(g.id),title:g.title,swimlanes:(i.get(g.id)??[]).sort((E,I)=>E.rank.localeCompare(I.rank)).map(E=>({id:E.id,title:E.title,readonly:!!E.readonly||n,issues:(c.get(E.id)??[]).sort((I,R)=>I.rank.localeCompare(R.rank)).map(I=>({id:I.id,ref:He(I.id),title:Ze(I.title),description:I.props.description??"",readonly:!!I.readonly||n,tags:tu(I),assignees:ru(I,s),parentNodeId:I.parentNodeId,isClosed:I.parentNodeId===ve})),parentNodeId:E.parentNodeId}))})),tags:Object.values(e.value.tags).map(g=>({...g,color:te(g.name)})),contributors:Object.values(e.value.contributors).map(g=>({...g,color:te(g.name)})),user:{name:l.value.userName??"",id:l.value.userId??"",color:te(l.value.userName??"")},commentsByIssueId:m,attachmentsByIssueId:f,attachmentMaxKb:Gi(),timeTravel:t})},dt=async(e={})=>{if(at().mode!=="live")return jn();let t=await Ne(e.repoRoot,{pull:!1});return d(t)?t:jn()},cu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(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 u("No changes made",{id:e.issueId,description:s});let i={id:q(),...n.value,action:"edit.description",payload:{id:e.issueId,md:e.description}},c=U([i],t.value.stateBranchRoot);return d(c)?a(c.message):u("Edited issue description",{id:e.issueId,description:e.description})},lu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=Ze(e.title);if(!s.trim())return a("Issue title cannot be empty");if(o.title===s)return u("No changes made",{id:e.issueId,title:s});let i={id:q(),...n.value,action:"edit.title",payload:{id:e.issueId,name:s}},c=U([i],t.value.stateBranchRoot);return d(c)?a(c.message):u("Edited issue title",{id:e.issueId,title:s})},uu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Tag target must be an issue");if(o.readonly)return a("Cannot tag readonly issue");let s=Ze(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??q(),l=[...i?[]:[{id:q(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:q(),...n.value,action:"add.issue.tag",payload:{id:e.issueId,tag:c}}],m=U(l,t.value.stateBranchRoot);return d(m)?a(m.message):u("Added issue tag",{id:e.issueId,tag:{id:c,name:s}})},mu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(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:q(),...n.value,action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},i=U([s],t.value.stateBranchRoot);return d(i)?a(i.message):u("Removed issue tag",{id:e.issueId,tagId:e.tagId})},pu=async(e,t)=>{let n=je(e);if(d(n))return;let r;for(let o of n.value)o.userId===t&&(r=o.userName??r);return r===void 0?void 0:{id:t,name:r}},fu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Assign target must be an issue");if(o.readonly)return a("Cannot assign readonly issue");let s=e.self?n.value.userId:e.assigneeId;if(s){let R=r.value.contributors[s],A=R?void 0:await pu(t.value.stateBranchRoot,s);if(!R&&!A)return a("Unknown assignee id");let P=R??A,_=[...R?[]:[{id:q(),...n.value,action:"create.contributor",payload:{id:P.id,name:P.name}}],{id:q(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:P.id}}],w=U(_,t.value.stateBranchRoot);return d(w)?a(w.message):u("Added issue assignee",{id:e.issueId,assignee:{id:P.id,name:P.name}})}let i=Ze(e.assigneeName??"").trim();if(!i)return a("Provide assigneeId, self or assigneeName");let l=[...nu(zi(),r.value.contributors).entries()].filter(([,R])=>R===i);if(l.length>1)return a(`"${i}" matches ${l.length} contributors (${l.map(([R])=>R).join(", ")}). Assign by assigneeId to choose.`);let m=l[0];if(!m&&!e.createUnlinked)return a(`No contributor named "${i}". Assign by id, or pass createUnlinked to add them as an external assignee.`);let[p=q(),f=i]=m??[],E=[...!!r.value.contributors[p]?[]:[{id:q(),...n.value,action:"create.contributor",payload:{id:p,name:f}}],{id:q(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:p}}],I=U(E,t.value.stateBranchRoot);return d(I)?a(I.message):u("Added issue assignee",{id:e.issueId,assignee:{id:p,name:f}})},gu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;if(!r.value.contributors[e.contributorId])return a("Contributor not found");if(await pu(t.value.stateBranchRoot,e.contributorId))return a("Cannot remove a contributor who has authored events \u2014 their name appears throughout the log");let i=[{id:q(),...n.value,action:"tombstone.contributor",payload:{id:e.contributorId}}],c=U(i,t.value.stateBranchRoot);return d(c)?a(c.message):u("Tombstoned contributor",{id:e.contributorId,name:ro})};var vu=async(e={})=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=je(t.value.stateBranchRoot);if(d(o))return a(o.message);let s=e.boardId?Vi(o.value,e.boardId):o.value,i=new Map,c=new Set,l=new Set;for(let g of o.value)g.userId&&l.add(g.userId);for(let g of s)g.userId&&(i.set(g.userId,g.userName??""),c.add(g.userId));let m=r.value.contributors,f=[...nu(i,m).entries()].map(([g,E])=>({id:g,name:E,color:te(E),isSelf:g===n.value.userId,isExternal:!c.has(g),isRemoved:m[g]?.tombstoned===!0,hasAuthoredAnywhere:l.has(g)}));return u("Listed board contributors",f)},yu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(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:q(),...n.value,action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},i=U([s],t.value.stateBranchRoot);return d(i)?a(i.message):u("Removed issue assignee",{id:e.issueId,assigneeId:e.assigneeId})},ss=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(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");if(s.length>4e3)return a(`Comment cannot exceed ${4e3} characters (got ${s.length})`);let i=q(),c={id:q(),...n.value,action:"add.issue.comment",payload:{id:i,issue:e.issueId,md:s,author:n.value.userId}},l=U([c],t.value.stateBranchRoot);return d(l)?a(l.message):u("Added issue comment",{id:i,issueId:e.issueId,body:s})},is=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();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(!T(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 u("Comment already deleted",{id:e.commentId,issueId:o.payload.issue});let c={id:q(),...n.value,action:"delete.issue.comment",payload:{id:e.commentId,issue:o.payload.issue}},l=U([c],t.value.stateBranchRoot);return d(l)?a(l.message):u("Deleted issue comment",{id:e.commentId,issueId:o.payload.issue})},hu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(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=ec(t.value.stateBranchRoot,s,Gi());if(d(i))return i;let c=Ze(e.name??"").trim()||"image",l=q(),m={id:q(),...n.value,action:"add.issue.attachment",payload:{id:l,issue:e.issueId,author:n.value.userId,hash:i.value.hash,ext:i.value.ext,name:c,bytes:i.value.bytes}},p=U([m],t.value.stateBranchRoot);return d(p)?a(p.message):u("Added issue attachment",{id:l,issueId:e.issueId,fileName:Dn(i.value.hash,i.value.ext),bytes:i.value.bytes})},xu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();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(!T(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 u("Attachment already deleted",{id:e.attachmentId,issueId:o.payload.issue});let c={id:q(),...n.value,action:"delete.issue.attachment",payload:{id:e.attachmentId,issue:o.payload.issue}},l=U([c],t.value.stateBranchRoot);return d(l)?a(l.message):u("Deleted issue attachment",{id:e.attachmentId,issueId:o.payload.issue})},bu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});return d(t)?t:tc(t.value.stateBranchRoot,e.fileName,Gi())};var uy=15e3,Iu=e=>{let t,n=!1,r=!1,o=0,s=()=>{let p=Jr();return d(p)?(le.error(p.message),null):p.value},i=()=>{let p=s();if(!p)return!1;let{autoSync:f,userName:g,preferredEditor:E}=p;return!!(f&&g&&E)},c=()=>{let p=s()?.autoSyncDebounceMs??uy;return Math.max(0,p-(Date.now()-o))},l=async()=>{if(!(n||r)){r=!0,o=Date.now();try{await nn(async()=>{if(at().mode!=="live")return;let p=await os({repoRoot:e.repoRoot});if(d(p))return;let{pulled:f,createdCommit:g,bootstrapped:E}=p.value;!f&&!g&&!E||_t({type:"state",payload:await dt({repoRoot:e.repoRoot})})})}finally{r=!1,m()}}};function m(){n||!i()||r||t||(t=setTimeout(()=>{t=void 0,l()},c()))}return m(),{queueSync:m,dispose:()=>{n=!0,t&&clearTimeout(t)}}};import{WebSocketServer as py}from"ws";var Eu=new Set(["sync","issues:create","issues:move","issue:close","issue:reopen","issue:edit:title","issue:edit:description","issue:tag:add","issue:tag:remove","contributor:remove","issue:assignee:add","issue:assignee:remove","issue:comment:add","issue:comment:delete"]);var my=e=>({...e,boards:(e.boards??[]).map(t=>({...t,swimlanes:(t.swimlanes??[]).map(n=>({...n,issues:(n.issues??[]).map(r=>({...r,description:""}))}))})),commentsByIssueId:Object.fromEntries(Object.entries(e.commentsByIssueId??{}).filter(([,t])=>t.length>0).map(([t,n])=>[t,n.map(r=>({...r,body:""}))])),attachmentsByIssueId:Object.fromEntries(Object.entries(e.attachmentsByIssueId??{}).filter(([,t])=>t.length>0))}),wr=e=>d(e)?e:u(e.message,my(e.value)),Su=(e,t)=>{let n=(e.boards??[]).flatMap(r=>r.swimlanes??[]).flatMap(r=>r.issues??[]).find(r=>r.id===t);return{issueId:t,description:n?.description??"",comments:e.commentsByIssueId?.[t]??[]}};var Cu=()=>{_t({type:"state",payload:wr(jn())})},ie=(e,t)=>{e.send(JSON.stringify(t))},as=async(e,t)=>ie(e,{type:"state",payload:wr(await dt({repoRoot:t}))}),fy=async(e,t)=>{let n=()=>ie(e,{type:"state",payload:wr(jn())});if(at().mode!=="live")return n();let r=await dt({repoRoot:t});return at().mode!=="live"?n():ie(e,{type:"state",payload:wr(r)})},ct=async(e,t,n,r,o)=>{if(ie(e,{type:r,payload:o}),d(o))return ie(e,{type:"failed",payload:o.message});n(),fy(e,t)},Nu=(e,t,{onStateChanged:n})=>{new py({server:e,path:"/ws"}).on("connection",o=>{Va(o),o.on("message",async s=>{let i=async c=>{let{type:l}=c;if(l==="timeline:get"){let{requestId:m,...p}=c.payload??{};return ie(o,{type:"timeline",requestId:m,payload:await ql({repoRoot:t,...p})})}if(l==="issue:get"){let m=c.payload?.issueId,p=jn();return ie(o,{type:"issue",payload:d(p)?p:u("Issue detail",Su(p.value,m))})}if(l==="commits:get"){let{requestId:m,...p}=c.payload??{};return ie(o,{type:"commits",requestId:m,payload:await Yl({repoRoot:t,...p})})}if(l==="commit:inspect")return ie(o,{type:"commit:inspect:result",payload:await Xl({repoRoot:t,sha:c.payload.sha})});if(l==="time-travel:scrub"){let m=await Ql({repoRoot:t,targetTime:c.payload.targetTime});return ie(o,{type:"time-travel:result",payload:m}),d(m)?void 0:Cu()}if(l==="time-travel:live"){let m=await Zl({repoRoot:t});return ie(o,{type:"time-travel:result",payload:m}),d(m)?void 0:Cu()}if(l==="state:get")return as(o,t);if(l==="sync"){let m=await os({repoRoot:t});return ie(o,{type:"sync:result",payload:m}),n(),as(o,t)}if(l==="issue:comment:add"){let m=await ss({repoRoot:t,...c.payload});return ct(o,t,n,"issue:comment:add:result",m)}if(l==="issue:comment:delete"){let m=await is({repoRoot:t,...c.payload});return ie(o,{type:"issue:comment:delete:result",payload:m}),d(m)?ie(o,{type:"failed",payload:m.message}):(n(),as(o,t))}if(l==="issue:edit:description"){let m=await cu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:edit:description:result",m)}if(l==="issue:edit:title"){let m=await lu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:edit:title:result",m)}if(l==="issue:tag:add"){let m=await uu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:tag:add:result",m)}if(l==="issue:tag:remove"){let m=await mu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:tag:remove:result",m)}if(l==="contributor:remove"){let m=await gu({repoRoot:t,...c.payload});return ct(o,t,n,"contributor:remove:result",m)}if(l==="contributors:get")return ie(o,{type:"contributors",payload:await vu({repoRoot:t,...c.payload})});if(l==="issue:assignee:add"){let m=await fu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:assignee:add:result",m)}if(l==="issue:assignee:remove"){let m=await yu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:assignee:remove:result",m)}if(l==="issues:list")return ie(o,{type:"issues",payload:await ou({repoRoot:t})});if(l==="issues:create"){let m=await su({...c.payload,repoRoot:t});return ie(o,{type:"issues:create:result",payload:m}),d(m)?_t({type:"failed",payload:m.message}):(_t({type:"issue:created",payload:m.value}),n(),as(o,t))}if(l==="issues:move"){if(!c.payload.position)return ie(o,{type:"error",message:"Missing move position"});let m=await du({...c.payload,repoRoot:t});return ct(o,t,n,"issues:move:result",m)}if(l==="issue:close"){if(!c.payload.issueId)return ie(o,{type:"error",message:"Missing issueId"});let m=await iu({repoRoot:t,issueId:c.payload.issueId});return ct(o,t,n,"issue:close:result",m)}if(l==="issue:reopen"){if(!c.payload.issueId)return ie(o,{type:"error",message:"Missing issueId"});let m=await au({repoRoot:t,issueId:c.payload.issueId});return ct(o,t,n,"issue:reopen:result",m)}return ie(o,{type:"error",message:"Unknown message type"})};try{let c=JSON.parse(s.toString());return Eu.has(c.type)?await nn(async()=>at().mode!=="live"?ie(o,{type:"failed",payload:"Read-only while viewing history"}):i(c)):await i(c)}catch(c){return ie(o,{type:"error",message:c instanceof Error?c.message:String(c)})}})})};var yy=Sn.dirname(vy(import.meta.url)),hy=process.env.IS_LOCAL==="true"?Sn.resolve(process.cwd(),"dist/gui"):Sn.join(yy,"gui"),ds,xy=async()=>(ds===void 0&&(ds=await import("node:sea").catch(()=>null)),ds?.isSea()?ds:null),fe=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},by=e=>fe(e,409,{isError:!0,message:"Read-only while viewing history"}),cs=(e,t)=>nn(async()=>at().mode!=="live"?by(e):t()),Ru=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)}),Iy=2*1024*1024,Ey={png:"image/png",jpg:"image/jpeg",gif:"image/gif",webp:"image/webp"},Sy=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",Au=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),r=Sn.resolve(hy),o=Sn.resolve(r,n),s=Sn.relative(r,o);if(s.startsWith("..")||Sn.isAbsolute(s))return fe(t,403,{isError:!0,message:"Forbidden"});let i=await xy();try{let c=i?Buffer.from(i.getAsset(`gui/${s}`)):await Tu(o);return t.writeHead(200,{"content-type":Sy(o)}),t.end(c)}catch{return fe(t,404,{isError:!0,message:`Not found: ${n}`})}},Cy=async(e,t=3710)=>new Promise((n,r)=>{let o=s=>{let i=l=>{if(e.off("listening",c),l.code==="EADDRINUSE"&&s===t){e.removeListener("error",i),o(0);return}r(l)},c=()=>{e.off("error",i);let l=e.address();if(!l||typeof l=="string"){r(new Error("Unable to resolve address"));return}n(l.port)};e.once("error",i),e.once("listening",c),e.listen(s,"127.0.0.1")};o(t)}),wu=async e=>{let t=gy.createServer(async(o,s)=>{let i=new URL(o.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return fe(s,200,await dt({repoRoot:e.repoRoot}));if(o.method==="POST"&&i.pathname==="/api/comments")try{let c=await Ru(o);if(!c.issueId||!c.body?.trim())return fe(s,400,{isError:!0,message:"Missing issueId or body"});let l=c.issueId,m=c.body;return await cs(s,async()=>{let p=await ss({repoRoot:e.repoRoot,issueId:l,body:m});return d(p)?fe(s,400,{isError:!0,message:p.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))})}catch(c){return fe(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 Ru(o,Iy);if(!c.issueId||!c.dataBase64)return fe(s,400,{isError:!0,message:"Missing issueId or dataBase64"});let l=c.issueId,m=c.dataBase64,p=c.name??"";return await cs(s,async()=>{let f=await hu({repoRoot:e.repoRoot,issueId:l,name:p,dataBase64:m});return d(f)?fe(s,400,{isError:!0,message:f.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))})}catch(c){return fe(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/",""));return c?cs(s,async()=>{let l=await xu({repoRoot:e.repoRoot,attachmentId:c});return d(l)?fe(s,400,{isError:!0,message:l.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))}):fe(s,400,{isError:!0,message:"Missing attachment id"})}if(o.method==="GET"&&i.pathname.startsWith("/media/")){let c=decodeURIComponent(i.pathname.replace("/media/","")),l=await bu({repoRoot:e.repoRoot,fileName:c});if(d(l))return fe(s,404,{isError:!0,message:l.message});try{let m=await Tu(l.value.filePath);return s.writeHead(200,{"content-type":Ey[l.value.ext]??"application/octet-stream","cache-control":"public, max-age=31536000, immutable"}),s.end(m)}catch{return fe(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/",""));return c?cs(s,async()=>{let l=await is({repoRoot:e.repoRoot,commentId:c});return d(l)?fe(s,400,{isError:!0,message:l.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))}):fe(s,400,{isError:!0,message:"Missing comment id"})}return i.pathname.startsWith("/board/")?Au("/",s):Au(i.pathname,s)});try{await Cy(t)}catch(o){return a(o instanceof Error?`Unable to start GUI server: ${o.message}`:`Unable to start GUI server: ${String(o)}`)}let n=Iu({repoRoot:e.repoRoot});Nu(t,e.repoRoot,{onStateChanged:()=>n.queueSync()}),t.on("close",n.dispose);let r=t.address();return!r||typeof r=="string"?(t.close(),a("Unable to resolve GUI server address")):u("Started GUI server",{url:`http://epiq.localhost:${r.port}${e.boardId?`/board/${e.boardId}`:""}`,server:t})};var Mu=async e=>{let t=Ot();Q(t)&&Me(t.value);let n=await wu({...e,boardId:""});if(d(n))return n;let{url:r}=n.value;return console.log(`Epiq GUI running at ${Ny.cyan(r)}`),Oa(r),u("Started GUI",{url:r})};import{Box as dn}from"ink";import ce from"react";import{Box as qi,Text as Mr}from"ink";import lt,{useEffect as Ry,useMemo as Ay}from"react";import{ulid as Ty}from"ulid";var Pu=({text:e,match:t,color:n,highlightColor:r=h.secondary,dimColor:o=!1})=>{if(!t)return lt.createElement(Mr,{color:n,dimColor:o},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?lt.createElement(Mr,{color:n,dimColor:o},e):lt.createElement(Mr,{color:n,dimColor:o},e.slice(0,c),lt.createElement(Mr,{backgroundColor:r,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},Lu=Ty(),wy=e=>`${e}`,My=e=>{let{pendingNavTarget:t}=Zt();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,s=new Set(de(b.NONE,{breadCrumb:n,contextNode:r,readOnly:v().readOnly,selectedNode:o}));return[...new Set(Object.values(b))].filter(i=>i!=="move").filter(i=>i.length>0).filter(i=>i!==b.PALETTE).map(i=>{let c=Lo(i),l=Xo.find(m=>m.intent===c);return{command:i,description:l?.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))},Py=e=>ee.text({id:Lu,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),Ly=(e,t,n)=>ee.text({id:wy(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),Yi=[],ky=e=>{ku();let t=S.createNode(Py(v().rootNodeId));d(t)||!$t(t.value)||(Yi=[t.value,...e.map((n,r)=>Ly(n,r,Lu)).map(S.createNode).filter(Q).map(({value:n})=>n).filter($t)],M.navigate({contextNode:t.value,selectedIndex:0}))},ku=()=>{let e=Yi.map(t=>t.id);Yi=[];for(let t of e)S.deleteNode(t)};function Du({width:e,height:t}){let r=Ic().value.trim().toLowerCase(),o=Ay(()=>My(r),[r]);Ry(()=>(ky(o),()=>{ku()}),[o]);let s=v().selectedIndex;return lt.createElement(qi,{flexDirection:"column",width:e,height:t-2},lt.createElement(tt,{height:t-4,itemHeight:3,selectedIndex:s},o.map((i,c)=>{let l=c===s,m=i.isAvailable?h.accent:h.secondary2,p=i.isAvailable?"":"[unavailable] ";return lt.createElement(qi,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:h.secondary,borderStyle:"single"},lt.createElement(Mr,{color:m,dimColor:!i.isAvailable},l?"\u276F ":" ",lt.createElement(Pu,{text:Xa(i.command),match:r,color:m,dimColor:!i.isAvailable})),lt.createElement(qi,{paddingLeft:2},lt.createElement(Pu,{text:p+i.description,match:r.length>=2?r:"",color:l&&i.isAvailable?h.primary:h.secondary2,dimColor:!i.isAvailable})))})))}import{Box as Xy}from"ink";import ms from"react";import Lr from"chalk";import{Box as Xi,Text as Bu}from"ink";import Pr,{useEffect as Dy,useMemo as By,useState as Fy}from"react";var Fu=Lr.hex(h.secondary),Uy=Lr.inverse,Oy=Lr.inverse.hex(h.secondary2),_y={hint:"",hints:[],overlap:0,remainder:""},Ou=({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}},$y=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=te(t);return{bg:r=>Lr.bgHex(n).black(r),bgCursor:r=>Lr.bgHex(n).inverse.black(r)}}return Js(t)},Hy=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=Ou({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}},Uu=()=>({value:Le.value,cursorPosition:Le.cursorPosition,commandIsPending:Le.commandIsPending,autoCompletion:Le.commandMeta.autoCompletion??_y,infoMessage:Le.commandMeta.infoMessage,validationStatus:Le.commandMeta.validity,command:Le.commandMeta.command,inputString:Le.commandMeta.inputString,modifier:Le.commandMeta.modifier}),jy=(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,_u=({width:e,mode:t})=>{let[n,r]=Fy(Uu());Dy(()=>{let I=()=>{let A=Uu();r(P=>jy(P,A)?P:A)},R=fi(I);return I(),()=>{R()}},[]);let{value:o,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:l,command:m,modifier:p,validationStatus:f}=n,g=c&&f===bt.Invalid,E=By(()=>{let I=Math.max(0,Math.min(s,o.length)),R=Ou({value:o,command:m}),A=Hy({value:o,command:m,modifier:p}),P=m?Js(m):null,_=$y({command:m,modifier:p}),w=(ge,me)=>{let Kn=R&&me>=R.start&&me<R.end,zn=A&&me>=A.start&&me<A.end;return Kn&&P?P.fg(ge):zn&&_?_.bg(ge):ge},W=(ge,me)=>{let Kn=R&&me>=R.start&&me<R.end,zn=A&&me>=A.start&&me<A.end;return Kn&&P?P.fgCursor(ge):zn&&_?_.bgCursor(ge):Uy(ge)},H=o.slice(0,I),D=o[I]??" ",$=I<o.length?o.slice(I+1):"",Ye=Array.from(H).map((ge,me)=>w(ge,me)).join(""),we=W(D,I),Xe=Array.from($).map((ge,me)=>w(ge,I+1+me)).join("");if(l.hint){let ge=l.hint[l.overlap]??D;we=Oy(ge),Xe=Fu(l.remainder.slice(1)+$)}return Fu(t===y.PALETTE?"?":":")+Ye+we+Xe},[o,s,l,m,p]);return Pr.createElement(Xi,{flexDirection:"column",justifyContent:"flex-start"},Pr.createElement(Xi,{flexDirection:"column",paddingX:1,borderColor:h.secondary,borderStyle:"round",width:e},Pr.createElement(Xi,null,Pr.createElement(Bu,null,E),i&&Pr.createElement(Bu,{wrap:"truncate",color:g?h.red:h.secondary2},` ${i} `))))};import{Box as Wy,Text as Vy}from"ink";import $u from"react";var Gy=(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},Hu=({width:e,availableHints:t})=>{let n=Gy(t,e).join(" | ");return $u.createElement(Wy,{width:e,borderStyle:"round",borderColor:h.secondary,paddingX:1},$u.createElement(Vy,{color:h.secondary2},n.length?n:"\xA0"))};import{Box as Ky,Text as ls}from"ink";import kr,{useEffect as zy,useRef as Wn,useState as qy}from"react";var Yy=40,us=.3,Ji="\u2500",ju=1,Wu=16,Vu=({width:e})=>{let{replay:t}=j(),n=t!==null,r=t?Math.min(1,Math.max(0,t.progress)):0,s=Math.max(4,e-6),i=s*ju,[c,l]=qy(0),m=Wn(r);m.current=r;let p=Wn(0),f=Wn(0),g=Wn(0),E=Wn(0),I=Wn(0);if(zy(()=>{if(!n){p.current=0,g.current=0,E.current=0,I.current=0,l(0);return}p.current=m.current,f.current=Date.now(),g.current=m.current;let w=setInterval(()=>{let W=Date.now(),H=m.current;if(H!==g.current){let Xe=H-g.current,ge=W-f.current;if(Xe<0)E.current=0,I.current=0;else if(Xe>0&&ge>0){let me=Xe/ge;E.current=E.current===0?me:E.current*(1-us)+me*us,I.current=I.current===0?Xe:I.current*(1-us)+Xe*us}p.current=H,f.current=W,g.current=H}let D=W-f.current,$=Math.min(I.current,E.current*D),Ye=Math.min(1,p.current+$),we=Math.round(Ye*i);l(Xe=>Xe===we?Xe:we)},Yy);return()=>clearInterval(w)},[n,i]),!t)return null;let R=w=>{let W=s>1?w/(s-1):0,H=Math.round(W*(Wu-1))/(Wu-1);return oo(H)},A=Math.min(s,Math.floor(c/ju)),P=[];for(let w=0;w<A;w++){let W=R(w),H=P[P.length-1];H&&H.color===W?H.text+=Ji:P.push({text:Ji,color:W})}let _=Ji.repeat(Math.max(0,s-A));return kr.createElement(Ky,{width:e,borderStyle:"round",borderColor:h.secondary,paddingX:1,columnGap:1},kr.createElement(ls,{color:h.secondary2},"\u25B6"),kr.createElement(ls,null,P.map((w,W)=>kr.createElement(ls,{key:W,color:w.color},w.text)),kr.createElement(ls,{color:h.secondary,dimColor:!0},_)))};var Dr=({width:e,mode:t,availableHints:n})=>{let{timeMode:r}=j(),o=t===y.COMMAND_LINE||t===y.PALETTE;return ms.createElement(Xy,null,o?ms.createElement(_u,{width:e,mode:t}):r==="replay"?ms.createElement(Vu,{width:e}):ms.createElement(Hu,{width:e,mode:t,availableHints:n}))};import{Box as rn,Text as Vn}from"ink";import _e,{useEffect as Jy,useMemo as Qy}from"react";import{ulid as Gu}from"ulid";var fs=Gu(),Zy=()=>[...new Set([...v().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})),eh=e=>ee.text({id:fs,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),th=(e,t,n)=>ee.text({id:Gu(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),ps=[],Ku=()=>{let e=ps.filter(n=>n.id!==fs).map(n=>n.id),t=ps.filter(n=>n.id===fs).map(n=>n.id);ps=[];for(let n of[...e,...t])S.deleteNode(n)},nh=e=>{Ku();let t=S.createNode(eh(v().rootNodeId));if(d(t)||!$t(t.value))return logger.error("Could not attach help nodes");ps=[t.value,...e.map((n,r)=>th(n,r,fs)).map(S.createNode).filter(Q).map(({value:n})=>n).filter($t)],M.navigate({contextNode:t.value,selectedIndex:0})},zu=({width:e,height:t})=>{let n=Qy(()=>Zy(),[]);Jy(()=>(nh(n),()=>{Ku()}),[n]);let r=v().selectedIndex;return _e.createElement(rn,{flexDirection:"column",marginTop:3,borderColor:h.secondary,borderStyle:"round",width:e,height:t-2},_e.createElement(rn,{paddingX:1,justifyContent:"center"},_e.createElement(Vn,{color:h.accent},"Help"),_e.createElement(Vn,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),_e.createElement(rn,{paddingX:1,marginTop:1},_e.createElement(rn,{width:20,justifyContent:"flex-end"},_e.createElement(Vn,{color:h.secondary},"Key(s)")),_e.createElement(rn,{flexGrow:1,width:40,paddingLeft:2},_e.createElement(Vn,{color:h.secondary},"Action"))),_e.createElement(tt,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:s},i)=>{let c=i===r;return _e.createElement(rn,{paddingX:1,key:`${o}-${s}-${i}`,flexDirection:"row"},_e.createElement(rn,{width:20,justifyContent:"flex-end"},_e.createElement(Vn,{color:h.accent},o)),_e.createElement(rn,{flexGrow:1,width:40,paddingLeft:2},_e.createElement(Vn,{color:c?h.primary:h.secondary2},s)))})))};import rh from"chalk";import{Box as gs,Text as Ft}from"ink";import qe from"react";var qu=({width:e,height:t})=>qe.createElement(gs,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:h.secondary,rowGap:1},qe.createElement(Ft,{color:h.accent,bold:!0},"Initialize project"),qe.createElement(Ft,null,`This folder is not an ${rh.hex(h.accent)("epiq")} project yet.`),qe.createElement(Ft,{color:h.primary},"To start tracking issues here, we need to initialize a new",qe.createElement(Ft,{color:h.primary,backgroundColor:h.secondary}," .epiq/project.json "),"file in this repository."),qe.createElement(gs,{marginTop:1,flexDirection:"column"},qe.createElement(gs,null,qe.createElement(Ft,{color:h.accent}," "),qe.createElement(Ft,{color:h.primary},"Type "),qe.createElement(Ft,{backgroundColor:h.secondary}," :init "))),qe.createElement(gs,{marginTop:1},qe.createElement(Ft,{color:h.secondary2},"This will create, commit and push "),qe.createElement(Ft,{color:h.primary,backgroundColor:h.secondary}," .epiq/project.json ")));import{Box as vs,Text as Ct}from"ink";import Te from"react";var oh=({isDone:e,command:t,value:n})=>Te.createElement(vs,null,Te.createElement(Ct,{color:h.accent,dimColor:e},e?" \u2714 ":" "),Te.createElement(Ct,{dimColor:e},"Type "),Te.createElement(Ct,{backgroundColor:h.secondary,dimColor:e}," "+t+" "),n!==void 0&&Te.createElement(Te.Fragment,null,Te.createElement(Ct,{dimColor:e}," "),Te.createElement(Ct,{color:h.secondary,dimColor:e},"<"+n+">"))),sh=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function Qi({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:s,autoSync:i,isSetAutoSync:c}=Kt(),l=[{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=l.findIndex(f=>!f.done),p=m===-1?void 0:l[m];return Te.createElement(vs,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:h.secondary,rowGap:1},Te.createElement(Ct,{color:h.accent,bold:!0},"Welcome! \u{1F539}"),Te.createElement(Ct,null,"Let's get you started - it's a breeze."),Te.createElement(Ct,{color:h.secondary2},"Remember - you can always search available commands by typing:",Te.createElement(Ct,{color:h.accent}," ? ")),p&&Te.createElement(Ct,{color:h.secondary2},p.message),Te.createElement(vs,{flexDirection:"column"},l.map((f,g)=>m===-1||g<=m?Te.createElement(vs,{key:f.key,marginBottom:1},Te.createElement(oh,{isDone:f.done,command:f.command,value:f.done?sh(f.value):void 0})):null)))}import Is from"chalk";import{Box as Fr,Text as Gn}from"ink";import xe from"react";import{Box as ys,Text as Yu}from"ink";import on from"react";import ih from"chalk";var ah=e=>(S.getTag(e)?.name??"").length+3,dh=e=>{let t=S.getContributor(e);return(t?Xt(e,t.name):"").length+3},Xu=({width:e})=>{let{viewMode:t}=K(),n=j(),{breadCrumb:r,contextNode:o,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[o.id]?.[s],l=At(c?.id??o.id,"TICKET"),m=Q(l)?l.value:void 0,p=m?.props.tags??[],f=m?.props.assignees??[],g=m?.parentNodeId?!qs(o.id,m.parentNodeId)&&t==="dense":!1,E=r.map((H,D)=>{let $=D===r.length-1,Ye=Y(H.id),we=$?Ye?.[s]?.title:void 0;return`${D?" / ":""}${H.title??""}${we?` \u25B8 ${we}`:""}`}).join(""),I=m?S.getCommentsByIssue(m.id):[],R=I.length?String(I.length).length+11:0,A=g?p.reduce((H,D)=>H+ah(D),0)+f.reduce((H,D)=>H+dh(D),0)+R:0,P=c?.id!=null&&!(t==="wide"&&T(c)),_=Math.max(0,e-A),w=E.substring(0,_)+(P?ih.hex(h.secondary2).dim(` ${He(c.id)}`):""),W=g?[...p.map(H=>on.createElement(ys,{key:`tag-${H}`,paddingLeft:1},on.createElement(Un,{id:H}))),...f.map(H=>on.createElement(ys,{key:`assignee-${H}`,paddingLeft:1},on.createElement(Jt,{id:H}))),I.length?on.createElement(ys,{key:"comments",paddingLeft:1},on.createElement(Yu,{color:h.accent},"[",I.length," comment",I.length===1?"":"s","]")):null]:[];return on.createElement(ys,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},on.createElement(Yu,{color:h.secondary2},w),W)};import{Box as ch,Text as Ju}from"ink";import hs from"react";var lh=({filters:e})=>hs.createElement(ch,{columnGap:1},hs.createElement(Ju,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>hs.createElement(Ju,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),Qu=hs.memo(lh);import{Box as uh,Text as xs}from"ink";import Br from"react";function Zu(){let{eventLog:e,unappliedEvents:t}=j(),n=e.at(-1)?.id,r=Ao(n??""),o=Q(r)?co(r.value):"INVALID DATE";return Br.createElement(uh,{paddingLeft:1},Br.createElement(xs,{backgroundColor:h.accent,color:h.secondary}," Readonly "),Br.createElement(xs,{color:h.accent}," "+t.length+" edits ago at "+o+"."),Br.createElement(xs,{color:h.accent}," Resume with "),Br.createElement(xs,{backgroundColor:h.accent,color:h.secondary}," ",":peek now"," "))}import{Box as mh,Text as Zi}from"ink";import bs from"react";function em(){let{replay:e}=j();if(!e)return null;let{appliedCount:t,totalCount:n,currentTime:r}=e;return bs.createElement(mh,{paddingRight:2,columnGap:1,justifyContent:"flex-end"},bs.createElement(Zi,{backgroundColor:h.accent,color:h.secondary}," \u25B6 REPLAY "),bs.createElement(Zi,{color:h.secondary2},co(new Date(r))),bs.createElement(Zi,{color:h.accent},`${t}/${n} edits`))}import ea from"chalk";import{Box as ph,Text as tm}from"ink";import ta,{useEffect as fh,useState as gh}from"react";var vh=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],yh=150,nm=12,hh=.36,rm=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)}},xh=({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)}`},bh=(e,t,n)=>{let r=rm(e),o=rm(t);return xh({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},Ih=(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 bh(s,i,o)};function om({syncStatus:e,autoSync:t}){let[n,r]=gh(0);fh(()=>{if(e.status!=="syncing"){r(0);return}let c=0,l=setInterval(()=>{c+=1;let m=(Math.sin(c*hh)+1)/2,p=Math.round(m*(nm-1));r(f=>f===p?f:p)},yh);return()=>clearInterval(l)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:h.secondary2,failed:h.yellow,pending:h.secondary2,syncing:Ih(vh,n/(nm-1))??""}[e.status];return ta.createElement(ph,null,ta.createElement(tm,null,ea.hex(h.secondary2).dim(t?"Sync (auto): ":"Sync: ")),ta.createElement(tm,null,ea.hex(i)("\u25CF")+ea.hex(h.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}import cm from"chalk";import{Text as lm}from"ink";import um,{useEffect as Nh,useState as Rh}from"react";var sn="1.4.3";import na from"chalk";var Eh="https://registry.npmjs.org/epiq/latest",ra=null,sm=0,Sh=1e3*60*60*24,im=e=>e.replace(/^v/,""),Ch=(e,t)=>{let n=im(e).split(".").map(Number),r=im(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},am=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(ra&&Date.now()-sm<Sh)return ra;try{let t=await fetch(Eh);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?Ch(r,e)>0:!1};return ra=o,sm=Date.now(),o}catch{return{current:e,latest:null,updateAvailable:!1}}},dm=(e,t)=>{let n=e.split("."),r=t.split("."),o=r.findIndex((s,i)=>s!=n[i]);return r.map((s,i)=>i>=o?na.hex(h.accent).dim(s):na.hex(h.secondary).dim(s)).join(na.hex(h.secondary2).dim("."))};function mm(){let[e,t]=Rh({current:sn,latest:null,updateAvailable:!1});return Nh(()=>{let n=!0;return am(sn).then(r=>{n&&t(r)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?um.createElement(lm,{dimColor:!0,color:h.secondary2},sn+" "):um.createElement(lm,null,cm.hex(h.secondary2).dim(sn),cm.hex(h.accent).dim(" \u2197 "),dm(sn,e.latest))}function Ur({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o,replay:s}=j(),{userName:i,preferredEditor:c,autoSync:l}=K(),m=64,p=process.stdout.columns-m-8,f=t||n==="replay",g=s?mn(s.currentLabel,Math.max(0,p)):"";return xe.createElement(Fr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},n==="replay"?xe.createElement(Fr,{paddingLeft:1},xe.createElement(Gn,{color:h.secondary2},g)):f?xe.createElement(Gn,null," "):o===y.PALETTE?xe.createElement(Fr,null,xe.createElement(Gn,{color:h.accent},"Command Palette"),xe.createElement(Gn,{dimColor:!0,color:h.secondary2}," ","- search, select and press enter")):xe.createElement(Fr,{paddingLeft:1},e.length>0?xe.createElement(Qu,{filters:e}):xe.createElement(Xu,{width:p})),n==="live"?xe.createElement(Fr,{columnGap:1,paddingRight:2,"max-width":m,overflow:"hidden",justifyContent:"flex-end"},xe.createElement(om,{autoSync:!!l,syncStatus:r}),xe.createElement(Gn,null,Is.hex(h.secondary2).dim("Mode: ")+Is.hex(h.secondary2).dim(o.padEnd(8," "))," "),xe.createElement(pm,{icon:"@",value:i}),xe.createElement(pm,{icon:"\u276F",value:c}),xe.createElement(mm,null)):"",n==="peek"?xe.createElement(Zu,null):"",n==="replay"?xe.createElement(em,null):"")}function pm({icon:e,value:t}){return xe.createElement(Gn,null,Is.dim(e)+Is.hex(h.accent)(` ${t??"-"} `))}import{Box as Ah,Text as Th}from"ink";import Or from"react";import{Box as Es,Text as oa}from"ink";import an from"react";function sa(){let e=j(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?z(t?.id):[];return an.createElement(Es,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:h.secondary,width:s},an.createElement(Es,{padding:1,paddingTop:0,paddingBottom:0},an.createElement(oa,null,"Select a board:")),an.createElement(Es,{padding:1,flexDirection:"column"},i.map((c,l)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===l,f=z(c.id).flatMap(({id:g})=>Y(g)).length;return an.createElement(Es,{key:c.id??l},an.createElement(oa,{color:m?h.accent:h.secondary2},an.createElement(ke,{isSelected:m})),an.createElement(oa,{color:m?h.accent:h.secondary2},c.title," (",f," issues)",c.readonly?" \u{1F512}":""))})))}var wh=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:s,width:i})=>{let{renderedChildrenIndex:c}=j(),l=n.find(({context:g})=>g==="BOARD"),f=s-1-3;return Or.createElement(Ah,{flexDirection:"row"},e.context==="WORKSPACE"?Or.createElement(sa,null):l?Or.createElement($o,{height:f,width:i,swimlanes:(c[l.id]??[]).filter(g=>g!==void 0&&Ht(g)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):Or.createElement(Th,null))},fm=Or.memo(wh);import{useEffect as Mh}from"react";var Ph=e=>{Mh(()=>{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:l}=v();l==="default"&&!c&&Io(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},gm=({autoSync:e})=>(Ph(e),null);function ia({width:e,height:t}){let n=j(),{autoSync:r,viewMode:o}=Ua(),s=n.filters;if(n.mode===y.HELP)return ce.createElement(dn,{flexDirection:"column"},ce.createElement(zu,{width:e,height:t}));if(n.mode===y.PALETTE)return ce.createElement(dn,{flexDirection:"column"},ce.createElement(Ur,{filters:s}),ce.createElement(Du,{width:e,height:t-2}),ce.createElement(Dr,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=Kt(),c=!i,l=i&&!n.hasProjectDefinition;if(c)return ce.createElement(dn,{flexDirection:"column"},ce.createElement(dn,{flexDirection:"column"},ce.createElement(Ur,{hideBreadCrumb:!0,filters:s}),ce.createElement(Qi,{height:t,width:e})),ce.createElement(Dr,{width:e,mode:n.mode,availableHints:n.availableHints}));if(l)return ce.createElement(dn,{flexDirection:"column"},ce.createElement(dn,{flexDirection:"column"},ce.createElement(Ur,{hideBreadCrumb:!0,filters:s}),ce.createElement(qu,{height:t,width:e})),ce.createElement(Dr,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Oe(n.breadCrumb??[],"BOARD");if(Q(m)){let p=m.value.id,f=z(p).length,g=3,E=Math.floor(e/g),I=Math.floor(e/Math.max(f,1));e=Math.min(I,E)*Math.max(f,g)}return ce.createElement(dn,{flexDirection:"column"},ce.createElement(gm,{autoSync:r}),ce.createElement(dn,{flexDirection:"column"},ce.createElement(Ur,{filters:s}),ce.createElement(fm,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),ce.createElement(Dr,{width:e,mode:n.mode,availableHints:n.availableHints}))}import Lh from"readline";var Ss,Cs,Nt,kh=new Set([x.MoveCursorLeft,x.EraseInputWord,x.MoveCursorLeftOfWord,x.MoveCursorRight,x.MoveCursorRightOfWord,x.NavToPreviousContainer,x.NavToNextContainer,x.NavPreviousItem,x.NavNextItem,x.SetViewDense,x.SetViewWide,x.Confirm,x.Exit,x.Yank,x.InitCommandLine,x.InitCommandPalette,x.ExitCommandLine,x.CaptureInput,x.EraseInput,x.EraseInputWord,x.HideHelp,x.ViewHelp,x.SetViewDense,x.SetViewWide,x.GetLastCommandFromHistory,x.GetNextCommandFromHistory,x.AutoCompleteCommand]),Dh=new Set([x.NavPreviousItem,x.NavNextItem,x.NavToPreviousContainer,x.NavToNextContainer,x.Confirm,x.Exit,x.InitCommandPalette,x.InitMove,x.MoveNextItem,x.MovePreviousItem,x.MoveToNextContainer,x.MoveToPreviousContainer,x.Delete,x.AddItem,x.EditTitle,x.EditDescription,x.ConfirmMove,x.Edit,x.ViewHelp,x.Yank]),vm=async e=>{if(e.ctrl&&e.name==="c")return M.exit();let{actionIndex:t,mode:n,readOnly:r,timeMode:o}=v(),s=Sc(e,n);if(!s||r&&!kh.has(s)||o==="replay"&&n===y.DEFAULT&&Dh.has(s))return;let i=t[n]?.[s];if(i?.action)try{await i.action(i,e)}catch(c){logger.error(c)}},Bh=()=>async function(t,n){n.name!=="escape"&&(Nt&&(clearTimeout(Nt),Nt=void 0),await vm(n))},Fh=()=>async function(t){if(t.length===1&&t[0]===27){Nt&&clearTimeout(Nt),Nt=setTimeout(()=>{vm({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),Nt=void 0},25);return}Nt&&(clearTimeout(Nt),Nt=void 0)};function ym(){Ss&&process.stdin.removeListener("keypress",Ss),Cs&&process.stdin.removeListener("data",Cs),Ss=Bh(),Cs=Fh(),Lh.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",Cs),process.stdin.on("keypress",Ss)}async function hm(){try{let e=Ot();Q(e)&&Me(e.value);let t=$e(process.cwd()),n=[];if(Q(t)){let s=Re({repoRoot:t.value});if(d(s))return vn(3,s.message);let i=Cn(),c=await un({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return vn(3,c.message);let l=await F({cwd:s.value,args:["pull","--ff-only"]});d(l)&&logger.info(3,l.message);let m=je(s.value);if(d(m))return vn(3,m.message);n=m.value}let r=gn(n);if(d(r))return vn(4,r.message);C({hasProjectDefinition:Q(t),hasInitializingEvents:!!n.length});let o=aa();return d(o)?vn(6,o.message):(ym(),u("Booted Epiq",void 0))}catch(e){return vn(0,ho(e))}}Yc();var $h=`${cn.bold("Epiq CLI")}
60
+ `).map(f=>f.trim()).filter(Boolean);if(o.length===0)return a("No changed files found for this commit");if(o.length>ay)return a(`Commit touches ${o.length} files \u2014 too many for a side-by-side view`);let s=Hn.join(zl.tmpdir(),"epiq","commit-diffs",t),i=await Promise.all(o.map(async(f,g)=>{let[E,I]=await Promise.all([Kl(e,`${t}~1`,f),Kl(e,t,f)]),R=Hn.basename(f),A=Hn.join(s,String(g),"before",R),P=Hn.join(s,String(g),"after",R);return $i(A)||(be.writeToFile(A,E),await Hi(A,292)),$i(P)||(be.writeToFile(P,I),await Hi(P,292)),{beforePath:A,afterPath:P}})),[c,...l]=i;if(!c)return a("No changed files found for this commit");let m=await Ai(n,c.beforePath,c.afterPath,"new");if(d(m)||l.length===0)return m;await new Promise(f=>setTimeout(f,dy));let p=await Promise.all(l.map(({beforePath:f,afterPath:g})=>Ai(n,f,g,"reuse")));for(let f of p)d(f)&&logger.error(`Failed to open an additional diff tab for ${t}: ${f.message}`);return m},Xl=async e=>{if(!sy(e.sha))return a("Invalid commit sha");let t=ji(e.repoRoot);if(d(t))return a(t.message);let n=t.value,r=Wo()[0];if(r&&Ri(r)){let o=await cy(n,e.sha,r);if(!d(o))return o;logger.error(`Side-by-side diff failed for ${e.sha}, falling back to unified diff: ${o.message}`)}return iy(n,e.sha)},Jl=e=>{let t=je(e);if(d(t))return a(t.message);let n=it();if(d(n))return a(n.message);rs=null;let o=st(t.value).filter(d);return o.length>0?a(o.map(s=>s.message).join(", ")):(C({readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),u("Restored live state",!0))},ly=(e,t)=>{rs=null;let n=Jl(e);return d(n)?a(`${t} (recovery to live also failed: ${n.message})`):a(t)},Ql=e=>nn(async()=>{let t=Wi(e.repoRoot);if(d(t))return a(t.message);let n=fo(t.value,e.targetTime);if(d(n))return a(n.message);let{appliedEvents:r,unappliedEvents:o}=n.value,s=it();if(d(s))return s;let c=st(r).filter(d);return c.length>0?ly(t.value,c.map(l=>l.message).join(", ")):(C({readOnly:!0,timeMode:"peek",unappliedEvents:o,replay:null}),rs=e.targetTime,u("Checked out historical state",{asOfTime:e.targetTime}))}),Zl=(e={})=>nn(async()=>{let t=Wi(e.repoRoot);if(d(t))return a(t.message);let n=Jl(t.value);return d(n)?a(n.message):u("Returned to live state",!0)});var Gi=()=>{let e=Ot();return d(e)?xt:e.value.attachmentMaxKb??xt},Ki=e=>{let t=$e(e??process.cwd());return d(t)?a(t.message):u("Resolved Epiq repo root",t.value)},Ne=async(e,t)=>{let n=Ki(e);if(d(n))return n;let r=Re({repoRoot:n.value});if(d(r))return a(r.message);let o=Cn(),s=await un({repoRoot:n.value,stateBranchRoot:r.value,stateBranchName:o.stateBranch});if(d(s))return a(s.message);if(t?.pull??!1){let l=await F({cwd:r.value,args:["pull","--ff-only"]});d(l)&&le.info(3,l.message)}let i=je(r.value);if(d(i))return a(i.message);let c=gn(i.value);return d(c)?a(c.message):u("Booted Epiq state",{repoRoot:n.value,stateBranchRoot:r.value})},Ae=()=>{let e=Ot();return d(e)?a(e.message):e.value.userId?e.value.userName?u("Resolved actor",{userId:e.value.userId,userName:e.value.userName}):a("Unable to retrieve user name"):a("Unable to retrieve user id")},Fe=()=>{let e=We();return d(e)?a(e.message):e},tu=e=>(e.props.tags??[]).map(t=>S.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:te(t.name)})),zi=()=>{let e=We(),t=d(e)?[]:e.value.eventLog??[],n=new Map;for(let r of t)r.userId&&r.userName&&n.set(r.userId,r.userName);return n},nu=(e,t)=>{let n=new Map(e);for(let r of Object.values(t)){if(r.tombstoned){n.set(r.id,r.name);continue}n.set(r.id,Fn(r.name,n.get(r.id))??r.name)}return n},ru=(e,t=new Map)=>(e.props.assignees??[]).map(n=>S.getContributor(n)).filter(n=>n!=null).map(n=>{let r=n.tombstoned?n.name:Fn(n.name,t.get(n.id))??n.name;return{id:n.id,name:r,color:te(r)}});var ou=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Fe();if(d(n))return n;let r=n.value.nodes,o=zi(),s=Object.values(r).filter(T).filter(i=>!i.isDeleted).filter(i=>e.includeClosed||i.parentNodeId!==ve).filter(i=>e.boardId?(i.parentNodeId?r[i.parentNodeId]:void 0)?.parentNodeId===e.boardId:!0).map(i=>({id:i.id,ref:He(i.id),title:Ze(i.title),description:i.props.description??"",parentNodeId:i.parentNodeId,isClosed:i.parentNodeId===ve,readonly:!!i.readonly,tags:tu(i),assignees:ru(i,o)}));return u("Listed issues",s)},su=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=Ln(e.parentId,n.value,t.value.stateBranchRoot);if(d(o))return o;let s=Go({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:q(),...n.value,action:"edit.description",payload:{id:c,md:e.description}});let l=[];for(let f of e.tagNames??[]){let g=Ze(f).trim();if(!g||l.some(R=>R.name===g))continue;let E=Object.values(r.value.tags).find(R=>R.name===g),I=E?.id??q();E||i.push({id:q(),...n.value,action:"create.tag",payload:{id:I,name:g}}),i.push({id:q(),...n.value,action:"add.issue.tag",payload:{id:c,tag:I}}),l.push({id:I,name:g})}let m=[];for(let f of e.assigneeNames??[]){let g=Ze(f).trim();if(!g||m.some(R=>R.name===g))continue;let E=Object.values(r.value.contributors).find(R=>R.name===g),I=E?.id??q();E||i.push({id:q(),...n.value,action:"create.contributor",payload:{id:I,name:g}}),i.push({id:q(),...n.value,action:"add.issue.assignee",payload:{id:c,assignee:I}}),m.push({id:I,name:g})}let p=U(i,t.value.stateBranchRoot);return d(p)?a(p.message):u("Created issue",{id:c,title:e.title,parentId:e.parentId,description:e.description??"",tags:l,assignees:m})},iu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=fn(ve,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(r))return r;let o={id:q(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:ve,rank:r.value}},s=U([o],t.value.stateBranchRoot);return d(s)?a(s.message):u("Closed issue",{id:e.issueId})},au=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Target node is not issue");if(o.parentNodeId!==ve)return a("Issue is not closed");let s=Ho(o);if(!s)return a("Unable to resolve previous parent from issue history");if(s===ve)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=fn(i.id,o.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let l={id:q(),...n.value,action:"reopen.issue",payload:{id:o.id,parent:i.id,rank:c.value}},m=U([l],t.value.stateBranchRoot);return d(m)?a(m.message):u("Reopened issue",{id:o.id,parentId:i.id})},du=async e=>{let t=Ki(e.repoRoot);if(d(t))return t;let n=Ae();if(d(n))return n;let r=Re({repoRoot:t.value});if(d(r))return r;let o=je(r.value);if(d(o))return o;let s=gn(o.value);if(d(s))return s;let i=fn(e.parentId,e.issueId,e.position??{at:"end"},n.value,r.value);if(d(i))return i;let c={id:q(),...n.value,action:"move.node",payload:{id:e.issueId,parent:e.parentId,rank:i.value}},l=U([c],r.value);return d(l)?a(l.message):u("Moved issue",{id:e.issueId,parentId:e.parentId})};var os=async(e={})=>{ts();let t=Ki(e.repoRoot);if(d(t))return a("Sync failed");let n=Ae();if(d(n))return n;let r=await bo({cwd:t.value,ownEventFileName:pn(n.value)});return d(r)?(_i(r.message),r):(ns(),u("Synced",r.value))};var jn=()=>{let e=Fe();if(d(e))return e;let t=at(),n=t.mode!=="live",r=Object.values(e.value.nodes),o=r.filter(g=>to(g)&&!g.isDeleted),s=zi(),i=new Map,c=new Map;for(let g of r)if(!g.isDeleted){if(Ht(g)&&g.parentNodeId){let E=i.get(g.parentNodeId)??[];E.push(g),i.set(g.parentNodeId,E)}if(T(g)&&g.parentNodeId){let E=c.get(g.parentNodeId)??[];E.push(g),c.set(g.parentNodeId,E)}}let l=Ot();if(d(l))return l;let m={};for(let g of r.filter(T))g.isDeleted||(m[g.id]=S.getCommentsByIssue(g.id).map(E=>{let I=S.getContributor(E.authorId);return{id:E.id,issueId:E.issue,body:E.md,author:{id:E.authorId,name:I?.name??"Unknown",color:te(I?.name??E.authorId)},createdAt:eu(E.id)}}));let p=new Map;for(let g of e.value.eventLog)g.action==="add.issue.attachment"&&p.set(g.payload.id,g.payload.author);let f={};for(let g of r.filter(T))g.isDeleted||(f[g.id]=S.getAttachmentsByIssue(g.id).map(E=>({id:E.id,issueId:E.issue,name:E.name,fileName:Dn(E.hash,E.ext),bytes:E.bytes,createdAt:eu(E.id),canDelete:p.get(E.id)===l.value.userId})));return u("Retrieved Epiq GUI state",{boards:o.sort((g,E)=>g.rank.localeCompare(E.rank)).map(g=>({id:g.id,ref:He(g.id),title:g.title,swimlanes:(i.get(g.id)??[]).sort((E,I)=>E.rank.localeCompare(I.rank)).map(E=>({id:E.id,title:E.title,readonly:!!E.readonly||n,issues:(c.get(E.id)??[]).sort((I,R)=>I.rank.localeCompare(R.rank)).map(I=>({id:I.id,ref:He(I.id),title:Ze(I.title),description:I.props.description??"",readonly:!!I.readonly||n,tags:tu(I),assignees:ru(I,s),parentNodeId:I.parentNodeId,isClosed:I.parentNodeId===ve})),parentNodeId:E.parentNodeId}))})),tags:Object.values(e.value.tags).map(g=>({...g,color:te(g.name)})),contributors:Object.values(e.value.contributors).map(g=>({...g,color:te(g.name)})),user:{name:l.value.userName??"",id:l.value.userId??"",color:te(l.value.userName??"")},commentsByIssueId:m,attachmentsByIssueId:f,attachmentMaxKb:Gi(),timeTravel:t})},dt=async(e={})=>{if(at().mode!=="live")return jn();let t=await Ne(e.repoRoot,{pull:!1});return d(t)?t:jn()},cu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(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 u("No changes made",{id:e.issueId,description:s});let i={id:q(),...n.value,action:"edit.description",payload:{id:e.issueId,md:e.description}},c=U([i],t.value.stateBranchRoot);return d(c)?a(c.message):u("Edited issue description",{id:e.issueId,description:e.description})},lu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=Ze(e.title);if(!s.trim())return a("Issue title cannot be empty");if(o.title===s)return u("No changes made",{id:e.issueId,title:s});let i={id:q(),...n.value,action:"edit.title",payload:{id:e.issueId,name:s}},c=U([i],t.value.stateBranchRoot);return d(c)?a(c.message):u("Edited issue title",{id:e.issueId,title:s})},uu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Tag target must be an issue");if(o.readonly)return a("Cannot tag readonly issue");let s=Ze(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??q(),l=[...i?[]:[{id:q(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:q(),...n.value,action:"add.issue.tag",payload:{id:e.issueId,tag:c}}],m=U(l,t.value.stateBranchRoot);return d(m)?a(m.message):u("Added issue tag",{id:e.issueId,tag:{id:c,name:s}})},mu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(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:q(),...n.value,action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},i=U([s],t.value.stateBranchRoot);return d(i)?a(i.message):u("Removed issue tag",{id:e.issueId,tagId:e.tagId})},pu=async(e,t)=>{let n=je(e);if(d(n))return;let r;for(let o of n.value)o.userId===t&&(r=o.userName??r);return r===void 0?void 0:{id:t,name:r}},fu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Assign target must be an issue");if(o.readonly)return a("Cannot assign readonly issue");let s=e.self?n.value.userId:e.assigneeId;if(s){let R=r.value.contributors[s],A=R?void 0:await pu(t.value.stateBranchRoot,s);if(!R&&!A)return a("Unknown assignee id");let P=R??A,_=[...R?[]:[{id:q(),...n.value,action:"create.contributor",payload:{id:P.id,name:P.name}}],{id:q(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:P.id}}],w=U(_,t.value.stateBranchRoot);return d(w)?a(w.message):u("Added issue assignee",{id:e.issueId,assignee:{id:P.id,name:P.name}})}let i=Ze(e.assigneeName??"").trim();if(!i)return a("Provide assigneeId, self or assigneeName");let l=[...nu(zi(),r.value.contributors).entries()].filter(([,R])=>R===i);if(l.length>1)return a(`"${i}" matches ${l.length} contributors (${l.map(([R])=>R).join(", ")}). Assign by assigneeId to choose.`);let m=l[0];if(!m&&!e.createUnlinked)return a(`No contributor named "${i}". Assign by id, or pass createUnlinked to add them as an external assignee.`);let[p=q(),f=i]=m??[],E=[...!!r.value.contributors[p]?[]:[{id:q(),...n.value,action:"create.contributor",payload:{id:p,name:f}}],{id:q(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:p}}],I=U(E,t.value.stateBranchRoot);return d(I)?a(I.message):u("Added issue assignee",{id:e.issueId,assignee:{id:p,name:f}})},gu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;if(!r.value.contributors[e.contributorId])return a("Contributor not found");if(await pu(t.value.stateBranchRoot,e.contributorId))return a("Cannot remove a contributor who has authored events \u2014 their name appears throughout the log");let i=[{id:q(),...n.value,action:"tombstone.contributor",payload:{id:e.contributorId}}],c=U(i,t.value.stateBranchRoot);return d(c)?a(c.message):u("Tombstoned contributor",{id:e.contributorId,name:ro})};var vu=async(e={})=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=je(t.value.stateBranchRoot);if(d(o))return a(o.message);let s=e.boardId?Vi(o.value,e.boardId):o.value,i=new Map,c=new Set,l=new Set;for(let g of o.value)g.userId&&l.add(g.userId);for(let g of s)g.userId&&(i.set(g.userId,g.userName??""),c.add(g.userId));let m=r.value.contributors,f=[...nu(i,m).entries()].map(([g,E])=>({id:g,name:E,color:te(E),isSelf:g===n.value.userId,isExternal:!c.has(g),isRemoved:m[g]?.tombstoned===!0,hasAuthoredAnywhere:l.has(g)}));return u("Listed board contributors",f)},yu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(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:q(),...n.value,action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},i=U([s],t.value.stateBranchRoot);return d(i)?a(i.message):u("Removed issue assignee",{id:e.issueId,assigneeId:e.assigneeId})},ss=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(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");if(s.length>4e3)return a(`Comment cannot exceed ${4e3} characters (got ${s.length})`);let i=q(),c={id:q(),...n.value,action:"add.issue.comment",payload:{id:i,issue:e.issueId,md:s,author:n.value.userId}},l=U([c],t.value.stateBranchRoot);return d(l)?a(l.message):u("Added issue comment",{id:i,issueId:e.issueId,body:s})},is=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();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(!T(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 u("Comment already deleted",{id:e.commentId,issueId:o.payload.issue});let c={id:q(),...n.value,action:"delete.issue.comment",payload:{id:e.commentId,issue:o.payload.issue}},l=U([c],t.value.stateBranchRoot);return d(l)?a(l.message):u("Deleted issue comment",{id:e.commentId,issueId:o.payload.issue})},hu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(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=ec(t.value.stateBranchRoot,s,Gi());if(d(i))return i;let c=Ze(e.name??"").trim()||"image",l=q(),m={id:q(),...n.value,action:"add.issue.attachment",payload:{id:l,issue:e.issueId,author:n.value.userId,hash:i.value.hash,ext:i.value.ext,name:c,bytes:i.value.bytes}},p=U([m],t.value.stateBranchRoot);return d(p)?a(p.message):u("Added issue attachment",{id:l,issueId:e.issueId,fileName:Dn(i.value.hash,i.value.ext),bytes:i.value.bytes})},xu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();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(!T(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 u("Attachment already deleted",{id:e.attachmentId,issueId:o.payload.issue});let c={id:q(),...n.value,action:"delete.issue.attachment",payload:{id:e.attachmentId,issue:o.payload.issue}},l=U([c],t.value.stateBranchRoot);return d(l)?a(l.message):u("Deleted issue attachment",{id:e.attachmentId,issueId:o.payload.issue})},bu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});return d(t)?t:tc(t.value.stateBranchRoot,e.fileName,Gi())};var uy=15e3,Iu=e=>{let t,n=!1,r=!1,o=0,s=()=>{let p=Jr();return d(p)?(le.error(p.message),null):p.value},i=()=>{let p=s();if(!p)return!1;let{autoSync:f,userName:g,preferredEditor:E}=p;return!!(f&&g&&E)},c=()=>{let p=s()?.autoSyncDebounceMs??uy;return Math.max(0,p-(Date.now()-o))},l=async()=>{if(!(n||r)){r=!0,o=Date.now();try{await nn(async()=>{if(at().mode!=="live")return;let p=await os({repoRoot:e.repoRoot});if(d(p))return;let{pulled:f,createdCommit:g,bootstrapped:E}=p.value;!f&&!g&&!E||_t({type:"state",payload:await dt({repoRoot:e.repoRoot})})})}finally{r=!1,m()}}};function m(){n||!i()||r||t||(t=setTimeout(()=>{t=void 0,l()},c()))}return m(),{queueSync:m,dispose:()=>{n=!0,t&&clearTimeout(t)}}};import{WebSocketServer as py}from"ws";var Eu=new Set(["sync","issues:create","issues:move","issue:close","issue:reopen","issue:edit:title","issue:edit:description","issue:tag:add","issue:tag:remove","contributor:remove","issue:assignee:add","issue:assignee:remove","issue:comment:add","issue:comment:delete"]);var my=e=>({...e,boards:(e.boards??[]).map(t=>({...t,swimlanes:(t.swimlanes??[]).map(n=>({...n,issues:(n.issues??[]).map(r=>({...r,description:""}))}))})),commentsByIssueId:Object.fromEntries(Object.entries(e.commentsByIssueId??{}).filter(([,t])=>t.length>0).map(([t,n])=>[t,n.map(r=>({...r,body:""}))])),attachmentsByIssueId:Object.fromEntries(Object.entries(e.attachmentsByIssueId??{}).filter(([,t])=>t.length>0))}),wr=e=>d(e)?e:u(e.message,my(e.value)),Su=(e,t)=>{let n=(e.boards??[]).flatMap(r=>r.swimlanes??[]).flatMap(r=>r.issues??[]).find(r=>r.id===t);return{issueId:t,description:n?.description??"",comments:e.commentsByIssueId?.[t]??[]}};var Cu=()=>{_t({type:"state",payload:wr(jn())})},ie=(e,t)=>{e.send(JSON.stringify(t))},as=async(e,t)=>ie(e,{type:"state",payload:wr(await dt({repoRoot:t}))}),fy=async(e,t)=>{let n=()=>ie(e,{type:"state",payload:wr(jn())});if(at().mode!=="live")return n();let r=await dt({repoRoot:t});return at().mode!=="live"?n():ie(e,{type:"state",payload:wr(r)})},ct=async(e,t,n,r,o)=>{if(ie(e,{type:r,payload:o}),d(o))return ie(e,{type:"failed",payload:o.message});n(),fy(e,t)},Nu=(e,t,{onStateChanged:n})=>{new py({server:e,path:"/ws"}).on("connection",o=>{Va(o),o.on("message",async s=>{let i=async c=>{let{type:l}=c;if(l==="timeline:get"){let{requestId:m,...p}=c.payload??{};return ie(o,{type:"timeline",requestId:m,payload:await ql({repoRoot:t,...p})})}if(l==="issue:get"){let m=c.payload?.issueId,p=jn();return ie(o,{type:"issue",payload:d(p)?p:u("Issue detail",Su(p.value,m))})}if(l==="commits:get"){let{requestId:m,...p}=c.payload??{};return ie(o,{type:"commits",requestId:m,payload:await Yl({repoRoot:t,...p})})}if(l==="commit:inspect")return ie(o,{type:"commit:inspect:result",payload:await Xl({repoRoot:t,sha:c.payload.sha})});if(l==="time-travel:scrub"){let m=await Ql({repoRoot:t,targetTime:c.payload.targetTime});return ie(o,{type:"time-travel:result",payload:m}),d(m)?void 0:Cu()}if(l==="time-travel:live"){let m=await Zl({repoRoot:t});return ie(o,{type:"time-travel:result",payload:m}),d(m)?void 0:Cu()}if(l==="state:get")return as(o,t);if(l==="sync"){let m=await os({repoRoot:t});return ie(o,{type:"sync:result",payload:m}),n(),as(o,t)}if(l==="issue:comment:add"){let m=await ss({repoRoot:t,...c.payload});return ct(o,t,n,"issue:comment:add:result",m)}if(l==="issue:comment:delete"){let m=await is({repoRoot:t,...c.payload});return ie(o,{type:"issue:comment:delete:result",payload:m}),d(m)?ie(o,{type:"failed",payload:m.message}):(n(),as(o,t))}if(l==="issue:edit:description"){let m=await cu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:edit:description:result",m)}if(l==="issue:edit:title"){let m=await lu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:edit:title:result",m)}if(l==="issue:tag:add"){let m=await uu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:tag:add:result",m)}if(l==="issue:tag:remove"){let m=await mu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:tag:remove:result",m)}if(l==="contributor:remove"){let m=await gu({repoRoot:t,...c.payload});return ct(o,t,n,"contributor:remove:result",m)}if(l==="contributors:get")return ie(o,{type:"contributors",payload:await vu({repoRoot:t,...c.payload})});if(l==="issue:assignee:add"){let m=await fu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:assignee:add:result",m)}if(l==="issue:assignee:remove"){let m=await yu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:assignee:remove:result",m)}if(l==="issues:list")return ie(o,{type:"issues",payload:await ou({repoRoot:t})});if(l==="issues:create"){let m=await su({...c.payload,repoRoot:t});return ie(o,{type:"issues:create:result",payload:m}),d(m)?_t({type:"failed",payload:m.message}):(_t({type:"issue:created",payload:m.value}),n(),as(o,t))}if(l==="issues:move"){if(!c.payload.position)return ie(o,{type:"error",message:"Missing move position"});let m=await du({...c.payload,repoRoot:t});return ct(o,t,n,"issues:move:result",m)}if(l==="issue:close"){if(!c.payload.issueId)return ie(o,{type:"error",message:"Missing issueId"});let m=await iu({repoRoot:t,issueId:c.payload.issueId});return ct(o,t,n,"issue:close:result",m)}if(l==="issue:reopen"){if(!c.payload.issueId)return ie(o,{type:"error",message:"Missing issueId"});let m=await au({repoRoot:t,issueId:c.payload.issueId});return ct(o,t,n,"issue:reopen:result",m)}return ie(o,{type:"error",message:"Unknown message type"})};try{let c=JSON.parse(s.toString());return Eu.has(c.type)?await nn(async()=>at().mode!=="live"?ie(o,{type:"failed",payload:"Read-only while viewing history"}):i(c)):await i(c)}catch(c){return ie(o,{type:"error",message:c instanceof Error?c.message:String(c)})}})})};var yy=Sn.dirname(vy(import.meta.url)),hy=process.env.IS_LOCAL==="true"?Sn.resolve(process.cwd(),"dist/gui"):Sn.join(yy,"gui"),ds,xy=async()=>(ds===void 0&&(ds=await import("node:sea").catch(()=>null)),ds?.isSea()?ds:null),fe=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},by=e=>fe(e,409,{isError:!0,message:"Read-only while viewing history"}),cs=(e,t)=>nn(async()=>at().mode!=="live"?by(e):t()),Ru=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)}),Iy=2*1024*1024,Ey={png:"image/png",jpg:"image/jpeg",gif:"image/gif",webp:"image/webp"},Sy=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",Au=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),r=Sn.resolve(hy),o=Sn.resolve(r,n),s=Sn.relative(r,o);if(s.startsWith("..")||Sn.isAbsolute(s))return fe(t,403,{isError:!0,message:"Forbidden"});let i=await xy();try{let c=i?Buffer.from(i.getAsset(`gui/${s}`)):await Tu(o);return t.writeHead(200,{"content-type":Sy(o)}),t.end(c)}catch{return fe(t,404,{isError:!0,message:`Not found: ${n}`})}},Cy=async(e,t=3710)=>new Promise((n,r)=>{let o=s=>{let i=l=>{if(e.off("listening",c),l.code==="EADDRINUSE"&&s===t){e.removeListener("error",i),o(0);return}r(l)},c=()=>{e.off("error",i);let l=e.address();if(!l||typeof l=="string"){r(new Error("Unable to resolve address"));return}n(l.port)};e.once("error",i),e.once("listening",c),e.listen(s,"127.0.0.1")};o(t)}),wu=async e=>{let t=gy.createServer(async(o,s)=>{let i=new URL(o.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return fe(s,200,await dt({repoRoot:e.repoRoot}));if(o.method==="POST"&&i.pathname==="/api/comments")try{let c=await Ru(o);if(!c.issueId||!c.body?.trim())return fe(s,400,{isError:!0,message:"Missing issueId or body"});let l=c.issueId,m=c.body;return await cs(s,async()=>{let p=await ss({repoRoot:e.repoRoot,issueId:l,body:m});return d(p)?fe(s,400,{isError:!0,message:p.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))})}catch(c){return fe(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 Ru(o,Iy);if(!c.issueId||!c.dataBase64)return fe(s,400,{isError:!0,message:"Missing issueId or dataBase64"});let l=c.issueId,m=c.dataBase64,p=c.name??"";return await cs(s,async()=>{let f=await hu({repoRoot:e.repoRoot,issueId:l,name:p,dataBase64:m});return d(f)?fe(s,400,{isError:!0,message:f.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))})}catch(c){return fe(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/",""));return c?cs(s,async()=>{let l=await xu({repoRoot:e.repoRoot,attachmentId:c});return d(l)?fe(s,400,{isError:!0,message:l.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))}):fe(s,400,{isError:!0,message:"Missing attachment id"})}if(o.method==="GET"&&i.pathname.startsWith("/media/")){let c=decodeURIComponent(i.pathname.replace("/media/","")),l=await bu({repoRoot:e.repoRoot,fileName:c});if(d(l))return fe(s,404,{isError:!0,message:l.message});try{let m=await Tu(l.value.filePath);return s.writeHead(200,{"content-type":Ey[l.value.ext]??"application/octet-stream","cache-control":"public, max-age=31536000, immutable"}),s.end(m)}catch{return fe(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/",""));return c?cs(s,async()=>{let l=await is({repoRoot:e.repoRoot,commentId:c});return d(l)?fe(s,400,{isError:!0,message:l.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))}):fe(s,400,{isError:!0,message:"Missing comment id"})}return i.pathname.startsWith("/board/")?Au("/",s):Au(i.pathname,s)});try{await Cy(t)}catch(o){return a(o instanceof Error?`Unable to start GUI server: ${o.message}`:`Unable to start GUI server: ${String(o)}`)}let n=Iu({repoRoot:e.repoRoot});Nu(t,e.repoRoot,{onStateChanged:()=>n.queueSync()}),t.on("close",n.dispose);let r=t.address();return!r||typeof r=="string"?(t.close(),a("Unable to resolve GUI server address")):u("Started GUI server",{url:`http://epiq.localhost:${r.port}${e.boardId?`/board/${e.boardId}`:""}`,server:t})};var Mu=async e=>{let t=Ot();Q(t)&&Me(t.value);let n=await wu({...e,boardId:""});if(d(n))return n;let{url:r}=n.value;return console.log(`Epiq GUI running at ${Ny.cyan(r)}`),Oa(r),u("Started GUI",{url:r})};import{Box as dn}from"ink";import ce from"react";import{Box as qi,Text as Mr}from"ink";import lt,{useEffect as Ry,useMemo as Ay}from"react";import{ulid as Ty}from"ulid";var Pu=({text:e,match:t,color:n,highlightColor:r=h.secondary,dimColor:o=!1})=>{if(!t)return lt.createElement(Mr,{color:n,dimColor:o},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?lt.createElement(Mr,{color:n,dimColor:o},e):lt.createElement(Mr,{color:n,dimColor:o},e.slice(0,c),lt.createElement(Mr,{backgroundColor:r,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},Lu=Ty(),wy=e=>`${e}`,My=e=>{let{pendingNavTarget:t}=Zt();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,s=new Set(de(b.NONE,{breadCrumb:n,contextNode:r,readOnly:v().readOnly,selectedNode:o}));return[...new Set(Object.values(b))].filter(i=>i!=="move").filter(i=>i.length>0).filter(i=>i!==b.PALETTE).map(i=>{let c=Lo(i),l=Xo.find(m=>m.intent===c);return{command:i,description:l?.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))},Py=e=>ee.text({id:Lu,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),Ly=(e,t,n)=>ee.text({id:wy(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),Yi=[],ky=e=>{ku();let t=S.createNode(Py(v().rootNodeId));d(t)||!$t(t.value)||(Yi=[t.value,...e.map((n,r)=>Ly(n,r,Lu)).map(S.createNode).filter(Q).map(({value:n})=>n).filter($t)],M.navigate({contextNode:t.value,selectedIndex:0}))},ku=()=>{let e=Yi.map(t=>t.id);Yi=[];for(let t of e)S.deleteNode(t)};function Du({width:e,height:t}){let r=Ic().value.trim().toLowerCase(),o=Ay(()=>My(r),[r]);Ry(()=>(ky(o),()=>{ku()}),[o]);let s=v().selectedIndex;return lt.createElement(qi,{flexDirection:"column",width:e,height:t-2},lt.createElement(tt,{height:t-4,itemHeight:3,selectedIndex:s},o.map((i,c)=>{let l=c===s,m=i.isAvailable?h.accent:h.secondary2,p=i.isAvailable?"":"[unavailable] ";return lt.createElement(qi,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:h.secondary,borderStyle:"single"},lt.createElement(Mr,{color:m,dimColor:!i.isAvailable},l?"\u276F ":" ",lt.createElement(Pu,{text:Xa(i.command),match:r,color:m,dimColor:!i.isAvailable})),lt.createElement(qi,{paddingLeft:2},lt.createElement(Pu,{text:p+i.description,match:r.length>=2?r:"",color:l&&i.isAvailable?h.primary:h.secondary2,dimColor:!i.isAvailable})))})))}import{Box as Xy}from"ink";import ms from"react";import Lr from"chalk";import{Box as Xi,Text as Bu}from"ink";import Pr,{useEffect as Dy,useMemo as By,useState as Fy}from"react";var Fu=Lr.hex(h.secondary),Uy=Lr.inverse,Oy=Lr.inverse.hex(h.secondary2),_y={hint:"",hints:[],overlap:0,remainder:""},Ou=({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}},$y=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=te(t);return{bg:r=>Lr.bgHex(n).black(r),bgCursor:r=>Lr.bgHex(n).inverse.black(r)}}return Js(t)},Hy=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=Ou({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}},Uu=()=>({value:Le.value,cursorPosition:Le.cursorPosition,commandIsPending:Le.commandIsPending,autoCompletion:Le.commandMeta.autoCompletion??_y,infoMessage:Le.commandMeta.infoMessage,validationStatus:Le.commandMeta.validity,command:Le.commandMeta.command,inputString:Le.commandMeta.inputString,modifier:Le.commandMeta.modifier}),jy=(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,_u=({width:e,mode:t})=>{let[n,r]=Fy(Uu());Dy(()=>{let I=()=>{let A=Uu();r(P=>jy(P,A)?P:A)},R=fi(I);return I(),()=>{R()}},[]);let{value:o,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:l,command:m,modifier:p,validationStatus:f}=n,g=c&&f===bt.Invalid,E=By(()=>{let I=Math.max(0,Math.min(s,o.length)),R=Ou({value:o,command:m}),A=Hy({value:o,command:m,modifier:p}),P=m?Js(m):null,_=$y({command:m,modifier:p}),w=(ge,me)=>{let Kn=R&&me>=R.start&&me<R.end,zn=A&&me>=A.start&&me<A.end;return Kn&&P?P.fg(ge):zn&&_?_.bg(ge):ge},W=(ge,me)=>{let Kn=R&&me>=R.start&&me<R.end,zn=A&&me>=A.start&&me<A.end;return Kn&&P?P.fgCursor(ge):zn&&_?_.bgCursor(ge):Uy(ge)},H=o.slice(0,I),D=o[I]??" ",$=I<o.length?o.slice(I+1):"",Ye=Array.from(H).map((ge,me)=>w(ge,me)).join(""),we=W(D,I),Xe=Array.from($).map((ge,me)=>w(ge,I+1+me)).join("");if(l.hint){let ge=l.hint[l.overlap]??D;we=Oy(ge),Xe=Fu(l.remainder.slice(1)+$)}return Fu(t===y.PALETTE?"?":":")+Ye+we+Xe},[o,s,l,m,p]);return Pr.createElement(Xi,{flexDirection:"column",justifyContent:"flex-start"},Pr.createElement(Xi,{flexDirection:"column",paddingX:1,borderColor:h.secondary,borderStyle:"round",width:e},Pr.createElement(Xi,null,Pr.createElement(Bu,null,E),i&&Pr.createElement(Bu,{wrap:"truncate",color:g?h.red:h.secondary2},` ${i} `))))};import{Box as Wy,Text as Vy}from"ink";import $u from"react";var Gy=(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},Hu=({width:e,availableHints:t})=>{let n=Gy(t,e).join(" | ");return $u.createElement(Wy,{width:e,borderStyle:"round",borderColor:h.secondary,paddingX:1},$u.createElement(Vy,{color:h.secondary2},n.length?n:"\xA0"))};import{Box as Ky,Text as ls}from"ink";import kr,{useEffect as zy,useRef as Wn,useState as qy}from"react";var Yy=40,us=.3,Ji="\u2500",ju=1,Wu=16,Vu=({width:e})=>{let{replay:t}=j(),n=t!==null,r=t?Math.min(1,Math.max(0,t.progress)):0,s=Math.max(4,e-6),i=s*ju,[c,l]=qy(0),m=Wn(r);m.current=r;let p=Wn(0),f=Wn(0),g=Wn(0),E=Wn(0),I=Wn(0);if(zy(()=>{if(!n){p.current=0,g.current=0,E.current=0,I.current=0,l(0);return}p.current=m.current,f.current=Date.now(),g.current=m.current;let w=setInterval(()=>{let W=Date.now(),H=m.current;if(H!==g.current){let Xe=H-g.current,ge=W-f.current;if(Xe<0)E.current=0,I.current=0;else if(Xe>0&&ge>0){let me=Xe/ge;E.current=E.current===0?me:E.current*(1-us)+me*us,I.current=I.current===0?Xe:I.current*(1-us)+Xe*us}p.current=H,f.current=W,g.current=H}let D=W-f.current,$=Math.min(I.current,E.current*D),Ye=Math.min(1,p.current+$),we=Math.round(Ye*i);l(Xe=>Xe===we?Xe:we)},Yy);return()=>clearInterval(w)},[n,i]),!t)return null;let R=w=>{let W=s>1?w/(s-1):0,H=Math.round(W*(Wu-1))/(Wu-1);return oo(H)},A=Math.min(s,Math.floor(c/ju)),P=[];for(let w=0;w<A;w++){let W=R(w),H=P[P.length-1];H&&H.color===W?H.text+=Ji:P.push({text:Ji,color:W})}let _=Ji.repeat(Math.max(0,s-A));return kr.createElement(Ky,{width:e,borderStyle:"round",borderColor:h.secondary,paddingX:1,columnGap:1},kr.createElement(ls,{color:h.secondary2},"\u25B6"),kr.createElement(ls,null,P.map((w,W)=>kr.createElement(ls,{key:W,color:w.color},w.text)),kr.createElement(ls,{color:h.secondary,dimColor:!0},_)))};var Dr=({width:e,mode:t,availableHints:n})=>{let{timeMode:r}=j(),o=t===y.COMMAND_LINE||t===y.PALETTE;return ms.createElement(Xy,null,o?ms.createElement(_u,{width:e,mode:t}):r==="replay"?ms.createElement(Vu,{width:e}):ms.createElement(Hu,{width:e,mode:t,availableHints:n}))};import{Box as rn,Text as Vn}from"ink";import _e,{useEffect as Jy,useMemo as Qy}from"react";import{ulid as Gu}from"ulid";var fs=Gu(),Zy=()=>[...new Set([...v().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})),eh=e=>ee.text({id:fs,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),th=(e,t,n)=>ee.text({id:Gu(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),ps=[],Ku=()=>{let e=ps.filter(n=>n.id!==fs).map(n=>n.id),t=ps.filter(n=>n.id===fs).map(n=>n.id);ps=[];for(let n of[...e,...t])S.deleteNode(n)},nh=e=>{Ku();let t=S.createNode(eh(v().rootNodeId));if(d(t)||!$t(t.value))return logger.error("Could not attach help nodes");ps=[t.value,...e.map((n,r)=>th(n,r,fs)).map(S.createNode).filter(Q).map(({value:n})=>n).filter($t)],M.navigate({contextNode:t.value,selectedIndex:0})},zu=({width:e,height:t})=>{let n=Qy(()=>Zy(),[]);Jy(()=>(nh(n),()=>{Ku()}),[n]);let r=v().selectedIndex;return _e.createElement(rn,{flexDirection:"column",marginTop:3,borderColor:h.secondary,borderStyle:"round",width:e,height:t-2},_e.createElement(rn,{paddingX:1,justifyContent:"center"},_e.createElement(Vn,{color:h.accent},"Help"),_e.createElement(Vn,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),_e.createElement(rn,{paddingX:1,marginTop:1},_e.createElement(rn,{width:20,justifyContent:"flex-end"},_e.createElement(Vn,{color:h.secondary},"Key(s)")),_e.createElement(rn,{flexGrow:1,width:40,paddingLeft:2},_e.createElement(Vn,{color:h.secondary},"Action"))),_e.createElement(tt,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:s},i)=>{let c=i===r;return _e.createElement(rn,{paddingX:1,key:`${o}-${s}-${i}`,flexDirection:"row"},_e.createElement(rn,{width:20,justifyContent:"flex-end"},_e.createElement(Vn,{color:h.accent},o)),_e.createElement(rn,{flexGrow:1,width:40,paddingLeft:2},_e.createElement(Vn,{color:c?h.primary:h.secondary2},s)))})))};import rh from"chalk";import{Box as gs,Text as Ft}from"ink";import qe from"react";var qu=({width:e,height:t})=>qe.createElement(gs,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:h.secondary,rowGap:1},qe.createElement(Ft,{color:h.accent,bold:!0},"Initialize project"),qe.createElement(Ft,null,`This folder is not an ${rh.hex(h.accent)("epiq")} project yet.`),qe.createElement(Ft,{color:h.primary},"To start tracking issues here, we need to initialize a new",qe.createElement(Ft,{color:h.primary,backgroundColor:h.secondary}," .epiq/project.json "),"file in this repository."),qe.createElement(gs,{marginTop:1,flexDirection:"column"},qe.createElement(gs,null,qe.createElement(Ft,{color:h.accent}," "),qe.createElement(Ft,{color:h.primary},"Type "),qe.createElement(Ft,{backgroundColor:h.secondary}," :init "))),qe.createElement(gs,{marginTop:1},qe.createElement(Ft,{color:h.secondary2},"This will create, commit and push "),qe.createElement(Ft,{color:h.primary,backgroundColor:h.secondary}," .epiq/project.json ")));import{Box as vs,Text as Ct}from"ink";import Te from"react";var oh=({isDone:e,command:t,value:n})=>Te.createElement(vs,null,Te.createElement(Ct,{color:h.accent,dimColor:e},e?" \u2714 ":" "),Te.createElement(Ct,{dimColor:e},"Type "),Te.createElement(Ct,{backgroundColor:h.secondary,dimColor:e}," "+t+" "),n!==void 0&&Te.createElement(Te.Fragment,null,Te.createElement(Ct,{dimColor:e}," "),Te.createElement(Ct,{color:h.secondary,dimColor:e},"<"+n+">"))),sh=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function Qi({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:s,autoSync:i,isSetAutoSync:c}=Kt(),l=[{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=l.findIndex(f=>!f.done),p=m===-1?void 0:l[m];return Te.createElement(vs,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:h.secondary,rowGap:1},Te.createElement(Ct,{color:h.accent,bold:!0},"Welcome! \u{1F539}"),Te.createElement(Ct,null,"Let's get you started - it's a breeze."),Te.createElement(Ct,{color:h.secondary2},"Remember - you can always search available commands by typing:",Te.createElement(Ct,{color:h.accent}," ? ")),p&&Te.createElement(Ct,{color:h.secondary2},p.message),Te.createElement(vs,{flexDirection:"column"},l.map((f,g)=>m===-1||g<=m?Te.createElement(vs,{key:f.key,marginBottom:1},Te.createElement(oh,{isDone:f.done,command:f.command,value:f.done?sh(f.value):void 0})):null)))}import Is from"chalk";import{Box as Fr,Text as Gn}from"ink";import xe from"react";import{Box as ys,Text as Yu}from"ink";import on from"react";import ih from"chalk";var ah=e=>(S.getTag(e)?.name??"").length+3,dh=e=>{let t=S.getContributor(e);return(t?Xt(e,t.name):"").length+3},Xu=({width:e})=>{let{viewMode:t}=K(),n=j(),{breadCrumb:r,contextNode:o,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[o.id]?.[s],l=At(c?.id??o.id,"TICKET"),m=Q(l)?l.value:void 0,p=m?.props.tags??[],f=m?.props.assignees??[],g=m?.parentNodeId?!qs(o.id,m.parentNodeId)&&t==="dense":!1,E=r.map((H,D)=>{let $=D===r.length-1,Ye=Y(H.id),we=$?Ye?.[s]?.title:void 0;return`${D?" / ":""}${H.title??""}${we?` \u25B8 ${we}`:""}`}).join(""),I=m?S.getCommentsByIssue(m.id):[],R=I.length?String(I.length).length+11:0,A=g?p.reduce((H,D)=>H+ah(D),0)+f.reduce((H,D)=>H+dh(D),0)+R:0,P=c?.id!=null&&!(t==="wide"&&T(c)),_=Math.max(0,e-A),w=E.substring(0,_)+(P?ih.hex(h.secondary2).dim(` ${He(c.id)}`):""),W=g?[...p.map(H=>on.createElement(ys,{key:`tag-${H}`,paddingLeft:1},on.createElement(Un,{id:H}))),...f.map(H=>on.createElement(ys,{key:`assignee-${H}`,paddingLeft:1},on.createElement(Jt,{id:H}))),I.length?on.createElement(ys,{key:"comments",paddingLeft:1},on.createElement(Yu,{color:h.accent},"[",I.length," comment",I.length===1?"":"s","]")):null]:[];return on.createElement(ys,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},on.createElement(Yu,{color:h.secondary2},w),W)};import{Box as ch,Text as Ju}from"ink";import hs from"react";var lh=({filters:e})=>hs.createElement(ch,{columnGap:1},hs.createElement(Ju,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>hs.createElement(Ju,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),Qu=hs.memo(lh);import{Box as uh,Text as xs}from"ink";import Br from"react";function Zu(){let{eventLog:e,unappliedEvents:t}=j(),n=e.at(-1)?.id,r=Ao(n??""),o=Q(r)?co(r.value):"INVALID DATE";return Br.createElement(uh,{paddingLeft:1},Br.createElement(xs,{backgroundColor:h.accent,color:h.secondary}," Readonly "),Br.createElement(xs,{color:h.accent}," "+t.length+" edits ago at "+o+"."),Br.createElement(xs,{color:h.accent}," Resume with "),Br.createElement(xs,{backgroundColor:h.accent,color:h.secondary}," ",":peek now"," "))}import{Box as mh,Text as Zi}from"ink";import bs from"react";function em(){let{replay:e}=j();if(!e)return null;let{appliedCount:t,totalCount:n,currentTime:r}=e;return bs.createElement(mh,{paddingRight:2,columnGap:1,justifyContent:"flex-end"},bs.createElement(Zi,{backgroundColor:h.accent,color:h.secondary}," \u25B6 REPLAY "),bs.createElement(Zi,{color:h.secondary2},co(new Date(r))),bs.createElement(Zi,{color:h.accent},`${t}/${n} edits`))}import ea from"chalk";import{Box as ph,Text as tm}from"ink";import ta,{useEffect as fh,useState as gh}from"react";var vh=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],yh=150,nm=12,hh=.36,rm=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)}},xh=({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)}`},bh=(e,t,n)=>{let r=rm(e),o=rm(t);return xh({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},Ih=(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 bh(s,i,o)};function om({syncStatus:e,autoSync:t}){let[n,r]=gh(0);fh(()=>{if(e.status!=="syncing"){r(0);return}let c=0,l=setInterval(()=>{c+=1;let m=(Math.sin(c*hh)+1)/2,p=Math.round(m*(nm-1));r(f=>f===p?f:p)},yh);return()=>clearInterval(l)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:h.secondary2,failed:h.yellow,pending:h.secondary2,syncing:Ih(vh,n/(nm-1))??""}[e.status];return ta.createElement(ph,null,ta.createElement(tm,null,ea.hex(h.secondary2).dim(t?"Sync (auto): ":"Sync: ")),ta.createElement(tm,null,ea.hex(i)("\u25CF")+ea.hex(h.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}import cm from"chalk";import{Text as lm}from"ink";import um,{useEffect as Nh,useState as Rh}from"react";var sn="1.4.4";import na from"chalk";var Eh="https://registry.npmjs.org/epiq/latest",ra=null,sm=0,Sh=1e3*60*60*24,im=e=>e.replace(/^v/,""),Ch=(e,t)=>{let n=im(e).split(".").map(Number),r=im(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},am=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(ra&&Date.now()-sm<Sh)return ra;try{let t=await fetch(Eh);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?Ch(r,e)>0:!1};return ra=o,sm=Date.now(),o}catch{return{current:e,latest:null,updateAvailable:!1}}},dm=(e,t)=>{let n=e.split("."),r=t.split("."),o=r.findIndex((s,i)=>s!=n[i]);return r.map((s,i)=>i>=o?na.hex(h.accent).dim(s):na.hex(h.secondary).dim(s)).join(na.hex(h.secondary2).dim("."))};function mm(){let[e,t]=Rh({current:sn,latest:null,updateAvailable:!1});return Nh(()=>{let n=!0;return am(sn).then(r=>{n&&t(r)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?um.createElement(lm,{dimColor:!0,color:h.secondary2},sn+" "):um.createElement(lm,null,cm.hex(h.secondary2).dim(sn),cm.hex(h.accent).dim(" \u2197 "),dm(sn,e.latest))}function Ur({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o,replay:s}=j(),{userName:i,preferredEditor:c,autoSync:l}=K(),m=64,p=process.stdout.columns-m-8,f=t||n==="replay",g=s?mn(s.currentLabel,Math.max(0,p)):"";return xe.createElement(Fr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},n==="replay"?xe.createElement(Fr,{paddingLeft:1},xe.createElement(Gn,{color:h.secondary2},g)):f?xe.createElement(Gn,null," "):o===y.PALETTE?xe.createElement(Fr,null,xe.createElement(Gn,{color:h.accent},"Command Palette"),xe.createElement(Gn,{dimColor:!0,color:h.secondary2}," ","- search, select and press enter")):xe.createElement(Fr,{paddingLeft:1},e.length>0?xe.createElement(Qu,{filters:e}):xe.createElement(Xu,{width:p})),n==="live"?xe.createElement(Fr,{columnGap:1,paddingRight:2,"max-width":m,overflow:"hidden",justifyContent:"flex-end"},xe.createElement(om,{autoSync:!!l,syncStatus:r}),xe.createElement(Gn,null,Is.hex(h.secondary2).dim("Mode: ")+Is.hex(h.secondary2).dim(o.padEnd(8," "))," "),xe.createElement(pm,{icon:"@",value:i}),xe.createElement(pm,{icon:"\u276F",value:c}),xe.createElement(mm,null)):"",n==="peek"?xe.createElement(Zu,null):"",n==="replay"?xe.createElement(em,null):"")}function pm({icon:e,value:t}){return xe.createElement(Gn,null,Is.dim(e)+Is.hex(h.accent)(` ${t??"-"} `))}import{Box as Ah,Text as Th}from"ink";import Or from"react";import{Box as Es,Text as oa}from"ink";import an from"react";function sa(){let e=j(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?z(t?.id):[];return an.createElement(Es,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:h.secondary,width:s},an.createElement(Es,{padding:1,paddingTop:0,paddingBottom:0},an.createElement(oa,null,"Select a board:")),an.createElement(Es,{padding:1,flexDirection:"column"},i.map((c,l)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===l,f=z(c.id).flatMap(({id:g})=>Y(g)).length;return an.createElement(Es,{key:c.id??l},an.createElement(oa,{color:m?h.accent:h.secondary2},an.createElement(ke,{isSelected:m})),an.createElement(oa,{color:m?h.accent:h.secondary2},c.title," (",f," issues)",c.readonly?" \u{1F512}":""))})))}var wh=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:s,width:i})=>{let{renderedChildrenIndex:c}=j(),l=n.find(({context:g})=>g==="BOARD"),f=s-1-3;return Or.createElement(Ah,{flexDirection:"row"},e.context==="WORKSPACE"?Or.createElement(sa,null):l?Or.createElement($o,{height:f,width:i,swimlanes:(c[l.id]??[]).filter(g=>g!==void 0&&Ht(g)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):Or.createElement(Th,null))},fm=Or.memo(wh);import{useEffect as Mh}from"react";var Ph=e=>{Mh(()=>{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:l}=v();l==="default"&&!c&&Io(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},gm=({autoSync:e})=>(Ph(e),null);function ia({width:e,height:t}){let n=j(),{autoSync:r,viewMode:o}=Ua(),s=n.filters;if(n.mode===y.HELP)return ce.createElement(dn,{flexDirection:"column"},ce.createElement(zu,{width:e,height:t}));if(n.mode===y.PALETTE)return ce.createElement(dn,{flexDirection:"column"},ce.createElement(Ur,{filters:s}),ce.createElement(Du,{width:e,height:t-2}),ce.createElement(Dr,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=Kt(),c=!i,l=i&&!n.hasProjectDefinition;if(c)return ce.createElement(dn,{flexDirection:"column"},ce.createElement(dn,{flexDirection:"column"},ce.createElement(Ur,{hideBreadCrumb:!0,filters:s}),ce.createElement(Qi,{height:t,width:e})),ce.createElement(Dr,{width:e,mode:n.mode,availableHints:n.availableHints}));if(l)return ce.createElement(dn,{flexDirection:"column"},ce.createElement(dn,{flexDirection:"column"},ce.createElement(Ur,{hideBreadCrumb:!0,filters:s}),ce.createElement(qu,{height:t,width:e})),ce.createElement(Dr,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Oe(n.breadCrumb??[],"BOARD");if(Q(m)){let p=m.value.id,f=z(p).length,g=3,E=Math.floor(e/g),I=Math.floor(e/Math.max(f,1));e=Math.min(I,E)*Math.max(f,g)}return ce.createElement(dn,{flexDirection:"column"},ce.createElement(gm,{autoSync:r}),ce.createElement(dn,{flexDirection:"column"},ce.createElement(Ur,{filters:s}),ce.createElement(fm,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),ce.createElement(Dr,{width:e,mode:n.mode,availableHints:n.availableHints}))}import Lh from"readline";var Ss,Cs,Nt,kh=new Set([x.MoveCursorLeft,x.EraseInputWord,x.MoveCursorLeftOfWord,x.MoveCursorRight,x.MoveCursorRightOfWord,x.NavToPreviousContainer,x.NavToNextContainer,x.NavPreviousItem,x.NavNextItem,x.SetViewDense,x.SetViewWide,x.Confirm,x.Exit,x.Yank,x.InitCommandLine,x.InitCommandPalette,x.ExitCommandLine,x.CaptureInput,x.EraseInput,x.EraseInputWord,x.HideHelp,x.ViewHelp,x.SetViewDense,x.SetViewWide,x.GetLastCommandFromHistory,x.GetNextCommandFromHistory,x.AutoCompleteCommand]),Dh=new Set([x.NavPreviousItem,x.NavNextItem,x.NavToPreviousContainer,x.NavToNextContainer,x.Confirm,x.Exit,x.InitCommandPalette,x.InitMove,x.MoveNextItem,x.MovePreviousItem,x.MoveToNextContainer,x.MoveToPreviousContainer,x.Delete,x.AddItem,x.EditTitle,x.EditDescription,x.ConfirmMove,x.Edit,x.ViewHelp,x.Yank]),vm=async e=>{if(e.ctrl&&e.name==="c")return M.exit();let{actionIndex:t,mode:n,readOnly:r,timeMode:o}=v(),s=Sc(e,n);if(!s||r&&!kh.has(s)||o==="replay"&&n===y.DEFAULT&&Dh.has(s))return;let i=t[n]?.[s];if(i?.action)try{await i.action(i,e)}catch(c){logger.error(c)}},Bh=()=>async function(t,n){n.name!=="escape"&&(Nt&&(clearTimeout(Nt),Nt=void 0),await vm(n))},Fh=()=>async function(t){if(t.length===1&&t[0]===27){Nt&&clearTimeout(Nt),Nt=setTimeout(()=>{vm({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),Nt=void 0},25);return}Nt&&(clearTimeout(Nt),Nt=void 0)};function ym(){Ss&&process.stdin.removeListener("keypress",Ss),Cs&&process.stdin.removeListener("data",Cs),Ss=Bh(),Cs=Fh(),Lh.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",Cs),process.stdin.on("keypress",Ss)}async function hm(){try{let e=Ot();Q(e)&&Me(e.value);let t=$e(process.cwd()),n=[];if(Q(t)){let s=Re({repoRoot:t.value});if(d(s))return vn(3,s.message);let i=Cn(),c=await un({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return vn(3,c.message);let l=await F({cwd:s.value,args:["pull","--ff-only"]});d(l)&&logger.info(3,l.message);let m=je(s.value);if(d(m))return vn(3,m.message);n=m.value}let r=gn(n);if(d(r))return vn(4,r.message);C({hasProjectDefinition:Q(t),hasInitializingEvents:!!n.length});let o=aa();return d(o)?vn(6,o.message):(ym(),u("Booted Epiq",void 0))}catch(e){return vn(0,ho(e))}}Yc();var $h=`${cn.bold("Epiq CLI")}
61
61
 
62
62
  ${cn.dim("Boot in directory:")}
63
63
  ${cn.cyan("$ epiq")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epiq",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "EPIQ - ergonomic, distributed CLI-first issue tracker TUI ready for the agentic era",